Jump to content
Sign in to follow this  
FdgeKake

Select certain units in a radius

Recommended Posts

A buddy and I have a pararescue mission in the works. We are wanting to grab wounded AI and fly them to an aid station and place them in their own group till we can get them back to the front lines. Is there a way for the join command to only select units in the array that are within a certain radius? I only need units present at the aid station to join the survivor group, not every unit within the array.

Share this post


Link to post
Share on other sites

You can iterate through the array, checking for units that are within a certain distance.

_radius = 20;
_closeUnits = [];
{
if (_myAidStation distance _x < _radius) then
{
	_closeUnits pushBack _x;
};
}forEach _myArray;

Share this post


Link to post
Share on other sites

thanks again for your help DreadedEntity :) , but where would the join group command come into play ? The original plan was to execute this through a trigger. Is this still possible? Or should we find another way to call the script?

Share this post


Link to post
Share on other sites

Okay, for editor placed triggers, I don't think you can use local variables so I rewrote that code using global variables, to join the units to a certain group, make sure the group is named from a global variable, then you can just use joinSilent:

radius = 20;
closeUnits = [];
{
if (myAidStation distance _x < radius) then
{
	closeUnits pushBack _x;
};
}forEach myArray;

closeUnits joinSilent myGroup;

Share this post


Link to post
Share on other sites

Once again thank you for your help im sure you know how for a beginner these things can be very frustrating so receiving advice is a godsend. But unfortunately I am still a bit confused on how I would go about using this particular script. After defining myArray and myAidStation, and placing the sqf into my mission folder should I then simply call the script via the trigger init.? Or am I way off?

BTW- ^ the help you have given so far is gold to me , helping reduce the amount of hair pulling time and also teaching me a few things. Truly Grateful.

Share this post


Link to post
Share on other sites

Oh, I didn't realize that you wanted to execVM a script from the trigger. That means we can use local variables again. Actually, if you want to create a script out of this, we can edit it a little to make it more dynamic:

_aidStation = (_this select 0);
_radius = (_this select 1);
_group = (_this select 2);
_unitArray = (_this select 3);

_closeUnits = [];
{
if (_aidStation distance _x < _radius) then
{
	_closeUnits pushBack _x;
};
}forEach _unitArray;

_closeUnits joinAs _group;

What I've done here is make it so that the script will take input. You probably see a lot of people doing [] execVM "myScript.sqf", well now you can put stuff inside the square brackets!

A usage example: [this, 10, createGroup west, playableUnits] execVM "radiusCheck.sqf"; I'll explain some of the parameters

this - "this" is a magic variable. when used in the editor, it refers to the object itself

10 - pretty simple, this is the range of the effect

createGroup west - this creates a new west group (you can use your own named groups, but this was easier for concept)

playableUnits - returns an array with all playableUnits (this array includes AI, though, so you have to exclude them in the script)

Share this post


Link to post
Share on other sites

:) this is great ! That is a very helpful explanation and I'm pretty sure I see what you have done there in the script. I just tried testing it in the Arma3 editor but I could not produce the desired result. :(

///What i did.

1. Created rediusCheck.sqf (with the script^ inside)& inserted it into mission folder.

2. Placed a game logic object named "aidcenter1"

3. Placed a trigger near ^said game logic and inserted:null = [aidcenter1, 10, createGroup west, playableUnits] execVM "radiusCheck.sqf"; into the activation field of the trigger.

4. Placed two Blufor riflemen (set to playable) one in my squad and the other not. (the unit not in my squad has a "move" waypoint to the trigger area)

5. Sent both units into trigger area.

This did not work for me. I believe im doin it right but I could very well be making a mistake. The desired effect i guess or what i was looking for would be that when any AI unit enters that trigger area they are assigned a new group. Preferably a group of 2 riflemen (not the two mentioned above^) I have placed in the editor and designated "svrgroup" (short for survivor group). I also tried :

null = [aidcenter1, 10, svrgroup, playableUnits] execVM "radiusCheck.sqf";

---------- Post added at 11:29 ---------- Previous post was at 10:45 ----------

Also I turned on my -showScriptErrors. In the editor it returned thus:

'...x;

}forEach _unitArray;

_closeunits |#|joinAs _group; '

Error joinas: Type Array, expected Object

File c:\users\myname\Documents\Arma3 - other

Profiles\myusername\missions\Medic%20Duty.Altis\radiusCheck.sqf, line 14

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  

×