Jump to content

Recommended Posts

I'm the leader of an Arma 3 milsim unit, and I'm attempting to complete a shoot-house with moving targets. How do I script an object (namely a target) to cycle movement directions? I'm specifically asking for the initialization script for cycling movement directions for objects in the 3den Editor. Please state the specific steps required to complete these actions, because I'm new to scripting, and as much as I would like to learn how to do it, I simply don't have that much time to dedicate.

Share this post


Link to post
Share on other sites
6 hours ago, pierremgi said:

movement directions?

I can toggle raise/lay a popup target like here, but what do you mean?

I meant the cycling of movement directions from left/right to right/left; an example of this: 

Also, I would like to know how to script the targets so that when they're shot, they lay on the ground without popping back up.

Share this post


Link to post
Share on other sites
18 hours ago, pierremgi said:

For such target, you need to script something like this code.

Thank you for the instructions, but is there any instructions for this in English? I translated it from German to English, but the grammar can be quite difficult to understand, although possible.

Share this post


Link to post
Share on other sites
Thank you for the instructions, but is there any instructions for this in English? I translated it from German to English, but the grammar can be quite difficult to understand, although possible.

The scripts are commented in English and there is an example mission you can look at to see how it all works.

Sent from my SM-G930P using Tapatalk

Share this post


Link to post
Share on other sites
4 hours ago, Harzach said:


The scripts are commented in English and there is an example mission you can look at to see how it all works.

Sent from my SM-G930P using Tapatalk
 

I created the .sqf files in the mpmissions folder (4 of them including the init.sqf). What script do I paste into the initialization script for the rail and/or the moving target to enable the target to move upon the rail?

Share this post


Link to post
Share on other sites

Just to be clear, I am not a scripting expert by any means. I am simply in a helpful mood and enjoy solving (or at least exploring) problems like this.

 

It looks like the demo mission is not available anymore. I grabbed the linked code and had a go at it tonight. Right out of the gate, there were problems with consistency in the comments regarding script call examples and a couple of other things, but that was an easy fix. I am currently trying to track down a problem with setVariable not parsing (lines 133-136 of initTargetRailExt.sqf). I can get rails set down perfectly, but the target does not spawn. That said,the real problem lies with MP compatibility. Which is to say, there is no MP compatibility. Even if I could get this working in the editor, it won't work in MP, which is ultimately your goal.

I'll take another crack at it tomorrow, but without the help of a locality guru, it's simply not going to work.

Share this post


Link to post
Share on other sites
11 minutes ago, Harzach said:

Just to be clear, I am not a scripting expert by any means. I am simply in a helpful mood and enjoy solving (or at least exploring) problems like this.

 

It looks like the demo mission is not available anymore. I grabbed the linked code and had a go at it tonight. Right out of the gate, there were problems with consistency in the comments regarding script call examples and a couple of other things, but that was an easy fix. I am currently trying to track down a problem with setVariable not parsing (lines 133-136 of initTargetRailExt.sqf). I can get rails set down perfectly, but the target does not spawn. That said,the real problem lies with MP compatibility. Which is to say, there is no MP compatibility. Even if I could get this working in the editor, it won't work in MP, which is ultimately your goal.

I'll take another crack at it tomorrow, but without the help of a locality guru, it's simply not going to work.

Thank you for the advice, and I hope that your attempt tomorrow will be fruitful.

Share this post


Link to post
Share on other sites

Couldn't wrap the night without one more look, and so I figured out the problem with the target not spawning - lack of clarity/language barrier in comments, and failure on my end to see through it.

 

I'll attempt to tackle locality tomorrow.

  • Like 1

Share this post


Link to post
Share on other sites
On 6/9/2017 at 1:17 AM, Harzach said:

Couldn't wrap the night without one more look, and so I figured out the problem with the target not spawning - lack of clarity/language barrier in comments, and failure on my end to see through it.

 

I'll attempt to tackle locality tomorrow.

Did you have any results for the locality?

Share this post


Link to post
Share on other sites
On ‎09‎.‎06‎.‎2017 at 6:33 AM, Harzach said:

... but without the help of a locality guru, it's simply not going to work ...

 

You don't need a guru because locality is not a mystery its just thinking about each line of code where it has to be executed and where its arguments have to come from. In most cases a simple remoteExec helps to get a command executed on the needed client. You can look at wiki for each command and u will find there the needed locality informations:

 

Arguments of this scripting command have to be local to the client the command is executed on - Arguments of these scripting commands have to be local to the client the command is executed on.

Arguments of this scripting command don't have to be local to the client the command is executed on - Arguments of these scripting commands don't have to be local to the client the command is executed on.

