timer object

Moderator: MacroQuest Developers

Kroak
a grimling bloodguard
a grimling bloodguard
Posts: 1801
Joined: Thu Sep 15, 2005 4:10 am

timer object

Post by Kroak » Tue Aug 15, 2006 8:42 am

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}."

bardomatic
a ghoul
a ghoul
Posts: 131
Joined: Thu Apr 29, 2004 12:09 am

Post by bardomatic » Wed Sep 06, 2006 1:34 am

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

xyilla
naggy
naggy
Posts: 33673
Joined: Sun Feb 23, 2025 5:36 am

Re: timer object

Post by xyilla » Fri Jul 25, 2025 12:27 pm


xyilla
naggy
naggy
Posts: 33673
Joined: Sun Feb 23, 2025 5:36 am

Re: timer object

Post by xyilla » Fri Jul 25, 2025 12:28 pm


xyilla
naggy
naggy
Posts: 33673
Joined: Sun Feb 23, 2025 5:36 am

Re: timer object

Post by xyilla » Fri Jul 25, 2025 12:29 pm


xyilla
naggy
naggy
Posts: 33673
Joined: Sun Feb 23, 2025 5:36 am

Re: timer object

Post by xyilla » Fri Jul 25, 2025 12:30 pm


xyilla
naggy
naggy
Posts: 33673
Joined: Sun Feb 23, 2025 5:36 am

Re: timer object

Post by xyilla » Fri Jul 25, 2025 12:31 pm


xyilla
naggy
naggy
Posts: 33673
Joined: Sun Feb 23, 2025 5:36 am

Re: timer object

Post by xyilla » Fri Jul 25, 2025 12:33 pm


xyilla
naggy
naggy
Posts: 33673
Joined: Sun Feb 23, 2025 5:36 am

Re: timer object

Post by xyilla » Fri Jul 25, 2025 12:34 pm


xyilla
naggy
naggy
Posts: 33673
Joined: Sun Feb 23, 2025 5:36 am

Re: timer object

Post by xyilla » Fri Jul 25, 2025 12:35 pm


xyilla
naggy
naggy
Posts: 33673
Joined: Sun Feb 23, 2025 5:36 am

Re: timer object

Post by xyilla » Fri Jul 25, 2025 12:36 pm


xyilla
naggy
naggy
Posts: 33673
Joined: Sun Feb 23, 2025 5:36 am

Re: timer object

Post by xyilla » Fri Jul 25, 2025 12:37 pm


xyilla
naggy
naggy
Posts: 33673
Joined: Sun Feb 23, 2025 5:36 am

Re: timer object

Post by xyilla » Fri Jul 25, 2025 12:38 pm


xyilla
naggy
naggy
Posts: 33673
Joined: Sun Feb 23, 2025 5:36 am

Re: timer object

Post by xyilla » Fri Jul 25, 2025 12:39 pm


xyilla
naggy
naggy
Posts: 33673
Joined: Sun Feb 23, 2025 5:36 am

Re: timer object

Post by xyilla » Fri Jul 25, 2025 12:40 pm