Jump to content
Sign in to follow this  
victim913

Unit Action question

Recommended Posts

I was wondering how to assign an action to more than 1 unit. Here's my example:

Spongebob action ["eject", uh1];

I want spongebob, Patrick, and squidward to eject. I've tried a few different things like[] (). Also created them with group name and put name in unit's place. But no luck.

***I know there are scripts. In fact that's where I got it from. But i'm trying to understand scripting, not just copying. So what could I do to that code (in the editor, no sqf or execvm stuff) to make that group and/or 3 people eject?

Thanks

Share this post


Link to post
Share on other sites

{
unassignVehicle _x;
_x action ["EJECT", vehicle _x];
sleep 0.4;
} foreach [spongebob, Patrick, Squidward];

We'll actually read this from the bottom up. First thing we do is make a list of the units we'll be ejecting as an array. Arrays are comma seperated lists of things surrounded by [ ]. So we make:

[spongebob, Patrick, Squidward]

Each of those names are objects since they don't have " " around them and therefore aren't strings. You'll need to make sure that the Name field of each of those units has spongebob, Patrick and Squidward in it, respectively.

Then there's the forEach command. The forEach takes the array we created and runs the code (between the { } symbols) for each value in the array. Within the code block each value of the array will be represented as the "magic" variable _x. So first time through the _x will be automatically replaced with spongebob for example.

So the actual code we do is first unassignVehicle _x (unassignVehicle spongebob the first time). Next line is the eject action you're already familiar with. In this case we used the vehicle _x instead of hard coding the uh1 unit name. Lastly we sleep for a quick moment so that everyone doesn't collide.

The one possible drawback is if one of the three guys isn't in the uh1, but might be in another vehicle. This would eject him from whatever vehicle he's in. You could get around this by using:

} forEach assignedCargo uh1;

That would just eject all passengers from the helo instead of three guys specifically.

Share this post


Link to post
Share on other sites

Thanks to both of you. In fact, Kylania, it is your script that I was looking at to begin with. I saw the small link under your name. Explaining it like you guys did should help a lot.

I keep seeing "unassign". I learned to use assign a lot but these are individual units or groups that aren't assigned to any vechicle (uh1) to begin with. So why would I unassign?

One other possible dumb question; The underline before things. " _ " such as this: _numWeapon. Now that I know is How many of that weapon. I know that I have to replace _numWeapon with a number.

I usually know what it means. But I keep seeing codes that have this _x. But _x doesn't need to change all the time. I can put that in a units init and it works, but if I leave _numWeapon in the init then it shows an error.

So how do I understand all the _x in your example?

In your mission you have this:

Grp2 = Group this; {_x moveincargo C_1} ForEach units group this;

You name the group; then {_x you moveincargo} each unit in the group. So what is the _x represent?

Edited by victim913

Share this post


Link to post
Share on other sites

In this case _x points to each unit in the group in turn, same as unit1 moveincargo C_1;unit2 moveincargo C_1;unit3 moveincargo C_1; ect

this wouldn't work in a trigger as this has little meaning

{_x moveincargo C_1} ForEach units group this;

You can use the name of the lead unit if you named him

{_x moveincargo C_1} ForEach units group ted

if the group has been named Grp2 then it would be

{_x moveincargo C_1} ForEach units Grp2

(probably best practice)

"_" infront means local. It only exists in the script or scope it's running in.

It's why you can run the same script at the same time using the same variables as they're kept separate.

Share this post


Link to post
Share on other sites

unassign is a good practice since if you don't do it sometimes units will just get right back into the vehicle. If you're parachuting that isn't much of a problem, but if you're say landing troops it can get annoying watching them clowncar out then right back into the transport!

Any questions about any of this stuff still?

Share this post


Link to post
Share on other sites

Ok, it's making sense. I got the cargo stuff I think.

This,

Grp2 = Group this; {_x moveincargo C_1} ForEach units group this;

in the init of leader will be faster than telling each unit to moveincargo.

But if I put it in a trigger I would use this,

{_x moveincargo C_1} ForEach units Grp2

Using your mission (kylania) as an example:

After I get all the above working, I can this in a trigger

{nul = [_x] execVM ""groupEject.sqf"";} foreach [Grp1, Grp2, Grp3, Grp4, Grp5, Grp6]; SetAccTime 0.7;";

and put your "groupeject.sqf" in my mission folder.

But so I understand, your code is:

_grp = _this select 0; This gives whichever group the 0 value in the next code (which makes it the first which is the _x before action?)

(_x) action ["EJECT", vehicle _x];

and vehicle _x is whichever vehicle they are cargo in.

Then last it tells them to do the same with everyone in that group

foreach units _grp;

If that was alright then hopefully it will sink in. Then i'll look up "sleep" cause I see it in everything. And all the different symbols like the different brackets.

***After all this bother, I just found out that there is a problem with the aircraft I was going to use. It was going to be the AN-72 Coaler. I was able to get it into the game but after trying it I found that I can't get inside it. None of the movein codes work. Also can't get in when it's on the ground. So I have no aircraft to get them to parachute from.

Is there a way to simulate a drop without an aircraft? I'm trying not to use the AllInArma mod but I'll have to find another aircraft that I can get into arma3.

thanks very much everyone

Edited by victim913

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
Sign in to follow this  

×