Effects of this scripting command are not broadcasted over the network and remain local to the client the command is executed on - Effects of these scripting commands are not broadcasted over the network and remain local to the client the command is executed on.

Effects of this scripting command are broadcasted over the network and happen on every computer in the network - Effects of these scripting commands are broadcasted over the network and happen on every computer in the network.

This scripting command must be executed on the server to work properly in multiplayer - Scripting commands that must be executed on the server to function properly

 

Sometimes as in case of setFuel you have additional locality informations in the description of the command. Like this:

 

Quote

Sets fuel percentage from 0 (empty) to 1 (full). The vehicle must be local to the computer where command is executed.

 

This is all you need in most cases and of course u have to think about it. If u just don't care 'bout locality then ur script would probably not work in MP-envitronment.

 

Now for those script u guys r talking 'bout. If you post it here (in a spoiler, plz) then I could take a look at it. Maybe I 'll see something which causes problems in MP.

I can't open the given link above because I'm at work and that URL is forbidden to open for me.

 

 

Share this post


Link to post
Share on other sites
11 hours ago, Commander Salamander said:

Did you have any results for the locality?

Hey, sorry - I foolishly planned to tackle this over the weekend, but life always finds a way...

I'll PM the working SP mission example later today, and take the following under advisement when I do get a chance to look at it again:

 

40 minutes ago, sarogahtyp said:

 

You don't need a guru because locality is not a mystery its just thinking about each line of code where it has to be executed and where its arguments have to come from. In most cases a simple remoteExec helps to get a command executed on the needed client. You can look at wiki for each command and u will find there the needed locality informations:

 

Arguments of this scripting command have to be local to the client the command is executed on - Arguments of these scripting commands have to be local to the client the command is executed on.

Arguments of this scripting command don't have to be local to the client the command is executed on - Arguments of these scripting commands don't have to be local to the client the command is executed on.

Effects of this scripting command are not broadcasted over the network and remain local to the client the command is executed on - Effects of these scripting commands are not broadcasted over the network and remain local to the client the command is executed on.

Effects of this scripting command are broadcasted over the network and happen on every computer in the network - Effects of these scripting commands are broadcasted over the network and happen on every computer in the network.

This scripting command must be executed on the server to work properly in multiplayer - Scripting commands that must be executed on the server to function properly

 

Sometimes as in case of setFuel you have additional locality informations in the description of the command. Like this:

 

Quote

Sets fuel percentage from 0 (empty) to 1 (full). The vehicle must be local to the computer where command is executed.

 

This is all you need in most cases and of course u have to think about it. If u just don't care 'bout locality then ur script would probably not work in MP-envitronment.

 

Now for those script u guys r talking 'bout. If you post it here (in a spoiler, plz) then I could take a look at it. Maybe I 'll see something which causes problems in MP.

I can't open the given link above because I'm at work and that URL is forbidden to open for me.

 

 

Well, I need a guru (aka: teacher) because I do not yet know these things! I am happy to learn - I take great joy in it - but time is always a factor. It has taken me five years to get where I am now. The little time I have to dedicate to this hobby is amplified by people such as yourself who share their knowledge freely here on the forums.

 

I'll post the relevant code later today, and try to carve out some time to do some reading.

 

Thank you!

Share this post


Link to post
Share on other sites

Basic SP test mission here:  https://www.dropbox.com/s/iaxsl1xa4enapvb/MovingTargetTest.Stratis.7z?dl=0

 

Spawn and start the target with Radio Alpha. After being shot, it will pop up in five seconds. This is fully configurable, details in initTargetRailExt.sqf .

 

I have not had a chance to test in MP, so I am assuming that the source page is correct in describing this system as not MP-compatible.

 

Relevant scripts/elements follow.

 

Init.sqf:

Spoiler

//set variable for PopUpTargetExt.sqf
nopop=false;

 

 

initTargetRailExt.sqf :

