PuszekLDZ
https://tibia74.eu
Hello all!
I trying to make a script, that You can use Item as a daily reward..
I merged some, and script works in 80% because I can use item, it gives me gold, changing storage - i got msg about that time left, but even then i can get new reward etc...
Can someone see that? I should work like that.
Player use item, gets coins and time is start counting to use it again.
My code is
I trying to make a script, that You can use Item as a daily reward..
I merged some, and script works in 80% because I can use item, it gives me gold, changing storage - i got msg about that time left, but even then i can get new reward etc...
Can someone see that? I should work like that.
Player use item, gets coins and time is start counting to use it again.
My code is
LUA:
local cooldown_storage = 88349
local presents = {
[3218] = { -- item id of the item that will give u random items
{3031, 10}, {3031, 20}, {3031, 50}, {3031, 100}--Setup the rewards here
}
}
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
local count = 1
local targetItem = presents[item.itemid]
if not targetItem then
return true
end
local gift = targetItem[math.random(#targetItem)]
if type(gift) == "table" then
count = gift[2]
gift = gift[1]
end
local time_left = player:getStorageValue(cooldown_storage)
if time_left > os.time() then
time_left = time_left - os.time() -- get the difference in time so it shows properly in error message
local hours = string.format("%02.f", math.floor(time_left / 3600))
local mins = string.format("%02.f", math.floor(time_left / 60 - (hours * 60)))
local secs = string.format("%02.f", math.floor(time_left - hours * 3600 - mins * 60))
local time_string = hours ..":".. mins ..":".. secs
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You cannot enter this teleport yet. Time left: ".. time_string .. ".")
player:addItem(gift, count)
return false
end
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You got ".. (count ~= nil and count .. ' ' or '') .. ItemType(gift):getName())
fromPosition:sendMagicEffect(CONST_ME_GIFT_WRAPS)
player:setStorageValue(cooldown_storage, os.time() + 30)
return true
end