OFPEC Forum

Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: duckwilliamson on 05 Oct 2003, 08:42:52

Title: simple: time
Post by: duckwilliamson on 05 Oct 2003, 08:42:52
I just have a simple question:

can anyone give me a quick script or support on how to make a script for time elapsed in a game?

I want the format to be: hr:min:sec
Title: Re:simple: time
Post by: macguba on 05 Oct 2003, 23:42:19
Doesn't the reserved global variable time return the time elapsed since the start of the mission?

I think the command for the time of day in the flashpoint world is daytime.     Watch out - they can be inconsistent by a few seconds.
Title: Re:simple: time
Post by: duckwilliamson on 06 Oct 2003, 06:40:03
well what i want is the time elapsed in the hr:min:sec format ...

the 'time' command gives it in seconds and any methods i use don't give me exact use of seconds ... i'm unsure how to use the % and such commands with remainders to give a proper time readout ...

if anyone can tell me how to make it so that the seconds are properly converted to hrs and mins it would be greatly appreciated ...
Title: Re:simple: time
Post by: Roni on 06 Oct 2003, 07:08:33
Hi

Just passing by and thought that I would throw in my two cents.

I couldn't find an entry for the "int" function in the Command Reference so I don't know whether or not OFP allows it.  "int" basially returns the integer value of a number, so "int(1.375)" would return 1 for example.

***IF*** OFP allows it then your required syntax would be something like this -

_secs = time mod 60
_mins = int(time / 60) mod 60
_hrs = int(time / 3600)

The "mod" function (which IS in the Command Reference !) basically "loops" one number and returns only the remainder.  50 mod 60 is 0 but 70 mod 60 is 10.

For example - a time value of 3730 (say) would read as _hrs = 1, _mins = 2, _secs = 10.

I'm not sure how to output that, but I think the syntax is "The time elapsed is %_hrs : %_mins : %_secs ."  (could be some missing parentheses there)

I think :-\

But if OFP doesn't have an "int" function then you ould be in strife - you need to be able to "lump" seconds and minutes together which without maths functions would require some sort of variable "clock" running in the background - messy.

Hope that this helps.



Roni
Title: Re:simple: time
Post by: KTottE on 06 Oct 2003, 09:28:10
_num = _num - _num (_num mod 1)

The above line will return the remainder of _num.
So if _num is 1.357, it will, after using the above line, be just 1.
Or if _num is 99.1, _num will become just 99.

Using format, this is the correct syntax:

hint format ["First: %1\nSecond: %2\nThird: %3",_num1,_num2,_num3]

That will display the three variables _num1, _num2 and _num3 in a hintbox.
\n is an escape character for a linebreak, so each number will be on it's own line in the hint.
It's very possible to do evaluations inside the format command, like so:

hint format ["Classname: %1",typeOf vehicleName]

But if you will send many things into the format command, I recommend doing all the necessary evaluations and calculations beforehand, like so:

Code: [Select]
_class = typeOf vehicleName
hint format ["Classname: %1",_class]

Now, I'm not sure what kind of maths you'd use to accomplish this, so I leave that up to more talented people ;)
Title: Re:simple: time
Post by: Chris Death on 06 Oct 2003, 16:10:52
Look what i found in the functions database at the
editors depot  :o

http://www.ofpec.com/editors/funcref.php?filter_func=33

maybe this could help yer out

~S~ CD
Title: Re:simple: time
Post by: duckwilliamson on 08 Oct 2003, 04:09:44
well i feel a little amazed ... i spent ten minutes yesterday and - got it!

_time could also be a starting number and you could just add to _time every repetition ...
Code: [Select]
#r
_time=time
_hr=(_time/3600) - ((_time/3600) mod 1)
_min=((_time - (_hr*3600))/60) - (((_time - (_hr*3600))/60) mod 1)
_sec=(_time - (_hr*3600) - (_min*60)) - ((_time - (_hr*3600) - (_min*60)) mod 1)

~1
hint format["%1:%2:%3",_hr,_min,_sec]
goto "r"
exit

thx everyone for your input!
Title: Re:simple: time
Post by: KTottE on 08 Oct 2003, 08:06:12
_time is a reserved variable, it returns the time in seconds since the script start.
So use another variable name than _time, otherwise you will have problems.