Spoiler

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/*  initTargetRailExt.sqf                                   EXTENDED VERSION                          				*/
/*  by [W] Steffie                                                                                    				*/
/*  v1.3, 16.02.14                                                                                    				*/
/*  required: "nopop=true;" in init.sqf                                                               				*/
/*            PopUpTargetExt.sqf v1.0                                                         						*/
/*            moveTargetRailExt.sqf v1.0                                                         					*/
/*                                                                                                    				*/
/*  Description:                                                                                      				*/
/*    This script automatically builds an Popup Target rail                                           				*/
/*    First Rail segment is used to place startpoint of railway. All other parts are built auto-      				*/
/*    matically. Movement of the target is controlled by movement-array.                              				*/
/*    It's possible to start movement by connecting a trigger.                                        				*/
/*                                                                                                    				*/
/*  Usage:                                                                                                     		*/
/*    Target = [Rail,Segm,Dir,Type,[Spd,Times,Delay,Downtime,Start,Reset]] execVM "scripts\initTargetRailExt.sqf"; 	*/
/*                                                                                                             		*/
/*  Parameters:                                                                                       				*/
/*    Rail:      Object - First rail segment, sets position an direction of track     ObjVar "_base"  				*/
/*    Segments:  Number - Count of total segments of rail (1m per Segment)                            				*/
/*    Direction: Number - 0 to 3, Direction target faces relatively to rail.                          				*/
/*                        Target starts on 1st rail. Rail 90 deg clockwise.                           				*/
/*    Type:      Number - Type of Target on Rail an Accuracy feature (2 digits)                       				*/
/*    Speed:     Number - Speed of target in m/s.                                                     				*/
/*    Times:     Number - Times the target passes the rail, 2 means to and back, -1 endless           				*/
/*    Delay:     Number - Time the target rest at the end of the rails.                               				*/
/*    Downtime:  Number - Time before Target popping up again (-1 means stay down)                    				*/
/*    Start:     Object - Trigger, Target sleeps until Trigger fires. No Trigger: objNull             				*/
/*                                                                                                    				*/
/*  Examples:                                                                                         				*/
/*    null = [RL_1,3,0,11,[5,2,2,4,trgDoor_1]] execVM "scripts\initTargetRailExt.sqf";                    			*/
/*    Short Rail that pops in when triggered, stays 2 sec and pops back. Perfect for doors and windows				*/
/*                                                                                                    				*/
/*    null = [RL_2,8,0,12,[3,-1,0,-1,objNull]] execVM "scripts\initTargetRailExt.sqf";                    			*/
/*    Target moves permanently, good for Sniper practice.                                             				*/
/*                                                                                                    				*/
/*    T_1 = [RL_3,5,3,21,[10,1,0,-1,trgDoor_2]] execVM "scripts\initTargetRailExt.sqf";                  			*/
/*    Target fast moving forward, good surprise in Kill houses                                        				*/
/*                                                                                                   				*/
/*  Helper Type:                                                                                      				*/
/*    first digit:  Target Type (Moving Target 1 to 3 and Zombie)                                     				*/
/*    second digit: Accuracy Type (none, accuracy aim, zones)                                         				*/
/*                                                                                                    				*/
/*    23 means using Moving Target 2 with Zones     10 uses Moving Target 1 plain                     				*/
/*    default: 10                                                                                     				*/
/*                                                                                                    				*/
/*  Helper Directions:                                                                                				*/
/*    0) v------   1) <------   2) A------   3) >------   initial direction of 1st rail part is top   				*/
/*         right     backward         left      forward                                               				*/
/*                                                                                                    				*/
/*  Reset nopop-targets:  by Variable Stef_targets_reset      (probably only works with times: -1)    				*/
/*                                                                                                    				*/
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


// reading parameters
_frstRail = _this select 0;    	// Object - first rail segment
_Seg = _this select 1;         	// Number - number of total rail sections
_targetDir = _this select 2;   	// Number - direction the target will face
_type = _this select 3;        	// Number - Type of Target on Rail
_moveArr = _this select 4;		// Array  - array that describes type of movement the target will perform.
_target = objNull;             	// Object - Movable target
_railArr = [];                 	// Array  - Contains all used objects
_downTime = _moveArr select 3;	// Bool   - target will popup on true  (saved as objVar "_nopop")

// building rails

_initPos = getPos _frstRail;   
_aktRail = "Target_Rail_End_F" createVehicle _initPos; // beginning
_aktRail attachTo [_frstRail,[-0.53,0,0]];
_railArr = [_aktRail,_frstRail];

for [{_x=1},{_x<_Seg},{_x=_x+1}] do {                  // rail parts
  _aktRail = "Target_Rail_F" createVehicle _initPos;
  _aktRail attachTo [_frstRail,[_x,0,0]];
  _railArr = _railArr + [_aktRail];
};

_aktRail = "Target_Rail_End_F" createVehicle _initPos; // ending
_aktRail attachTo [_frstRail,[(_Seg - 0.53),0,0]];
_railArr = _railArr + [_aktRail];

// Target_PopUp2_Moving_90deg_F // Target_PopUp2_Moving_90deg_Acc2_F // Target_PopUp2_Moving_90deg_Acc1_F

_type1 = floor (_type / 10); 
_type2 = _type mod 10;

