Jump to content
Sign in to follow this  
Ice_Rhino

Next Stupid Question - Despawning Units

Recommended Posts

I am trying to despawn a Helo, default crew and two AI named passengers from a trigger activation. I found this little bit of code

{deletevehicle _x} forEach (units _group1);
deleteGroup _group1;

but not sure what the _x or _group is? is the _x the helo name? and _group1 the name of the whle group, Helo wih crew etc? If yes, is the simple method to make my additional two AI part of the helo group??

Do I need all of the {}[]() stuff. Not sure what the difference is between them all

Thanks

Share this post


Link to post
Share on other sites

You could try assigning whatever you spawned as a name

helo1 = "helicopterclass" createVehicle (position player);

Repeat for every unit (crew may be a part of it if you get the right classname, otherwise define those too using the same syntax)

Then just

deletevehicle helo1
deletevehicle crew1
deletevehicle crew2
deletevehicle pass1
deletevehicle pass2

Of course this is a horrible method and there probably is a better way, but it may work for your quick needs whilst someone else replies.

Share this post


Link to post
Share on other sites

To delete a vehicle you need to delete it's crew first. If your helo is flying to a waypoint it's as easy as this:

{deleteVehicle _x} forEach crew (vehicle this) + [(vehicle this)];

Otherwise you'd want something like this:

{deleteVehicle _x} forEach crew heloName + [heloName];

{ } forEach [ ]; is the structure of a forEach command. The { } means "code", as in "this code will be executed" for each elements in the array [ ] list. _x is a magic variable which means "the current value from the list". So take this:

{_x setDamage 1} forEach [unit1, unit2, unit3];

You have a list of 3 units, unit1, unit2 and unit3 in an array. The forEach will step through them running the code inside the { } for each element. Each time _x will be the current value.

So first time through it'll execute the code: unit1 setDamage 1

Second time through it'll execute the code: unit2 setDamage 1

and finally: unit3 setDamage 1

Killing all three units in the array.

Going back to the main example {deleteVehicle _x} forEach crew (vehicle this) + [(vehicle this)];

First we evalute what (vehicle this) is. Since it's a waypoint it's the helicopter the group is flying. So now it's:

{deleteVehicle _x} forEach crew heloName + [heloName];

Next we figure out what crew heloName is. It's an array of all the units inside the helicopter. So pilot, co-pilot, namedGuy1 and namedGuy2. So now we have:

{deleteVehicle _x} forEach [pilot, co-pilot, namedGuy1, namedGuy2] + [heloName];

In this example the actual names of the units doesn't matter for pilot and co-pilot, the engine will know which units. Next we add the heloName to the list of units to delete:

{deleteVehicle _x} forEach [pilot, co-pilot, namedGuy1, namedGuy2, heloName];

And then we forEach through each element deleteVehicle'ing them in turn...

deleteVehicle pilot; then deleteVehicle co-pilot.. and so on.

Make sense?

Share this post


Link to post
Share on other sites

Thanks Comp_, I haven't worked out how to spawn something yet. Just can't seem to find anything decent on the web where I can learn the information. I hate having to ask dumb questions when I am amongst genius's on here. Despite the fact I don't ask the same question twice. I just like to understand something and then move onto the next challenge.

If you know, or anybody for that matter knows, a good example of spawning or despawning script then I would appreciate the heads up.

Thanks

---------- Post added at 22:33 ---------- Previous post was at 22:31 ----------

kylania, thanks for that in depth explanation. I will re-read it again right now.

Share this post


Link to post
Share on other sites

There's four main ways of spawning things. Two commands and two functions.

createUnit will create an AI unit, a soldier for example.

createVehicle will create an object or empty vehicle, such as a road cone or empty helicopter.

BIS_fnc_spawnGroup will create a group of AI units automatically part of a group either based on units listed or pre-defined groups.

BIS_fnc_spawnVehicle will create a single vehicle with appropriate crew as a group.

Share this post


Link to post
Share on other sites

Where you say

To delete a vehicle you need to delete it's crew first. If your helo is flying to a waypoint it's as easy as this:

PHP Code:

{deleteVehicle _x} forEach crew (vehicle this) + [(vehicle this)];  

Otherwise you'd want something like this:

PHP Code:

{deleteVehicle _x} forEach crew heloName + [heloName]; 

Do I need the first one or the second one, or both? What is the _x bit?

Thanks

Share this post


Link to post
Share on other sites

_x is explained above, it's a magical variable that means "the current value". Leave it as _x and only ever use _x in forEach structures to keep yourself sane. :)

Use the top if your helo is flying to a waypoint. In that case it's already a group and we already know what the helo is and who's in it.

If you're not flying to a waypoint but instead something like a doMove to a marker, then you'd want to use the second version where you tell it the name of the helicopter.

Share this post


Link to post
Share on other sites
_x is explained above, it's a magical variable that means "the current value". Leave it as _x and only ever use _x in forEach structures to keep yourself sane. :)

Use the top if your helo is flying to a waypoint. In that case it's already a group and we already know what the helo is and who's in it.

If you're not flying to a waypoint but instead something like a doMove to a marker, then you'd want to use the second version where you tell it the name of the helicopter.

Thanks kylania, very much appreciated

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  

×