SetTime: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
Line 17: Line 17:
==Example==
==Example==
This serverside function sets the time and notifies players.
This serverside function sets the time and notifies players.
<section name="Server" class="server" show="true">
<section name="Example 1" class="server" show="true">
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function setTimeAndNotify( hour, minute )
function setTimeAndNotify( hour, minute )
Line 27: Line 27:
outputChatBox ( notifyMessage )
outputChatBox ( notifyMessage )
end
end
</syntaxhighlight>
</section>
<section name="Example 2" class="client" show="true">
The example freeze the time.
<syntaxhighlight lang="lua">
addEventHandler( 'onClientRender', getRootElement( ),
    function( )
        setTime( 1, 0 )
    end
)
</syntaxhighlight>
</syntaxhighlight>
</section>
</section>

Revision as of 13:08, 23 December 2012

This function sets the current GTA time to the given time.

Syntax

bool setTime ( int hour, int minute )

Required Arguments

  • hour: The hour of the new time (range 0-23).
  • minute: The minute of the new time (range 0-59).

Returns

Returns true if the new time was successfully set, false otherwise.

Example

This serverside function sets the time and notifies players.

Click to collapse [-]
Example 1
function setTimeAndNotify( hour, minute )
	-- set the time first
	setTime ( hour, minute )
	-- format a notification message, adding leading zeros (e.g. 12:03 instead of 12:3)
	local notifyMessage = string.format("Time changed to %02d:%02d!", hour, minute)
	-- output the message
	outputChatBox ( notifyMessage )
end
Click to collapse [-]
Example 2

The example freeze the time.

addEventHandler( 'onClientRender', getRootElement( ),
    function( )
        setTime( 1, 0 )
    end
)

See Also