// Set type of target texture
_typeStr = switch (_type1) do {
  case 1: {_accStr = "Target_PopUp_Moving"; _accStr};
  case 2: {_accStr = "Target_PopUp2_Moving"; _accStr};
  case 3: {_accStr = "Target_PopUp3_Moving"; _accStr};
  case 4: {_accStr = "Zombie_PopUp_Moving"; _accStr};
  default {_accStr = "Target_PopUp_Moving"; _accStr};
};

// Set Accuracy texture
_accStr = switch (_type2) do {
  case 0: {_accStr = ""; _accStr};
  case 1: {_accStr = "_Acc1"; _accStr};
  case 2: {_accStr = "_Acc2"; _accStr};
  default {_accStr = ""; _accStr};
};

_target = switch (_targetDir) do {
  case 0: // Target moves right
  {
    _target = (_typeStr + _accStr + "_F") createVehicle _initPos;
    _target setPos (_frstRail modelToWorld [-0.1,0,-0.10]);
    _target setDir (getDir _frstRail); _target
  };
  case 2: // Target moves backward
  {
    _target = (_typeStr + _accStr + "_F") createVehicle _initPos;
    _target setPos (_frstRail modelToWorld [-0.1,0,-0.10]);
    _target setDir (getDir _frstRail -180); _target
  };
  case 1: // Target moves left
  {
    _target = (_typeStr + "_90deg" + _accStr + "_F") createVehicle _initPos;
    _target setPos (_frstRail modelToWorld [-0.1,0,-0.10]);
    _target setDir (getDir _frstRail + 90); _target
  };
  case 3: // Target moves forward
  {
    _target = (_typeStr + "_90deg" + _accStr + "_F") createVehicle _initPos;
    _target setPos (_frstRail modelToWorld [-0.1,0,-0.10]);
    _target setDir (getDir _frstRail - 90); _target
  };
};

// Object Variables
_target setVariable ["_downTime", _downTime, true];
_target setVariable ["_down", false, true];
_target setVariable ["_base", _frstRail, true];
_target setVariable ["_objArr", _railArr, true];

_move = [_moveArr,_seg,_target] execVM "scripts\moveTargetRailExt.sqf";

_target // return value is object Target, frstRail is objVar "_base"
        //                                all objects in objVar "_objArr"

 

 

moveTargetRailExt.sqf:

Spoiler

//////////////////////////////////////////////////////////////////////////////////////////////////////////
/*  moveTargetRailExt.sqf                                                                   			*/
/*  by [W] Steffie                                                                              		*/
/*  v1.3, 16.02.14                                                                               		*/
/*  required: "nopop=true;" in init.sqf                                                         		*/
/*            PopUpTargetExt.sqf v1.0                                                         			*/
/*            initTargetRailExt.sqf v1.3                                                  				*/
/*                                                                                           			*/
/*  [[speed,times,delay,nopop,start,reset],segments,target]                                     		*/
/*                                                                                             			*/
/*  Description:                                                                                     	*/
/*    This script automatically builds an Popup Target rail                                           	*/
/*    First Rail segment is used to place startpoint of railway. All other parts are built auto-      	*/
/*    matically. Movement of the target is controlled by movement-array.                              	*/
/*    It's possible to start movement by connecting a trigger.                                        	*/
/*                                                                                                    	*/
/*  more Information in initTargetRailExt.sqf                                                         	*/
/*                                                                                                    	*/
//////////////////////////////////////////////////////////////////////////////////////////////////////////

// reading parameters
_movArr = _this select 0;      // Array  - array that describes type of movement the target will perform.
_Seg = _this select 1;         // Number - number of total rail sections
_target = _this select 2;      // Number - direction the target will face
_speed = _movArr select 0;     // Number - Speed n/s
_times = _movArr select 1;     // Number - times
_delay = _movArr select 2;     // Number - time target will rest
_downTime = _movArr select 3;   // Bool   - target will popup on true
_start = _movArr select 4;     // Object - Trigger
_reset = _movArr select 5;     // Object - Trigger
_frstRail = _target getVariable "_base"; // baseRail

// custom hit Eventhandler, default disabled by nopop=true; in init.sqf
_target addEventHandler ["HitPart", {[(_this select 0)] execVM 'scripts\PopUpTargetExt.sqf';}];

// calculating distance for movement
_dist = _Seg - 1 + 2*0.05;
_dw = _speed * 0.01;


// if trigger used, wait until it's triggered
if( !isNull _start ) then {
  _target animate ["terc", 1]; 
  waitUntil {triggerActivated _start};
  _target animate ["terc", 0]; 
};

