Jump to content

Recommended Posts

Hello,

I'm new to Arma 3 and its weird and crazy scripting language. I do have a background in computer programing in case it is relevant. I'm currently building a mission where I want the enemy AI (OPFOR) to garrison into the buildings and not move from their positions. I have given them the command to garrison (and they do it without a hitch). The issue I'm running into is that whenever someone (me) enters their territory they all leave their posts. I want them to stay in the buildings. I have created a trigger that is set off when they are all garrisoned (using a boolean variable that becomes true). The trigger has this in its "On Activation" box:
 

_units = [alpha_1_1, alpha_1_2, alpha_1_3, alpha_1_4];
{_x disableAI "PATH"} forEach units group _units;

//I have also tried
_units = [alpha_1_1, alpha_1_2, alpha_1_3, alpha_1_4];
{_x disableAI "PATH"} forEach _units;

each member of _units (alpha_1_1, alpha_1_2, etc...) is a whole group with at least 7 soldiers in it. The main problem with this is I get the error message
"Type group expected Object."

I'm not proficient enough with this scripting language, can someone tell me how to possibly get around this?

Thank you! Any help would be greatly appreciated!

Share this post


Link to post
Share on other sites

Hello! Try and take a look at this video from Gunter, who's also a member here in forums. I dare to say it will help you a lot by solving that.
Also, perform a search for "hunt" in his channel, so you will find some really cool ideas for those "garrison-and-hunt" situations.

 

  • Like 2

Share this post


Link to post
Share on other sites

Try this, untested:

_units = [alpha_1_1, alpha_1_2, alpha_1_3, alpha_1_4]; {_x disableAI "ALL"} forEach units this;

 

An alternative is

_units = [alpha_1_1, alpha_1_2, alpha_1_3, alpha_1_4]; {_x enableSimulation false;} forEach units this;

 

But as JCataclisma has posted my video for the TOG Garrison script, that script will do what your looking to do,

just a warning when using that script and the ai is garrisoned is dont use any AI enhancement mods,

at least not Lambs or VcomAI as they will leave their positions.

    Hope that helps!

  • Like 1

Share this post


Link to post
Share on other sites

Thank you both for you replies!
Gunther your code was of great help! It helped me understand the syntax and a few of the functions on Arma.

Here's the code I used for anyone else running into this issue. I put this in the trigger activation box with a boolean variable called _activated as the trigger, the boolean variable is initiated as false in group composition init (alpha_1_1). _activated is set to true once they're done garrisoning:

 

_i = 0;
_units = [alpha_1_1, alpha_1_2, alpha_1_3, alpha_1_4];
 while { i < count(_units) } do {

_ref = _units select i;
{_x disableAI "PATH"} forEach _ref;
i = i+1;
}

 

Share this post


Link to post
Share on other sites
52 minutes ago, Trickshot1994 said:

with a boolean variable called _activated as the trigger, the boolean variable is initiated as false in group composition init

 

That's a local variable, which would not work in this case, so I'm curious as to what's actually going on.

  • Like 1

Share this post


Link to post
Share on other sites

