Scripting/Squirrel/Client Functions/System::GetDate: Difference between revisions
		
		
		
		Jump to navigation
		Jump to search
		

This wiki is using an old backup from 2020
Some information may be old/missing
| No edit summary | |||
| Line 41: | Line 41: | ||
| == Example == | == Example == | ||
| <source lang=squirrel> | <source lang=squirrel> | ||
| /* Player::PlayerDeath is triggered whenever someone die */ | /* Player::PlayerDeath is triggered whenever someone die, we are going to use this for the sake of example */ | ||
| function Player::PlayerDeath( player )   | function Player::PlayerDeath( player )   | ||
| { | { | ||
|        /* Check whether the player that just died is local player/self */ |        /* Check whether the player that just died is local player/self by comparing ID */ | ||
|        if ( player.ID == World.FindLocalPlayer().ID ) |        if ( player.ID == World.FindLocalPlayer().ID ) | ||
|        { |        { | ||
| Line 52: | Line 52: | ||
|              local ftTime = format( "%i:%i:%i", now.hour, now.min, now.sec );   |              local ftTime = format( "%i:%i:%i", now.hour, now.min, now.sec );   | ||
|              /*  |              /* Send message about the time of death to local player/self */   | ||
|              Console.Print( player.Name +" died at "+ ftTime ); |              Console.Print( player.Name +" died at "+ ftTime ); | ||
|        } |        } | ||
Latest revision as of 14:27, 2 October 2018
This function returns a table containing a date/time splitted as in the table under Return type. It follows same syntax as the Squirrel standard library's date function: [1]
Syntax
System.GetDate([time], [format]])
time and format are optional.
Return type
table
| Name | Description | 
|---|---|
| sec | Seconds after minute (0 - 59) | 
| min | Minutes after hour (0 - 59) | 
| hour | Hours since midnight (0 - 23) | 
| day | Day of month (1 - 31) | 
| month | Month (0 - 11; January = 0) | 
| year | Year (current year) | 
| wday | Day of week (0 - 6; Sunday = 0) | 
| yday | Day of year (0 - 365; January 1 = 0) | 
Example
/* Player::PlayerDeath is triggered whenever someone die, we are going to use this for the sake of example */
function Player::PlayerDeath( player ) 
{
      /* Check whether the player that just died is local player/self by comparing ID */
      if ( player.ID == World.FindLocalPlayer().ID )
      {
            local now = System.GetDate(); 
            // hour:minute:sec
            local ftTime = format( "%i:%i:%i", now.hour, now.min, now.sec ); 
            /* Send message about the time of death to local player/self */ 
            Console.Print( player.Name +" died at "+ ftTime );
      }
}Notes
Player::PlayerDeath, World::FindLocalPlayer and Console::Print were used in this example, more info about them in the corresponding pages.