OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: reedwasere on 11 Dec 2004, 13:14:18
-
Hey everyone...
I wrote this script for an addon of mine - the Australian Defence Forces ARH Tiger
(http://xs6.xs.to/pics/04501/clp13.jpg)
What it does is detects the Speed/Altitude of a helicopter and then changes the Heads up Display as needed.
_heli = _heli select 0
#loop
? ! isengineon _heli: goto "end"
_alt = getpos _heli select 1
_speed = speed _heli
? _alt > 9999 : _alt = ["e","e","e","e"], goto "next"
? _alt < 0 : _alt = [0,0,0.0], goto "next"
#next
? _speed > 9999 : _alt = ["e","e","e","e"], goto "display"
? _speed < 0 : _alt = [0,0,0,0], goto "display"
#display
_heli setobjecttexture [6, format ["\ADF_ARHtiger\hud\num%1.paa", _alt select 0]]
_heli setobjecttexture [7, format ["\ADF_ARHtiger\hud\num%1.paa", _alt select 1]]
_heli setobjecttexture [8, format ["\ADF_ARHtiger\hud\num%1.paa", _alt select 2]]
_heli setobjecttexture [9, format ["\ADF_ARHtiger\hud\num%1.paa", _alt select 3]]
_heli setobjecttexture [10, format ["\ADF_ARHtiger\hud\num%1.paa", _speed select 0]]
_heli setobjecttexture [11, format ["\ADF_ARHtiger\hud\num%1.paa", _speed select 1]]
_heli setobjecttexture [12, format ["\ADF_ARHtiger\hud\num%1.paa", _speed select 2]]-
_heli setobjecttexture [13, format ["\ADF_ARHtiger\hud\num%1.paa", _speed select 3]]
~0.5
goto "loop"
#end
_heli setobjecttexture [6, ""]
_heli setobjecttexture [7, ""]
_heli setobjecttexture [8, ""]
_heli setobjecttexture [9, ""]
_heli setobjecttexture [10, ""]
_heli setobjecttexture [11, ""]
_heli setobjecttexture [12, ""]
_heli setobjecttexture [13, ""]
exit
disregard the 'setobjecttexture' line it is of no importance to the problem.
basicly i have the altitude of the helicopter (stored as "_alt")
so lets assume...
_alt = 1234
now what i want to do is seperate _alt into it's digits for instance
_alt = [1,2,3,4]
like this, I can use a format command to select the digit I want and using that number I can run the setobjecttexture line. (don't worry about how I do this, I understand it)
_heli setobjecttexture [6, format ["\ADF_ARHtiger\hud\num%1.paa", _alt select 0]]
so in simple words i want to know a method to select single digits out of a multiple digit number or convert a number to a string as I showed.
Number to String Conversion
but how the fornicate do I do it? :P
Thanks for you help guys
Reed
-
I haven't checked this or anything, I'll leave that to you.
Syntax is not quaranteed to be accurate, but is probably ok.
_altarr = []
(_altarr select 0) = ((_alt/1000)-(_alt mod 1000) ; _alt = _alt - ((_altarr select 0) * 1000)
(_altarr select 1) = ((_alt/100)-(_alt mod 100) ; _alt = _alt - ((_altarr select 1) * 100)
(_altarr select 2) = ((_alt/10)-(_alt mod 10) ; _alt = _alt - ((_altarr select 2) * 10)
(_altarr select 3) = _alt
hint format ["%1 - %2 - %3 - %4", altarr select 0, altarr select 1, altarr select 2, altarr select 3,]
The hint line is only there to check the 4 elements of the array come out ok.
Anyway, play with it until it works the way you want.
There is maybe a simpler way of doing this, but thats what I came up with, only took about 10 mins. ::)
Planck
-
thanks mate!!! you're a champion!
-
Instead of:
(_altarr select 0) = .....
(_altarr select 1) = .....
It is better to use:
_altarr set [0, ..... ]
_altarr set [1, ..... ]
;)
-
Ok, time to 'pick a nit' ;D
It is better to use
How so?
Does exactly the same thing...
set is 'more pro'? ;) :P ;D
-
I have worked it out!
I used a variation on what Planck posted...
_altarr = [0,0,0,0]
_altarr0 = 0
_altarr1 = 0
_altarr2 = 0
_altarr3 = 0
_altarr0 = (_alt / 1000) - (_alt mod 1000 / 1000)
_altarr set [0, _altarr0]
_altarr1 = (_alt / 100) - (_alt mod 100 / 100) - (10 * _altarr0)
_altarr set [1, _altarr1]
_altarr2 = (_alt / 10) - (_alt mod 10 / 10) - ((100 * _altarr0) + (10 * _altarr1))
_altarr set [2, _altarr2]
_altarr3 = _alt - ((1000 * _altarr0) + (100 * _altarr1) + (10 * _altarr2))
_altarr set [3, _altarr3]
_speedarr = [0,0,0,0]
_speedarr0 = 0
_speedarr1 = 0
_speedarr2 = 0
_speedarr3 = 0
_speedarr0 = (_speed / 1000) - (_speed mod 1000 / 1000)
_speedarr set [0, _speedarr0]
_speedarr1 = (_speed / 100) - (_speed mod 100 / 100) - (10 * _speedarr0)
_speedarr set [1, _speedarr1]
_speedarr2 = (_speed / 10) - (_speed mod 10 / 10) - ((100 * _speedarr0) + (10 * _speedarr1))
_speedarr set [2, _speedarr2]
_speedarr3 = _speed - ((1000 * _speedarr0) + (100 * _speedarr1) + (10 * _speedarr2))
_speedarr set [3, _speedarr3]
It's working ;D ;D ;D
Thanks for all your help guys!
-
Ok, time to 'pick a nit' ;DHow so?
Does exactly the same thing...
set is 'more pro'? ;) :P ;D
No, simply because that is what that command was designed for.