Home   Help Search Login Register  

Author Topic: New observer script  (Read 1037 times)

0 Members and 4 Guests are viewing this topic.

Robinhansen

  • Guest
New observer script
« on: 16 Apr 2005, 15:45:41 »
Dinger (The one from Coc) made this script for me on request:

_player = player
_targetX = _this select 0
_targetY = _this select 1
_targetZ = _this select 2

_playerPos = getpos _player
_playerX =_playerPos select 0
_playerY = _playerPos select 1
_Xdiff = _TargetX - _playerX
_YDiff = _TargetY - _playerY
_Range = sqrt ((_Xdiff^2)+(_yDiff^2))
?(_Range == 0):goto "wait"
_Xfactor = (_Xdiff/_Range)
_Yfactor = (_YDiff/_Range)
_direction = acos _Yfactor
?(_Xfactor < 0):_direction = 360- _direction
_range = _range - (_range mod 10)
_Direction = _direction - (_direction mod 1)
_DirectionName = format ["%1 Degrees", _Direction]
_title = Format [""+_DirectionName+", %1m", _Range]
hint format [_title, "PLAIN DOWN", .3]

It's designed to give the player who's assigned as mortargunner, artilleryobserver etc. the abillity to click on the map and recive the angle in degrees and distance in meters between the player and the target.

I would like to know how to expand the script so it also messures the angel in the deffirent in heights between the player and the target.

Any suggestions?

bdfy1

  • Guest
Re:New observer script
« Reply #1 on: 16 Apr 2005, 16:06:22 »
Code: [Select]
_player = player
_targetX = _this select 0
_targetY = _this select 1
_targetZ = _this select 2

_playerPos = getpos _player
_playerX =_playerPos select 0
_playerY = _playerPos select 1
_playerZ = _playerPos select 2

_Xdiff = _TargetX - _playerX
_YDiff = _TargetY - _playerY
_ZDiff = _TargetZ - _playerZ
_Range = sqrt ((_Xdiff^2)+(_yDiff^2)+(_zDiff^2))
?(_Range == 0):goto "wait"
_Xfactor = (_Xdiff/_Range)
_Yfactor = (_YDiff/_Range)
_Zfactor = (_ZDiff/_Range)

_direction = acos _Yfactor
_Hdirection = acos _Zfactor

?(_Xfactor < 0):_direction = 360- _direction
_range = _range - (_range mod 10)
_Direction = _direction - (_direction mod 1)
_HdirectionName  = format ["%1 Degrees above", _HDirection]
_DirectionName = format ["%1 Degrees", _Direction]
_title = Format [""+_DirectionName+", %1m", "+_HdirectionName+"",_Range]
hint format [_title, "PLAIN DOWN", .3]
Just secondary school math ;)
...
I guess I fix all quotations at last ... :)
« Last Edit: 16 Apr 2005, 16:15:05 by bdfy1 »

Robinhansen

  • Guest
Re:New observer script
« Reply #2 on: 16 Apr 2005, 16:51:15 »
Well not quite ;)

Quote
_title = Format [""+_DirectionName+", %1m", "+_HdirectionName+"",_Range]

the second last line causes an error and I can't figuer out what's wrong  ???

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re:New observer script
« Reply #3 on: 16 Apr 2005, 17:14:53 »
seems like the double quotes... try

Code: [Select]
_title = Format ["%1 %2 %3",_DirectionName, _Range,_HdirectionName]

that should give exactly the same result...

Robinhansen

  • Guest
Re:New observer script
« Reply #4 on: 16 Apr 2005, 22:58:08 »
Yep! Now it works perfectly fine. Just one thing - I made a mistake, I would like to have the distance in meters not angel (my mistake). :-\

bdfy1

  • Guest
Re:New observer script
« Reply #5 on: 16 Apr 2005, 23:16:36 »
The distance between player and target - _Range . You already have it
Or you want target altitude minus  player one? :)

Robinhansen

  • Guest
Re:New observer script
« Reply #6 on: 16 Apr 2005, 23:39:02 »
I'm mumbling! I mean meters instead of degrees, not angles... 8)

- or + depends of what the altitude is...
« Last Edit: 16 Apr 2005, 23:40:18 by Robinhansen »

bdfy1

  • Guest
Re:New observer script
« Reply #7 on: 21 Apr 2005, 18:45:31 »
 Robinhansen
Did you solve your problem ?
I've just found out that I was wrong :(
The script I posted will not work properly. Math is OK , but it was a mistake to use getpos command. Getpos will return the height above the _ground_ , not above zero level. To get proper height you  have to use ASLheight function or auxiliary trigger/game logic , because they are placed at zero level. I guess , tha's why CoC requires thier obelisk to be on map.
So you should replace
[_playerZ = _playerPos select 2
with  [player] call ASLheight
don't forget to preprocess ASLheight .sqf in init.sqs
You will find ASLheight .sqf in function library.

Offline Terox

  • Former Staff
  • ****
  • Follow the Sappers!
    • zeus-community.net
Re:New observer script
« Reply #8 on: 22 Apr 2005, 00:18:57 »
there's are functions available in the editor depot that will return these values for ya also
Zeus ARMA2 server IP = 77.74.193.124 :2302
Teamspeak IP = 77.74.193.123

Robinhansen

  • Guest
Re:New observer script
« Reply #9 on: 23 Apr 2005, 15:24:13 »
Wow!! I'm short of "OFP Quality time" at the moment due to work, but I'll try it as soon possible and then I'll post some feedback here...

Tnx.
 8)