SetTime: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
 
(14 intermediate revisions by 7 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
==Description==
{{Server client function}}
This function sets the current time to the given time. It returns false if it fails.
This function sets the current GTA time to the given time.


==Syntax==
==Syntax==
<syntaxhighlight lang="lua">bool setTime ( int hour, int minute )</syntaxhighlight>
<syntaxhighlight lang="lua">
bool setTime ( int hour, int minute )
</syntaxhighlight>


===Required Arguments===
===Required Arguments===
*'''hour''': The hour of the new time (range 0-23)
*'''hour''': The hour of the new time (range 0-23).
*'''minute''': The minute of the new time (range 0-59)
*'''minute''': The minute of the new time (range 0-59).
 
==Returns==
Returns ''true'' if the new time was successfully set, ''false'' otherwise.


==Example==
==Example==
[[setTime]] ( 18, 0 )
<section name="Example 1" class="server" show="true">
[[serverChat]] ( "Time changed to 18:00!" )
This serverside function sets the time and notifies players.
<syntaxhighlight lang="lua">
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
</syntaxhighlight>
</section>
<section name="Example 2" class="client" show="true">
This example freeze the time.
<syntaxhighlight lang="lua">
addEventHandler( 'onClientRender', root,
    function( )
        setTime( 1, 0 )
    end
)
</syntaxhighlight>
</section>
 
==See Also==
{{World functions}}
 
[[ru:setTime]]

Latest revision as of 07:46, 4 November 2020

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

Click to collapse [-]
Example 1

This serverside function sets the time and notifies players.

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

This example freeze the time.

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

See Also