Perhaps I'm mistaken but local variables are accessible all throughout mission.sqf right? Perhaps I'm mistaken though but it seems to be working here (tested it a couple of times/ unless there's a bug where it's working but shouldn't). 

P.S: I'm also very unfamiliar with how triggers are coded in the sqf files of the mission so perhaps I'm wrong.

If someone could test this as well and let me know I'd welcome any feedback!

Share this post


Link to post
Share on other sites

Clarification: the reason I suspect that it's accessible throughout the mission.sqf file is because when you set a variable name (for example a trigger called trigger1) it's accessible by other objects in the file. If you initialize a variable called _activated in a group init, I believe it works similarily. Am I missing something?

Share this post


Link to post
Share on other sites

Final solution
Harzach was correct, I should use global variables by declaring activated instead of _activated. The trigger was not being accessed. 
Thank you Harzach!

Now I had another issue which is that other parts of my code were also incorrect and were not being accessed. Here's the correct code:
 

_i = 0;
_units = [alpha_1_1, alpha_1_2, alpha_1_3, alpha_1_4];


while {_i <= count (_units) } do 
{ 
_ref = _units select _i; 
{_x disableAI "MOVE"} forEach units _ref;
_i = _i+1 ; 
};

Explanation:
_units = the units I want selected.
As long as _i is less than the number of elements in _units go through each element of the array _units (one by one) and put it in variable _ref. For the unit selected in variable _ref execute disableAI "MOVE" and specify that _ref contains a unit not a single soldier.
increment _i each time you do this until you've gone through all 4 elements of _units.

If anyone wants to amend my code (refactor) or provide a simpler/ more efficient way of doing this. Please let me know!

I want to thank everyone who replied to this thread as they have all contributed a great deal to me reaching this solution.

Edited by Trickshot1994
Typos
  • Like 1

Share this post


Link to post
Share on other sites

I have 15 units (each alpha references an entire unit not just one soldier) each one placed near a building. I want them all garrisoned with no one patrolling. 
I put this code in the init.sqf file but after a few successful garrisons I get the _ref undefined variable.

if (isServer) then {
sleep 1;
_units = [alpha_1_1, alpha_1_2, alpha_1_3, alpha_1_4, alpha_1_5, alpha_1_6, alpha_2_1, alpha_2_2, alpha_2_3, alpha_2_4, alpha_2_5, alpha_2_6, alpha_3_1, alpha_3_2, alpha_3_3];
_i = 0;
nul = [];
while {_i <= count (_units)}  do 
{
sleep 2;
_ref = _units select _i;
{_x disableAI "PATH"} forEach units _ref;
{ nul = [_x,25,8,0,true] execVM "tog_garrison_script.sqf"} forEach units _ref;

_i = _i + 1;

};
};


What am I doing wrong?

 

Share this post


Link to post
Share on other sites

Count _units > select _i because selection starts at 0. So a while {_i < count _units}  should do the trick.

 

Anyway, if I'm right alpha_1_1, alpha_1_2... are group variable names, not call sign! (and not really units in term of scripting)

if (isServer) then {
  private _grps = [alpha_1_1, alpha_1_2, alpha_1_3, alpha_1_4, alpha_1_5, alpha_1_6, alpha_2_1, alpha_2_2, alpha_2_3, alpha_2_4, alpha_2_5, alpha_2_6, alpha_3_1, alpha_3_2, alpha_3_3];
  private _units = flatten (_grps apply {units _x});
  {_x disableAI "PATH"} forEach _units;
  [_x,25,8,0,true] execVM "tog_garrison_script.sqf";
};

Nothing more. Simple no?

Share this post


Link to post
Share on other sites
1 hour ago, Trickshot1994 said:

What am I doing wrong?

imo your making it more complicated then what it is, the code is redundant when also using the garrison script too,

the script does what your looking to do without adding to it.

     nul = [this] execVM "tog_garrison.script";

Is all you need, put that in a squad leader's init box of a squad or squads and they will be garrisoned and not move.

Share this post


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

Count _units > select _i because selection starts at 0. So a while {_i < count _units}  should do the trick.

 

Anyway, if I'm right alpha_1_1, alpha_1_2... are group variable names, not call sign! (and not really units in term of scripting)


if (isServer) then {
  private _grps = [alpha_1_1, alpha_1_2, alpha_1_3, alpha_1_4, alpha_1_5, alpha_1_6, alpha_2_1, alpha_2_2, alpha_2_3, alpha_2_4, alpha_2_5, alpha_2_6, alpha_3_1, alpha_3_2, alpha_3_3];
  private _units = flatten (_grps apply {units _x});
  {_x disableAI "PATH"} forEach _units;
  [_x,25,8,0,true] execVM "tog_garrison_script.sqf";
};

Nothing more. Simple no?

Thank you for your answer Pierremgi, it's really helpful. I perhaps should have mentioned this but I named the squad's variable name to alpha_1_1, alpha_1_2 to keep track of them while scripting. So I think those references are solid. However, you were correct in your statement that I should remove the <= in while { _i < count (_units)}. I will give your code a try and report back!

Share this post


Link to post
Share on other sites
7 hours ago, Gunter Severloh said:

imo your making it more complicated then what it is, the code is redundant when also using the garrison script too,

the script does what your looking to do without adding to it.

     nul = [this] execVM "tog_garrison.script";

Is all you need, put that in a squad leader's init box of a squad or squads and they will be garrisoned and not move.

Are you sure? When I checked your code I didn't see a script that would disable them from moving. The problem I have is that when I enter a location they all converge to my position. I want them in their buildings even if they're assaulted.

Share this post


Link to post
Share on other sites

Gunter, I've implemented your code in a fresh scenario and it's working fine. However, when I try to do it in my existing scenario I get "Error undefined variable in expression _pos" (Line 110) What do you think could be causing this? I know I messed something up 😅
 

I should mention that I did what you said and put the nul = [this] execVM "tog_garrison.script"; in the group leader's init box.

Share this post


Link to post
Share on other sites

Would need to see the entire code to determine that, but seems like you havent defined a name for something thats being called.

So go to line 110, assuming your using notepad++ and look at the code there, and see what its asking for, something not defined there.

 

  • Like 1

Share this post


Link to post
Share on other sites

I removed all code, mods and created a fresh scenario. Executed the code tog_ garrison script on 1 squad leader's init (instead of many in case it was contributing to the issue) and it was still giving me the error. For some reason, when _pos returns 0 and causes the issue. I think this may be a bug.

Share this post


Link to post
Share on other sites

I never had an issue with that script, no errors, so about all i can tell you is make sure your

using the correct code to call the script, its at the top of the script itself.

Share this post


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

I removed all code, mods and created a fresh scenario. Executed the code tog_ garrison script on 1 squad leader's init (instead of many in case it was contributing to the issue) and it was still giving me the error. For some reason, when _pos returns 0 and causes the issue. I think this may be a bug.


I am less than rookie in such subject, but most of the times I get that kind of error ("undefined variable") it's related to the global/local stuff mentioned by Harzach.
In my case, usually it's because I ended up throwing the script "inside" another function or previous existing stuff, let's say, I add it in a trigger which was already being used for other scripts, and it is no longer passing that required variable to the flow.

Could you have maybe forgotten some "{  };" somewhere in your script, from previous attempts?


 

 

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

×