OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: Robinhansen 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?
-
_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 ... :)
-
Well not quite ;)
_title = Format [""+_DirectionName+", %1m", "+_HdirectionName+"",_Range]
the second last line causes an error and I can't figuer out what's wrong ???
-
seems like the double quotes... try
_title = Format ["%1 %2 %3",_DirectionName, _Range,_HdirectionName]
that should give exactly the same result...
-
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). :-\
-
The distance between player and target - _Range . You already have it
Or you want target altitude minus player one? :)
-
I'm mumbling! I mean meters instead of degrees, not angles... 8)
- or + depends of what the altitude is...
-
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.
-
there's are functions available in the editor depot that will return these values for ya also
-
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)