Home   Help Search Login Register  

Author Topic: detecting unit position in a group  (Read 2054 times)

0 Members and 1 Guest are viewing this topic.

Offline LCD

  • Former Staff
  • ****
    • Everon Cartel
detecting unit position in a group
« 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
"guess being the community has downsides .." - cheetah
Help Perfecting Da Next Best Thing - O-Team Beta

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: detecting unit position in a group
« Reply #1 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 for OFP.
urp!

Offline myke13021

  • Contributing Member
  • **
  • Myke
Re: detecting unit position in a group
« Reply #2 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

Offline LCD

  • Former Staff
  • ****
    • Everon Cartel
Re: detecting unit position in a group
« Reply #3 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
"guess being the community has downsides .." - cheetah
Help Perfecting Da Next Best Thing - O-Team Beta

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: detecting unit position in a group
« Reply #4 on: 22 Oct 2007, 19:49:13 »
It must be an FSM command.
urp!

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: detecting unit position in a group
« Reply #5 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.
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re: detecting unit position in a group
« Reply #6 on: 23 Oct 2007, 19:39:42 »
(units group) find unitname
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: detecting unit position in a group
« Reply #7 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 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*).
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline LCD

  • Former Staff
  • ****
    • Everon Cartel
Re: detecting unit position in a group
« Reply #8 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...
« Last Edit: 23 Oct 2007, 23:32:06 by LCD »
"guess being the community has downsides .." - cheetah
Help Perfecting Da Next Best Thing - O-Team Beta

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: detecting unit position in a group
« Reply #9 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!
« Last Edit: 24 Oct 2007, 00:15:35 by Spooner »
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline LCD

  • Former Staff
  • ****
    • Everon Cartel
Re: detecting unit position in a group
« Reply #10 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


"guess being the community has downsides .." - cheetah
Help Perfecting Da Next Best Thing - O-Team Beta

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: detecting unit position in a group
« Reply #11 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.
« Last Edit: 24 Oct 2007, 00:24:30 by Spooner »
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline LCD

  • Former Staff
  • ****
    • Everon Cartel
Re: detecting unit position in a group
« Reply #12 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
"guess being the community has downsides .." - cheetah
Help Perfecting Da Next Best Thing - O-Team Beta