Home   Help Search Login Register  

Author Topic: Average positions of a group  (Read 793 times)

0 Members and 1 Guest are viewing this topic.

Offline icarus_uk

  • Members
  • *
  • LiarLiarPants Inflame True
    • [furryclan]
Average positions of a group
« on: 09 Feb 2003, 21:13:14 »
Ok peoples, a simple getpos problem for you.

A group of soldiers, I was to find the average position of the entire group.

That is, I want to add up all their X co-ordinates, all their Z co-ordinates and all their Y co-ordinates and then divide by the number of people in the group.

I believe that will give me the average group position.  But how to do?
« Last Edit: 09 Feb 2003, 21:13:53 by [icarus_uk] »

Offline LCD

  • Former Staff
  • ****
    • Everon Cartel
Re:Average positions of a group
« Reply #1 on: 09 Feb 2003, 23:17:31 »
try dat script

Code: [Select]
_man = _this select 0
_units = units (group _man)
_avgX = 0
_avgY = 0
_avgZ = 0
_i = 0
_count = count _units

#loop
_man = _units select _i
_avgX = _avgX+(getpos _man select 0)
_avgY = _avgY+(getpos _man select 1)
_avgZ = _avgZ+(getpos _man select 2)
_i = _i+1
? _i < _count : goto "loop"

_avgX = _avgX/_count
_avgY = _avgY/_count
_avgZ = _avgZ/_count

avgPOS = [_avgX,_avgY,_avgZ]

execute - [NameOfUnitFromGroup] exec "scriptname.sqs"

but im not promising nything   ;D  ;)

it wil give avgPOS wich is da avrage position ;D

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

Offline Sui

  • Former Staff
  • ****
    • OFPEC
Re:Average positions of a group
« Reply #2 on: 10 Feb 2003, 01:04:17 »
would it not be easier to just get the position of the leader of the group?

eg.

"marker" setmarkerpos (getpos (leader group))

Or is the group generally running away from the leader all the time?

Offline icarus_uk

  • Members
  • *
  • LiarLiarPants Inflame True
    • [furryclan]
Re:Average positions of a group
« Reply #3 on: 10 Feb 2003, 01:06:13 »
Well the whole set of questions of mine floating around the forums is for a single mortar script.  I want the players (it'll eventually go into a MP mission) to be running the crap away from the enemy.  I dont think its very fair if only one person is targetted, so I want to get the average position of them all.

Offline Sui

  • Former Staff
  • ****
    • OFPEC
Re:Average positions of a group
« Reply #4 on: 10 Feb 2003, 01:08:45 »
Oh ok. I was just thinking that with an 'average' position you may end up with the situation that the mortar doesn't hit anybody... (If say one or two guys were a fair distance behind the rest).

Using the (leader group) you'll always be targetting a group member, as when the current leader dies, a new one takes over... I dunno, just a thought :)

Offline icarus_uk

  • Members
  • *
  • LiarLiarPants Inflame True
    • [furryclan]
Re:Average positions of a group
« Reply #5 on: 10 Feb 2003, 01:15:03 »
True, but I dont mind if no-one is killed.  Infact I want to get the shells landing as close to the players without killing anyone.  Dying from a mortar is no fun, the fun part is running with shells landing right in front of you as you run through the smoke.

Incidently, the average position script works wonders.  I tweaked it slightly into my existing script instead of having a serparate one.
« Last Edit: 10 Feb 2003, 01:51:08 by [icarus_uk] »