scottdog62 9 Posted March 9, 2017 Trying to get this simple script to work Charge.sqf { _x setunitpos "up"; _x disableAI "FSM"; _x disableAI "Cover"; _x } forEach units _this; I'm trying to make a script, so that when i activate it in the group leaders Init box, all the AI in the squad stand up and disable FSM, ect. I put " 'this exec "charge.sqf' ". in the group leaders Init box. The problem is its not working.. And I'm unsure of the order to put the code in. Any help would be greatly appreciated Share this post Link to post Share on other sites
duda123 1341 Posted March 9, 2017 Try using https://community.bistudio.com/wiki/execVM isntead of exec. Share this post Link to post Share on other sites
scottdog62 9 Posted March 9, 2017 11 minutes ago, duda123 said: Try using https://community.bistudio.com/wiki/execVM isntead of exec. tried that, keeps coming up with "Init: Type Script, Expected Nothing". when using execVM. Share this post Link to post Share on other sites
scottdog62 9 Posted March 9, 2017 Works if I put the code in the units init box, but not when activating it from script. Share this post Link to post Share on other sites
zulu1 145 Posted March 9, 2017 2 hours ago, scottdog62 said: Works if I put the code in the units init box, but not when activating it from script. Try this: charge.sqf _x= _this select 0; _x setunitpos "up"; _x disableAI "FSM"; _x disableAI "Cover"; then in leaders init field put: nul=[this] execVM "charge.sqf"; This may only work for the leader. Other syntax may be needed for the group. Quote What you had there wasn't linked to anything. By using [this] in the units init it passes the units ID to select 0 in the first line of the script. If you were working with multiple variables it would look like this: _x= _this select 0; _n=_this select 1; _p=_this select 2; _x bla bla bla _n bla bla bla _p bla bla bla in init field Quote nul=[leader, unit_a, unit_b] execVM "charge.sqf"; Share this post Link to post Share on other sites
f2k sel 164 Posted March 9, 2017 To make it work for the whole group you will need to use a group command. There are a few options null=group this execvm "charge.sqf' ". { _x setunitpos "up"; _x disableAI "FSM"; _x disableAI "Cover"; } forEach units _this; or null=this execvm "charge.sqf' ". { _x setunitpos "up"; _x disableAI "FSM"; _x disableAI "Cover"; } forEach units group _this; You also have an extra "_x" in the original post that would cause the script to fail. Share this post Link to post Share on other sites
scottdog62 9 Posted March 9, 2017 Ah yes thanks for the help. zulu1 that works for the individual unit but not for the whole group. thanks f2k sel, ah yes that what I was looking for. thanks Share this post Link to post Share on other sites
serena 151 Posted March 9, 2017 scottdog62, this variable exists and points to the object only in object initialization field. In all other cases it has no value and meaning. Clear? // object initialization field this execVM "script.sqf" // OK, this variable references object // not in object initialization field this execVM "script.sqf" // ERROR, this variable references NOTHING terrorist execVM "killeveryone.sqf" // OK, terrorist variable references concrete unit policesquad execVM "eliminateterrorist.sqf" // OK, policesquad variable references concrete group Share this post Link to post Share on other sites
scottdog62 9 Posted March 9, 2017 @serena Ok yes, that makes sense; Share this post Link to post Share on other sites
scottdog62 9 Posted March 9, 2017 Moving further into the script. { _x setunitpos "up"; _x disableAI "FSM"; _x disableAI "Cover"; _x disableAi "SUPPRESION"; } forEach units group _this; while {Alive leader1} do { { _x setSpeedMode "FUll"; _x setBehaviour "CARELESS"; sleep (2 +(random 4)); _x setBehaviour "COMBAT"; sleep (1 + (random 2)); } forEach units group _this; }; Leader1 is the name I gave the leader of the group. (not sure how to make it the entire squad). I'm trying to get the AI to change there Combat mode from CARELESS to COMBAT every few seconds. The problem is that the AI won't move, the leader just stays put and the squad just raises and lowers their weapons, going from COMBAT to CARELESS mode. Share this post Link to post Share on other sites
serena 151 Posted March 9, 2017 // in init.sqf file inside mission directory // this script auto-executed by game when mission starts SquadControl = { // _this variable here references whole group, not leader unit { _x setunitpos "UP"; //_x disableAI "FSM"; // if you uncomment this line then units wont move _x disableAI "Cover"; _x disableAi "SUPPRESION"; } forEach units _this; // you can set speedmode and behavior once and for group, not individual unit _this setSpeedMode "FUll"; _this setBehaviour "CARELESS"; // check (alive leader _this) - bad idea, because, if leader die, another unit take command while {{alive _x} count units _this > 0} do // check if any alive unit in group { // do something sleep 1; }; // all units die, exit from script }; waitUntil {time > 0}; // wait until mission realy starts //grp variable defined in group leader init field as "grp = group this" grp call SquadControl; // launch squad control function. Sample mission: link Share this post Link to post Share on other sites
scottdog62 9 Posted March 11, 2017 Ok that works in the init. I'm trying now to make the script be called from null=group this execvm "charge.sqf' "; SquadControl = { { _x setunitpos "UP"; _x disableAI "FSM"; _x disableAI "Cover"; _x disableAi "SUPPRESION"; } forEach units _this; _this setSpeedMode "FUll"; _this setBehaviour "CARELESS"; while {{alive _x} count units _this > 0} do { { _x setCombatMode "BLUE"; sleep 5; _x setCombatMode "RED"; sleep 5; } foreach units _this; } }; waitUntil {time > 0}; grp call SquadControl; I want them to only take aim and shoot every 5 seconds so i'v changed there "setCombatMode". the problem is I don't think its working. I've also tried adding grp = group this I'm not getting any errors ingame. any help appreciated. Share this post Link to post Share on other sites
serena 151 Posted March 11, 2017 Try this: // in group leader init field _tmp = (group this) execVM "myscript.sqf"; // in myscript.sqf file { _x setUnitPos "UP"; //_x disableAI "FSM"; // if you uncomment this line then units probably wont move _x disableAI "Cover"; _x disableAi "SUPPRESION"; } forEach units _this; _this setSpeedMode "FUll"; while {{alive _x} count units _this > 0} do { sleep 5; _this setCombatMode "BLUE"; sleep 5; _this setCombatMode "RED"; }; Share this post Link to post Share on other sites