SetMinuteDuration: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
(Replace to predefined variables.)
 
(5 intermediate revisions by 5 users not shown)
Line 9: Line 9:


===Required Arguments===
===Required Arguments===
*'''milliseconds''': the new duration of an ingame minute
*'''milliseconds''': the new duration of an ingame minute, accepted values 0 - 2147483647.


===Returns===
===Returns===
Line 16: Line 16:
==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.
<section class="server" name="Server" show="true">
<section class="server" name="Server" show="true">
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function syncRealTime(player)
function resourceStart()
    -- get the current real time and send it to the player
     local realtime = getRealTime()
     local realtime = getRealTime()
    triggerClientEvent(player, "doSyncRealTime", getRootElement(), realtime.hour, realtime.minute)
end


function resourceStart()
     setTime(realtime.hour, realtime.minute)
    -- 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)
</syntaxhighlight>
</section>
 
<section class="client" name="Client" show="true">
<syntaxhighlight lang="lua">
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)
     setMinuteDuration(60000)
end
end
-- attach the above function to the doSyncRealTime event
addEventHandler("onResourceStart", resourceRoot, resourceStart)
addEvent("doSyncRealTime", true)
addEventHandler("doSyncRealTime", getRootElement(), syncRealTime)
</syntaxhighlight>
</syntaxhighlight>
</section>
</section>

Latest revision as of 23:14, 11 January 2023

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, accepted values 0 - 2147483647.

Returns

Returns true if successful, false otherwise.

Example

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

Click to collapse [-]
Server
function resourceStart()
    local realtime = getRealTime()

    setTime(realtime.hour, realtime.minute)
    setMinuteDuration(60000)
end
addEventHandler("onResourceStart", resourceRoot, resourceStart)

See Also