Editors Depot - Mission Editing and Scripting > ArmA - Editing/Scripting General

Join my group by distance.

(1/2) > >>

The-Architect:
Ok, didn't want to ask in here as the forum is cold and fairly lifeless. However, I can't find the right wording anywhere that gets me close to a simple querie.

I have an addaction. When the player clicks it, I want anyone within 20m to join the player's group. Should be simple but I can't do it.

Any help appreciated.

SoldierEPilot:
init.sqf

--- Code: ---ALLY=[];
{
if (side _x==side player) then {ALLY set [count ALLY, _x]};
} forEach allUnits;
PR=rating player;
player addAction ["Join units", "join.sqf"];
--- End code ---

join.sqf
join.sqf

--- Code: ---private "_ct";
_ct=count units player;
{
if ((alive _x) && (_x distance player<20) && (_ct<12) && (PR>rating _x)) then
{
[_x] join player;
_ct=_ct+1;
}
} forEach (ALLY-units player);
--- End code ---

One can remove "PR>rating _x" fragment
to join units despite of their ranks.

h-:
Or, simplier (you didn't specify if ranks matter so left it out).
You can paste this into a trigger on activation if you wish (just remove the comments first), or in some script (like init.sqf if you wish it to be available right from the start):

--- Code: ---player addAction [
"Join Me", //title of the action
{
(_this select 0) removeAction (_this select 2);//removes the action once used,

// finds man class objects around the player within 20m radius and if on the same side as player joins them silently (without the radio calls)
{
if (side _x == side player) then {
[_x] joinSilent player;
};
} forEach (nearestObjects [player, ["Man"], 20]);
}
];
--- End code ---

EDIT:
Didn't test the above in A1 though, so not 100% it will work :P

EDIT2:
Oh, and in case you weren't already familiar with A1 scripting, it prefers .sqf not .sqs so any script examples we give are in .sqf format (both scripts and functions are now in .sqf) and such scripts have to executed using execVM, not exec.
Just wanted to make sure, not knowing how familiar you are with these thingies...  :dunno:

The-Architect:
Thanks for that guys. Much appreciated.

I've been throwing .sqs and .sqf files into my missions. Behind the scenes they look like Frankenstein's monster but they play really well. I've taken script snippets and full blown scripts from everywhere. I plan to release a campaign soon. I don't mind if only a handful of people play it. I've enjoyed the journey.

savedbygrace:
Ah crap, you mean I have to play Armed Assault again? The torture!!  :whistle:

Navigation

[0] Message Index

[#] Next page

Go to full version