Page 1 of 3
timer object
Posted: Tue Aug 15, 2006 8:42 am
by Kroak
I didn't see this posted anywhere over here, but this is code almost direct from Lax on the other board, and I can't remember the post I saw it in, but since ISXEQ no longer has a buit in timer, I tried it, and it works. Added #Ifndef so it can be added to scripts or includes, and changed name to scripttimer so it doesn't conflict with whatever is left in the current timer datatype.
. Also be sure to remember that this is in milliseconds...
Code: Select all
#ifndef scripttimer
objectdef scripttimer
{
variable uint EndTime
method Set(string Milliseconds)
{
if ${Milliseconds.Right[1].Find[s]}
Milliseconds:Set[${Math.Calc[${Milliseconds.Left[${Math.Calc[${Milliseconds.Length}-1]}]}*1000]}]
EndTime:Set[${Milliseconds}+${Script.RunningTime}]
}
member:uint TimeLeft()
{
if ${Script.RunningTime}>=${EndTime}
return 0
return ${Math.Calc[${EndTime}-${Script.RunningTime}]}
}
member:uint ToText()
{
if ${Script.RunningTime}>=${EndTime}
return 0
return ${Math.Calc[${EndTime}-${Script.RunningTime}]}
}
}
#endif
Just figured I'd post it since I couldn't find the original post on it. (Kinda buried I think)
Edit: Changed it to allow inputting full seconds using "s". In other words, :Set[30s] now works along with :Set[30000].
Added ToText (ty Bardomatic) Now can use "if ${timername}."
Posted: Wed Sep 06, 2006 1:34 am
by bardomatic
I may have gotten carried away, but I use this for my /timer command to time various events/spawns.
Code: Select all
;************************************************************
;variable scripttimer MyTimer
;
;Useage:
; Methods:
; MyTimer:Set[#] (1/10th seconds)
; MyTimer:Set[#s] (# seconds)
; MyTimer:Set[#m] (# minutes)
; MyTimer:Set[hh:mm:ss] (hours:minutes:seconds)
; MyTimer:Set[mm:ss] (minutes:seconds)
; MyTimer:Set[-] (Stop Watch mode)
; Members
; MyTimer (time remaining in 1/10th seconds)
; MyTimer.TimeLeft (time remaining in Milliseconds)
; MyTimer.TotalSeconds (time remaining in Seconds)
; MyTimer.Hours (hours remaining)
; MyTimer.Minutes (minutes remaining 59-0)
; MyTimer.Seconds (seconds remaining 59-0)
; MyTimer.HMS (formatted output HH:MM:SS)
;************************************************************
#ifndef scripttimer
objectdef scripttimer
{
variable bool StopWatch=FALSE
variable uint EndTime
method Set(string settime)
{
if ${settime.Left[1].Equal[-]}
{
StopWatch:Set[TRUE]
EndTime:Set[${Script.RunningTime}]
return
}
if ${settime.Find[:]}
switch ${settime.Count[:]}
{
case 2
settime:Set[${Math.Calc[${settime.Token[1,:]}*3600 + ${settime.Token[2,:]}*60 + ${settime.Token[3,:]}].Int}000]
break
case 1
settime:Set[${Math.Calc[${settime.Token[1,:]}*60 + ${settime.Token[2,:]}].Int}000]
break
default
settime:Set[0]
}
else
switch ${settime.Right[1]}
{
case s
settime:Set[${settime.Left[${Math.Calc[${settime.Length}-1]}]}000]
break
case m
settime:Set[${Math.Calc[${settime.Left[${Math.Calc[${settime.Length}-1]}]}*60].Int}000]
break
case 0
case 1
case 2
case 3
case 4
case 5
case 6
case 7
case 8
case 9
settime:Set[${settime}00]
break
default
settime:Set[0]
}
StopWatch:Set[FALSE]
EndTime:Set[${settime}+${Script.RunningTime}]
}
member:uint TimeLeft()
{
if ${Script.RunningTime}>=${EndTime}
if ${StopWatch}
return ${Math.Calc[${Script.RunningTime}-${EndTime}]}
else
return 0
return ${Math.Calc[${EndTime}-${Script.RunningTime}]}
}
member:uint ToText()
{
if ${Script.RunningTime}>=${EndTime}
if ${StopWatch}
return ${Math.Calc[(${Script.RunningTime}-${EndTime})/100].Int}
else
return 0
return ${Math.Calc[(${EndTime}-${Script.RunningTime})/100].Int}
}
member:uint TotalSeconds()
{
if ${Script.RunningTime}>=${EndTime}
if ${StopWatch}
return ${Math.Calc[((${Script.RunningTime}-${EndTime})/1000)].Int}
else
return 0
return ${Math.Calc[((${EndTime}-${Script.RunningTime})/1000)].Int}
}
member:uint Hours()
{
if ${Script.RunningTime}>=${EndTime}
if ${StopWatch}
return ${Math.Calc[((${Script.RunningTime}-${EndTime})/1000)/3600].Int}
else
return 0
return ${Math.Calc[((${EndTime}-${Script.RunningTime})/1000)/3600].Int}
}
member:uint Minutes()
{
if ${Script.RunningTime}>=${EndTime}
if ${StopWatch}
return ${Math.Calc[((${Script.RunningTime}-${EndTime})/1000)/60%60].Int}
else
return 0
return ${Math.Calc[((${EndTime}-${Script.RunningTime})/1000)/60%60].Int}
}
member:uint Seconds()
{
if ${Script.RunningTime}>=${EndTime}
if ${StopWatch}
return ${Math.Calc[((${Script.RunningTime}-${EndTime})/1000)%60].Int}
else
return 0
return ${Math.Calc[((${EndTime}-${Script.RunningTime})/1000)%60].Int}
}
member:string HMS()
{
variable int h=${Math.Calc[((${EndTime}-${Script.RunningTime})/1000)/3600].Int}
variable int m=${Math.Calc[((${EndTime}-${Script.RunningTime})/1000)/60%60].Int}
variable int s=${Math.Calc[((${EndTime}-${Script.RunningTime})/1000)%60].Int}
if ${Script.RunningTime}>=${EndTime}
if ${StopWatch}
{
h:Set[${Math.Calc[((${Script.RunningTime}-${EndTime})/1000)/3600].Int}]
m:Set[${Math.Calc[((${Script.RunningTime}-${EndTime})/1000)/60%60].Int}]
s:Set[${Math.Calc[((${Script.RunningTime}-${EndTime})/1000)%60].Int}]
return "${If[${h}>0,${h}:,]}${If[${m}>9,${m},0${m}]}:${If[${s}>9,${s},0${s}]}"
}
else
return ""
return "${If[${h}>0,${h}:,]}${If[${m}>9,${m},0${m}]}:${If[${s}>9,${s},0${s}]}"
}
}
#endif
Re: timer object
Posted: Fri Jul 25, 2025 12:27 pm
by xyilla
Re: timer object
Posted: Fri Jul 25, 2025 12:28 pm
by xyilla
Re: timer object
Posted: Fri Jul 25, 2025 12:29 pm
by xyilla
Re: timer object
Posted: Fri Jul 25, 2025 12:30 pm
by xyilla
Re: timer object
Posted: Fri Jul 25, 2025 12:31 pm
by xyilla
Re: timer object
Posted: Fri Jul 25, 2025 12:33 pm
by xyilla
Re: timer object
Posted: Fri Jul 25, 2025 12:34 pm
by xyilla
Re: timer object
Posted: Fri Jul 25, 2025 12:35 pm
by xyilla
Re: timer object
Posted: Fri Jul 25, 2025 12:36 pm
by xyilla
Re: timer object
Posted: Fri Jul 25, 2025 12:37 pm
by xyilla
Re: timer object
Posted: Fri Jul 25, 2025 12:38 pm
by xyilla
Re: timer object
Posted: Fri Jul 25, 2025 12:39 pm
by xyilla
Re: timer object
Posted: Fri Jul 25, 2025 12:40 pm
by xyilla