WikiArk21
Member
- Joined
- Oct 24, 2023
- Messages
- 23
- Reaction score
- 5
I was making a script for the posts and similar to change from on to off at a certain time on the server, but this causes a lag in the time. Is there any way to reduce this lag or even eliminate the lag altogether? Remembering that this is a globalevents
LUA:
local LIGHT_ON_TIME = 18
local LIGHT_OFF_TIME = 6
local LAMPS = {
[1479] = 1480,
[26782] = 26781,
[26783] = 26784,
}
function toggleLamps()
local currentHour = tonumber(os.date("%H"))
local shouldTurnOn = (currentHour >= LIGHT_ON_TIME or currentHour < LIGHT_OFF_TIME)
local worldLightState = Game.getStorageValue(65412)
-- Se o estado já está correto, não faz nada
if worldLightState == (shouldTurnOn and 1 or 0) then
return true
end
for x = 100, 1000 do
for y = 100, 1000 do
for z = 0, 15 do
local tile = Tile(Position(x, y, z))
if tile then
local item = nil
for lampOff, lampOn in pairs(LAMPS) do
item = tile:getItemById(lampOff) or tile:getItemById(lampOn)
if item then
item:transform(shouldTurnOn and lampOn or lampOff)
end
end
end
end
end
end
-- Atualiza o estado das luzes no servidor
Game.setStorageValue(65412, shouldTurnOn and 1 or 0)
return true
end
function onThink(interval)
toggleLamps()
return true
end