// loop until times over, target not popping up again or endless
_i = 0;  // counting times

while{ (_i < _times || _times == -1)} do {

  _aktw = 0;
  
  // target moving down rail
  while {(_aktw < _dist)  && !(_target getVariable "_down")} do {
  
    _aktw = _aktw + _dw;
    _target setPos (_frstRail modelToWorld [(_aktW - 0.15),0,-0.10]);
    sleep 0.01;
  
  };
  
  _i = _i +1;
  sleep _delay;
  
  // target moving up rail again
  if ( _i < _times || _times == -1) then {  // stop if times over
    while {(_aktw > 0) && !(_target getVariable "_down")} do {
    
      _aktw = _aktw - _dw;
      _target setPos (_frstRail modelToWorld [(_aktW - 0.15),0,-0.10]);
      sleep 0.01;
 
    };
  _i = _i +1;
  sleep _delay;
  };
};

true

 

 

PopUpTarget.sqf:

Spoiler

/*
File: PopUpTarget.sqf
Author: BIS
Description:
Script to make the pop-up target actually pop back up.
Parameter(s):
_this select 0: the pop-up target object.
*/

private ["_target"];
_target = (_this select 0) select 0;
_target setDamage 0;

scopeName "root";

if ((_target animationPhase "terc") <= 0) then 
{
_target animate["terc", 1];

if (!isNil "nopop") then 
{
	if (nopop) then 
	{
		breakTo "root"
	};
};

sleep 3;

if (!isNil "nopop") then 
{
	if (nopop) then 
	{
		breakTo "root";	
	};
};

if (alive _target) then 
{
	_target animate["terc", 0];
};
};

true

 

 

  • Like 3

Share this post


Link to post
Share on other sites

Note the folder structure of the example mission. All script files are located in a subfolder named "scripts" and are being called accordingly. Since you have not followed the same structure, the files are not being found.

 

Hence "script scripts\initTargetRailExt.sqf not found."

 

Easiest fix is to move the three script files (initTargetRailExt.sqf, moveTargetRailExt.sqf, PopUpTargetExt.sqf) to a new subfolder named "scripts."

  • Like 1

Share this post


Link to post
Share on other sites
On 6/24/2017 at 2:40 AM, Harzach said:

Note the folder structure of the example mission. All script files are located in a subfolder named "scripts" and are being called accordingly. Since you have not followed the same structure, the files are not being found.

 

Hence "script scripts\initTargetRailExt.sqf not found."

 

Easiest fix is to move the three script files (initTargetRailExt.sqf, moveTargetRailExt.sqf, PopUpTargetExt.sqf) to a new subfolder named "scripts."

why.. tf... did i get redirected to the board in the middle of me typing a message??

Anyways, I did that, therefore not receiving the error, but the rail didn't generate a target, and there were no call signs available in the radio section of the command menu.

Share this post


Link to post
Share on other sites

Did you place a trigger with a Radio activation?

Share this post


Link to post
Share on other sites
On 6/29/2017 at 11:14 PM, Harzach said:

Did you place a trigger with a Radio activation?

I did that, and the script successfully spawned the additional rails, but it spawned too many targets. I believe that the script spawned approximately ten (give or take five). Also, I changed the Segment amount to 7 (meters, according to the instructions) and it instead spawned a long line of rails.

Share this post


Link to post
Share on other sites

If multiple targets are spawning, I'd guess that's a locality issue. It's mentioned on the source page. You'd see a target for every player on the server. As for the length of the rail, I just tried setting the segment param to "7" and seven rails spawned. Again, maybe a locality thing and seven rails were spawning for each player - though I'd think they would spawn on top of each other in that case. I don't know. If I ever get around to tackling this for MP, I'll be sure to post here.

  • Like 1

Share this post


Link to post
Share on other sites
9 hours ago, Harzach said:

If multiple targets are spawning, I'd guess that's a locality issue. It's mentioned on the source page. You'd see a target for every player on the server. As for the length of the rail, I just tried setting the segment param to "7" and seven rails spawned. Again, maybe a locality thing and seven rails were spawning for each player - though I'd think they would spawn on top of each other in that case. I don't know. If I ever get around to tackling this for MP, I'll be sure to post here.

Please do if possible. It would be much appreciated.

Share this post


Link to post
Share on other sites
On 13/6/2017 at 9:50 PM, Harzach said:

I have not had a chance to test in MP, so I am assuming that the source page is correct in describing this system as not MP-compatible.

 

Is work, but not properly, I mean the target spawn and move but very slowly each 10 seconds more or less.

Do you know how to fix the speed trouble?

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×