Home   Help Search Login Register  

Author Topic: adding an arrea to a position array.  (Read 921 times)

0 Members and 1 Guest are viewing this topic.

Offline GRFoxhound

  • OFPEC Patron
  • ****
    • Armaholic.com
adding an arrea to a position array.
« on: 31 Aug 2006, 08:57:56 »
Hello again!

I am working on a script which checks if a unit is on a position where another unit was earlier. Right now the position has to be totally the same (same X, same Y) otherwise the script wont see the position of the unit to be a position another (or the same) unit has been already.


So I made this script of which I will post some below to be able to explain what I would like.
Code: [Select]
_trigger = _this select 0

_list = list _trigger
_tempObj = ObjNull
_b = 0
unit_oldpos = [[0,0,0]]
_unit = _list select 0 

#start
_i = 0
~2

#checkpos
_unitPos = GetPos _unit
_unitPosX = _unitPos select 0
_unitPosY = _unitPos select 1
_unitPosZ = _unitPos select 2
?((_unitPosX == unit_oldpos select _i select 0) and (_unitPosY == unit_oldpos select _i select 1) and (_unitPosZ == unit_oldpos select _i select 2)) : goto "same"
_i = _i + 1
if (_i < (count unit_oldpos )) then {goto "checkpos"}
goto "explode"


#explode
player sidechat "explosion should be now"
unit_oldpos = (unit_oldpos + [_ExplosionPos])
goto "start"

#same
player sidechat "already exploded here"
goto "start"

Now I would like an extra area of lets say 10 meters around an old position to be added to every "unit_oldpos" just so that if a unit is within 10 meters of an old position (X and Y) the script will consider the position of a unit to be the same.
But making it like this:
Code: [Select]
?((_unitPosX == unit_oldpos select _i select 0 + 10) and (_unitPosY == unit_oldpos select _i select 1 + 10) and (_unitPosZ == unit_oldpos select _i select 2)) : goto "same"

wont work, that will just move the pos 10 meters.

Changing the code to
Code: [Select]
?((_unitPosX <= unit_oldpos select _i select 0 + 10)
wont work neither, now all values lower or equal will be considered true. It should only be for a 10 meter radius.

I really have no clue if this is even possible and if so how to do it. I guess maybe some math???  :scratch:
I never understood math...............not a single thing   :banghead:

Thanks again for your help.


Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re: adding an arrea to a position array.
« Reply #1 on: 31 Aug 2006, 09:03:48 »
Code: [Select]
?(_newx >= (_oldx - 10)) and (_newx <=(_oldx + 10)):_xmatch = true
?(_newy >= (_oldy - 10)) and (_newy <=(_oldy + 10)):_ymatch = true

?_xmatch and _ymatch:goto "same"


Offline GRFoxhound

  • OFPEC Patron
  • ****
    • Armaholic.com
Re: adding an arrea to a position array.
« Reply #2 on: 31 Aug 2006, 22:56:55 »
Thank you again bedges!!  :)

So easy...............you wont believe that I sat in front of my comp the entire evening/night trying to figure out how to do this LOL   :-[