RU/setMinuteDuration

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Устанавливает продолжительность минуты в игре. В GTA изначально равна 1000.

Использование

bool setMinuteDuration ( int milliseconds )

Необходимые параметры

  • milliseconds: новая продолжительность игровой минуты.

Что возвращается

Возвращается true, если изменение успешно произошло, или false, если изменение не произошло.

Пример

В этом примере мы изменяем продолжительность времени на реальную и синхронизируем с реальным временем.

Click to collapse [-]
Сервер
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)

Смотри также