GetTime: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
mNo edit summary
 
(11 intermediate revisions by 9 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
==Description==
{{Server client function}}
Returns the current time as two integers (hour and minute).
This function is used to get the current time in the game. If you want to get the real server time, use [[getRealTime]].


==Syntax==
==Syntax==
<syntaxhighlight lang="lua">getTime ()</syntaxhighlight>
<syntaxhighlight lang="lua">int, int getTime ()</syntaxhighlight>
 
===Returns===
Returns two ''ints'' that represent hours and minutes.


==Example==
==Example==
<syntaxhighlight lang="lua">hour, min = getTime ()
These two examples adds the command ''gettime'' which outputs the local game time and the server game time.
outputChatBox ( "The current time is ", hour, ":", min )</syntaxhighlight>
<section name="Client" class="client" show="true">
<syntaxhighlight lang="lua">
function currentTime()
    local timehour, timeminute = getTime()
    outputChatBox( "The current game time is "..timehour..":"..timeminute )
end
addCommandHandler("gettime", currentTime)
</syntaxhighlight>
</section>
<section name="Server" class="server" show="true">
<syntaxhighlight lang="lua">
function currentTime(sourcePlayer)
    local timehour, timeminute = getTime()
    outputChatBox( "The current game time (server) is "..timehour..":"..timeminute, sourcePlayer )
end
addCommandHandler("gettime", currentTime)
</syntaxhighlight>
</section>


==See Also==
==See Also==
{{World functions}}
{{World functions}}
[[ru:getTime]]

Latest revision as of 18:46, 18 November 2021

This function is used to get the current time in the game. If you want to get the real server time, use getRealTime.

Syntax

int, int getTime ()

Returns

Returns two ints that represent hours and minutes.

Example

These two examples adds the command gettime which outputs the local game time and the server game time.

Click to collapse [-]
Client
function currentTime()
    local timehour, timeminute = getTime()
    outputChatBox( "The current game time is "..timehour..":"..timeminute )
end
addCommandHandler("gettime", currentTime)
Click to collapse [-]
Server
function currentTime(sourcePlayer)
    local timehour, timeminute = getTime()
    outputChatBox( "The current game time (server) is "..timehour..":"..timeminute, sourcePlayer )
end
addCommandHandler("gettime", currentTime)

See Also