2021-04-09 19:01:18 +00:00

42 lines
1.0 KiB
Lua

-- Magic wall & Wild growth timer
-- config
local magicWallId = 2129
local magicWallTime = 20000
local wildGrowthId = 2130
local wildGrowthTime = 45000
-- script
local activeTimers = {}
onAddThing(function(tile, thing)
if not thing:isItem() then
return
end
local timer = 0
if thing:getId() == magicWallId then
timer = magicWallTime
elseif thing:getId() == wildGrowthId then
timer = wildGrowthTime
else
return
end
local pos = tile:getPosition().x .. "," .. tile:getPosition().y .. "," .. tile:getPosition().z
if not activeTimers[pos] or activeTimers[pos] < now then
activeTimers[pos] = now + timer
end
tile:setTimer(activeTimers[pos] - now)
end)
onRemoveThing(function(tile, thing)
if not thing:isItem() then
return
end
if (thing:getId() == magicWallId or thing:getId() == wildGrowthId) and tile:getGround() then
local pos = tile:getPosition().x .. "," .. tile:getPosition().y .. "," .. tile:getPosition().z
activeTimers[pos] = nil
tile:setTimer(0)
end
end)