OFPEC Forum

Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting General => Topic started by: LCD on 22 Oct 2007, 01:15:36

Title: detecting unit position in a group
Post by: LCD on 22 Oct 2007, 01:15:36
simple thing... shud b... i wanna know wich number da unit is in da group (as in 1,2,3... ya know.... da number da unit gets b4 its radio chatter :D)

LCD OUT
Title: Re: detecting unit position in a group
Post by: Mr.Peanut on 22 Oct 2007, 15:54:13
I thought there was a new ArmA command that did this, but if there isn't Gen Barron wrote the following function (http://www.ofpec.com/ed_depot/index.php?action=details&id=139&page=1&game=OFP&type=fu&cat=xyz) for OFP.
Title: Re: detecting unit position in a group
Post by: myke13021 on 22 Oct 2007, 16:04:37
A short look in the ofpec comref showed me this:

http://www.ofpec.com/COMREF/index.php?action=list&game=All&letter=f#formationPosition

Unsure if it is what you need.


Myke out
Title: Re: detecting unit position in a group
Post by: LCD on 22 Oct 2007, 17:57:51
formationposition returns a posirion (an array)... doesnt seem 2 b a command...

thjx 4 da help Pnut :P  :D

LCD OUT
Title: Re: detecting unit position in a group
Post by: Mr.Peanut on 22 Oct 2007, 19:49:13
It must be an FSM command.
Title: Re: detecting unit position in a group
Post by: Spooner on 23 Oct 2007, 17:58:28
The only place I've seen it (formationposition) is in the FSMs, but I don't think that makes it a "FSM command" as such. I think it gives the position of the individual relative to the group leader, based on the current formation, and the standard FSM uses this information to correct the individual AI's positions as the group leader moves.
Title: Re: detecting unit position in a group
Post by: h- on 23 Oct 2007, 19:39:42
(units group) find (http://www.ofpec.com/COMREF/index.php?action=list&game=All&letter=f#find) unitname
Title: Re: detecting unit position in a group
Post by: Spooner on 23 Oct 2007, 21:19:42
Your number isn't always the same as your number in the units array. What about when someone dies or changes group? If the leader dies, then soldier 2 become 1 in the group array, but this new leader should still have the group number 2 they had at the start, not 1 (I'm numbering from 1 here, since this is where the group numbers start counting, not the 0 that arrays start at). I think adapting Gen Barron's function (http://www.ofpec.com/ed_depot/index.php?action=details&id=139&page=1&game=OFP&type=fu&cat=xyz) from the OPF version is the best bet, as Mr Peanut suggested (Needs changing, since ArmA has no 12-man group-limit, though I can't imagine why I'd want a larger group *shrugs*).
Title: Re: detecting unit position in a group
Post by: LCD on 23 Oct 2007, 23:29:30
ok i tried it... doesnt seem 2 work :P

if ny1 can edit da script 2 go good with ArmA ? i tried modifing it myself also... and it wont work also ::)

LCD OUT

[edit] ok it seems dat it works 4 unit dat dont have variable name.... or somin like that...
Title: Re: detecting unit position in a group
Post by: Spooner on 24 Oct 2007, 00:10:26
Yes, as far as I can see it is not MP compatible (since it assumes that only the local player can have a name), whereas in an MP game, any player can have a name. Simplest fix for that is just to replace:
Code: [Select]
if (_this == player) then {if(format ["%1",_this] == format["%1:%2 (%3)", _grp, _i, name _this]) then {_ret = true;};};

with:
Code: [Select]
if (isPlayer _this) then {if(format ["%1",_this] == format["%1:%2 (%3)", _grp, _i, name _this]) then {_ret = true;};};

If it still causes problems with AI with identities set (not used them myself, so I can't say whether it would), just use:
Code: [Select]
if(format ["%1",_this] == format["%1:%2 (%3)", _grp, _i, name _this]) then {_ret = true;};

In case it wasn't obvious, you might need to increase the "13" in "while {!_ret AND _i <= 13} do" to a higher number, since that limits the result to 1 to 12 (i.e. 12-man groups).

**EDIT**
Actually, what that actually does is limit the number to 1 to 14 (14-man groups) in ArmA, but that wasn't an issue in OFP so the faulty logic wasn't an problem!
Title: Re: detecting unit position in a group
Post by: LCD on 24 Oct 2007, 00:13:02
da prob aint MP compatibilty :P heres da fix i found (dis how new file looks)

Code: [Select]
private ["_i", "_grp", "_ret"];

_ret = false;
_grp = group _this;
_i = 0;
_var = vehicleVarName _this;
_this setvehiclevarname "";

while {!_ret AND (_i < count units group _this)} do
{
_i = _i + 1;
if (format ["%1",_this] == format["%1:%2", _grp, _i]) then {_ret = true;};
if (_this == player) then {if(format ["%1",_this] == format["%1:%2 (%3)", _grp, _i, name _this]) then {_ret = true;};};
};

_this setvehiclevarname _var;

_i

i had 2 remove da vehiclevariable and return it back after it finds da vehicle...

LCD OUT


Title: Re: detecting unit position in a group
Post by: Spooner on 24 Oct 2007, 00:21:32
Well, there will be MP issues if you use the script in MP, even if you haven't had them yet ;P All you need is "isPlayer _this" rather than "_this == player" though.

You are right about the vehicle var name issue though and I can see that your solution sorts that out. I hadn't understood what you meant.

Alas, using "_i < count units group _this" won't work in OFP or ArmA, since, as I explained earlier, the current number of units in a group doesn't tell you how many it had originally. e.g. If you started off with a group of 10 men and the first 9 died, then check the group number of the 10th man, then that function will actually return 1, not 10. This is why the original author used a specific value, not the size of the group to limit the loop.
Title: Re: detecting unit position in a group
Post by: LCD on 24 Oct 2007, 00:44:24
Quote
Alas, using "_i < count units group _this" won't work in OFP or ArmA, since, as I explained earlier, the current number of units in a group doesn't tell you how many it had originally. e.g. If you started off with a group of 10 men and the first 9 died, then check the group number of the 10th man, then that function will actually return 1, not 10. This is why the original author used a specific value, not the size of the group to limit the loop.

right... didnt actualy think bout it :D thx 4 reminding me ;) :D

LCD OUT