User Tools

Site Tools


scripting:reference:time

Time Functions and Values

Sometimes you'll want to script events that happen at a certain time (e.g. A minigame that runs every hour, or a special script that runs every Thursday at 7pm).

The main events for hourly events are “OnTheHour” (called every hour with no parameter) and “RealTimeClock” (where the event parameter specifies the time for this event - i.e. Event( “RealTimeClock”, “14” ) is triggered once a day at 2pm.

You can use the sys function sysRealTime to get the current realtime date (or you can also use the system value $gRealTimeDayOfWeek to get the day of the week - 1 is Sunday, 7 is Saturday.)

RealTimeClock

Triggered by Realtime clock reaching the specified hour
Event Parameter Hour 0 - 23
CancelTransaction N/A

Example

$maDaysOfWeek[] = {  "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }

Event( "RealTimeClock", "14" )
{
    *say It is 2pm on $maDaysOfWeek[$gRealTimeDayOfWeek]  !!
}

OnTheHour

Triggered by Realtime clock reaching the hour
Event Parameter None
CancelTransaction N/A

Example

Event( "OnTheHour", "" )
{
    $numBongs = sysRealTime("Hour")
    if ( $numBongs > 12 )
    {
        $numBongs -= 12
    }
    $loop = 0
    while ( $loop < $numBongs )
    {
       	*customsoundall 1
       Sleep(10)
       $loop += 1
    }
}

sysRealTime

Format sysRealTime ( Type )
Description Returns details of the current real time (according to the server clock)
Returns Depending on the type field:
Year - returns the current year (e.g. 2014)
Month - returns the current month number (1 to 12)
Day - returns the current day number (1 to 31)
WeekDay - returns the current day of the week (1 to 7)
Hour - returns the current hour (0 to 23)
Minute - returns the current minute (0 to 59)
Second - returns the current second (0 to 59)
UnixTime - number of seconds passed since 1st Jan, 1970

Example:

Event( "UseItem", "Tea" )
{
   $hour = sysRealTime( "Hour" )
   if ( $hour < 18 )
   {
      *msg %PLAYER% Tea can only be used at tea-time (6pm - 8pm)
    }
    else if ( $hour >= 20 )
    {
      *msg %PLAYER% Tea can only be used at tea-time (6pm - 8pm)    
    }
    else
    {
        *notifylarge %PLAYER% Tea-time!
    }
}
scripting/reference/time.txt · Last modified: 2023/05/18 08:11 by mit

Except where otherwise noted, content on this wiki is licensed under the following license: Public Domain
Public Domain Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki