Home   Help Search Login Register  

Author Topic: Timers  (Read 2269 times)

0 Members and 1 Guest are viewing this topic.

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Timers
« on: 18 Oct 2006, 20:38:04 »
Anyone looking for a timer?


Code: [Select]
;mandotimer.sqs
;
;Arguments:
;   resolution in seconds, step in second between timer checks
;   timer limit in seconds
;   timer direction 1 counting up, -1 counting down
;   Show elapsed time every timer check? true/false
;   script to be executed when timeout, "" if not needed
;   script to be executed if timer is stopped before timeout, "" if not needed
;
;   To end timer before timeout, set gobal variable globalstoptimer to true
;   global variable globalelapse keeps elapsed time since timer start
;
;Example:
;   1 hour left to accomplish something (countdown type), timer checks every 5 seconds showing elapsed time
;   [5, 3600, -1, true, "gameover.sqs", "youwon.sqs"]exec"mandotimer.sqs"
;
_resolution     = _this select 0
_limit          = _this select 1
_dir            = _this select 2
_show           = _this select 3
_scripttimeout  = _this select 4
_scripttimerend = _this select 5

_elapsed = 0
globalstoptimer = false
?_dir == -1:_elapsed = _limit;_limit = 0

#check
_timeini = time
@((time - _timeini) > _resolution)
_elapsed = _elapsed + _dir * _resolution
?!_show:goto "continue"
_h = (_elapsed/3600)- ((_elapsed/3600)mod 1)
_sr = _elapsed - _h*3600
_m = (_sr/60)- ((_sr/60)mod 1)
_s = _elapsed - _h*3600 - _m*60
_hp = "0"
_mp = "0"
_sp = "0"
?_h > 9:_hp = ""
?_m > 9:_mp = ""
?_s > 9:_sp = ""
?_show:cutText[format["%1%2:%3%4:%5%6",_hp,_h, _mp,_m,_sp,_s], "PLAIN DOWN"]
#continue
globalelapsed = _elapsed
?globalstoptimer: goto "timerend"
?_elapsed != _limit:goto "check"

;Uncomment next line if you want a message indicating timer ended
;?_show:cutText["TIMER END REACHED", "PLAIN DOWN"]

?_scripttimeout != "":[]exec _scripttimeout
exit

#timerend
?_scripttimerend  != "":[]exec _scripttimerend
exit

Offline Wabbit

  • Members
  • *
  • Jeez, I used to have so many posts!
Re: Timers
« Reply #1 on: 18 Oct 2006, 21:13:12 »
Wow, that's a cool idea!  I don't have a use for it now, but I'm sure I will soon!
Thanks!

Offline ZapBrannigan

  • Members
  • *
Re: Timers
« Reply #2 on: 25 Jul 2007, 23:36:04 »
Its good, but how do I make it stop and display the finaly time after a triger has been hit?
and is there a way to make it so it dosent flash on and off and just the numbers change?

thanks

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Timers
« Reply #3 on: 25 Jul 2007, 23:41:56 »
If you want to stop the timer, just globalstoptimer = true. I did apply a slight change so the timer value is shown after the timer is aborted.

Code: [Select]
;mandotimer.sqs
;
;Arguments:
;   resolution in seconds, step in second between timer checks
;   timer limit in seconds
;   timer direction 1 counting up, -1 counting down
;   Show elapsed time every timer check? true/false
;   script to be executed when timeout, "" if not needed
;   script to be executed if timer is stopped before timeout, "" if not needed
;
;   To end timer before timeout, set gobal variable globalstoptimer to true
;   global variable globalelapse keeps elapsed time since timer start
;
;Example:
;   1 hour left to accomplish something (countdown type), timer checks every 5 seconds showing elapsed time
;   [5, 3600, -1, true, "gameover.sqs", "youwon.sqs"]exec"mandotimer.sqs"
;
_resolution     = _this select 0
_limit          = _this select 1
_dir            = _this select 2
_show           = _this select 3
_scripttimeout  = _this select 4
_scripttimerend = _this select 5

_elapsed = 0
globalstoptimer = false
?_dir == -1:_elapsed = _limit;_limit = 0

#check
_timeini = time
@((time - _timeini) > _resolution)
_elapsed = _elapsed + _dir * _resolution
?!_show:goto "continue"
_h = (_elapsed/3600)- ((_elapsed/3600)mod 1)
_sr = _elapsed - _h*3600
_m = (_sr/60)- ((_sr/60)mod 1)
_s = _elapsed - _h*3600 - _m*60
_hp = "0"
_mp = "0"
_sp = "0"
?_h > 9:_hp = ""
?_m > 9:_mp = ""
?_s > 9:_sp = ""
?_show:cutText[format["%1%2:%3%4:%5%6",_hp,_h, _mp,_m,_sp,_s], "PLAIN DOWN"]
#continue
globalelapsed = _elapsed
?globalstoptimer: goto "timerend"
?_elapsed != _limit:goto "check"

;Uncomment next line if you want a message indicating timer ended
;?_show:cutText["TIMER END REACHED", "PLAIN DOWN"]

?_scripttimeout != "":[]exec _scripttimeout
exit

#timerend
;Note the change here
cutText[format["%1%2:%3%4:%5%6",_hp,_h, _mp,_m,_sp,_s], "PLAIN DOWN"]

?_scripttimerend  != "":[]exec _scripttimerend
exit

Offline ZapBrannigan

  • Members
  • *
Re: Timers
« Reply #4 on: 26 Jul 2007, 22:40:09 »
works great. Is there any way to get miliseconds in there and remove hours?
I have a racing mission and need to show the accurate time.

thanks