local actionId = 7000
local storage = 7000
local fee = 10000
local item = 2152
local hours = 24
local function getTimeString(seconds)
if seconds < 60 then
return string.format("%d seconds", seconds)
elseif seconds < 3600 then
return string.format("%d minutes", math.floor(seconds / 60))
end
return string.format("%d hours", math.floor(seconds / 3600))
end
local action = Action()
function action.onUse(player, lever, fromPos, target, toPos, isHotkey)
local now = os.time()
local lastUse = player:getStorageValue(storage)
if lastUse > now then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format("You have to wait %s before using this lever again.", getTimeString(lastUse - now)))
return true
end
if player:getMoney() < fee then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You don't have enough money.")
return true
end
player:removeMoney(fee)
local item = player:addItem(item, 30)
player:setStorageValue(storage, now + hours * 3600)
player:sendTextMessage(MESSAGE_INFO_DESCR, string.format("You have received %s", item:getDescription()))
player:getPosition():sendMagicEffect(CONST_ME_FIREWORK_BLUE)
lever:transform(lever:getId() == 1945 and 1946 or 1945)
return true
end
action:aid(actionId)
action:register()