GetTime: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
Line 14: Line 14:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function currentTime()
function currentTime()
     local hour, minutes = getTime()
     local time = getTime()
     outputChatBox( "The current game time is "..hour..":"..minutes )
     outputChatBox( "The current game time is "..time )
end
end
addCommandHandler("gettime", currentTime)
addCommandHandler("gettime", currentTime)
Line 23: Line 23:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function currentTime(sourcePlayer)
function currentTime(sourcePlayer)
     local hour, minutes = getTime()
     local time = getTime()
     outputChatBox( "The current game time (server) is "..hour..":"..minutes, sourcePlayer )
     outputChatBox( "The current game time (server) is "..time, sourcePlayer )
end
end
addCommandHandler("gettime", currentTime)
addCommandHandler("gettime", currentTime)

Revision as of 23:49, 9 November 2016

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 time = getTime()
    outputChatBox( "The current game time is "..time )
end
addCommandHandler("gettime", currentTime)
Click to collapse [-]
Server
function currentTime(sourcePlayer)
    local time = getTime()
    outputChatBox( "The current game time (server) is "..time, sourcePlayer )
end
addCommandHandler("gettime", currentTime)

See Also