SetMinuteDuration: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
__NOTOC__
__NOTOC__
{{Server client function}}
{{Server client function}}
Sets the real-world duration of an ingame minute. The GTA default is 1000.
Sets the real-world duration of an ingame minute. The GTA default is 1000.
Line 16: Line 17:
==Example==
==Example==
This example will make the ingame time correspond to the real-world time of the server.
This example will make the ingame time correspond to the real-world time of the server.
{{Needs_Checking|In this example, triggerClientEvent, if executed immediately on resource start, gives an error, that "doSyncRealTime" event is not registered on client side, although it does work on player join. Hence the example won't work, unless resourceStart() execution is delayed using a timer}}


<section class="server" name="Server" show="true">
<section class="server" name="Server" show="true">

Revision as of 15:18, 27 June 2010


Sets the real-world duration of an ingame minute. The GTA default is 1000.

Syntax

bool setMinuteDuration ( int milliseconds )

Required Arguments

  • milliseconds: the new duration of an ingame minute

Returns

Returns true if successful, false otherwise.

Example

This example will make the ingame time correspond to the real-world time of the server.


Dialog-information.png This article needs checking.

Reason(s): In this example, triggerClientEvent, if executed immediately on resource start, gives an error, that "doSyncRealTime" event is not registered on client side, although it does work on player join. Hence the example won't work, unless resourceStart() execution is delayed using a timer
Click to collapse [-]
Server
function syncRealTime(player)
    -- get the current real time and send it to the player
    local realtime = getRealTime()
    triggerClientEvent(player, "doSyncRealTime", getRootElement(), realtime.hour, realtime.minute)
end

function resourceStart()
    -- when the resource starts, send the real time to all players currently in the server
    local players = getElementsByType("player")
    for i,player in ipairs(players) do
        syncRealTime(player)
    end
end
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), resourceStart)

function playerJoin()
    -- send the real time to joining players
    syncRealTime(source)
end
addEventHandler("onPlayerJoin", getRootElement(), playerJoin)
Click to collapse [-]
Client
function syncRealTime(h, m)
    -- set the ingame time
    setTime(h, m)
    -- make ingame time progress at the same rate as real time (60 seconds per minute)
    setMinuteDuration(60000)
end
-- attach the above function to the doSyncRealTime event
addEvent("doSyncRealTime", true)
addEventHandler("doSyncRealTime", getRootElement(), syncRealTime)

See Also

Shared