local storage = 5964 -- change this value
local cooldown = 24 -- hours
local effect = CONST_ME_MAGIC_BLUE
local items = {
{ itemId = 5162, itemCount = 1, itemChance = 1 },
{ itemId = 5599, itemCount = 1, itemChance = 10 },
{ itemId = 5166, itemCount = 20, itemChance = 30 },
{ itemId = 5114, itemCount = 1, itemChance = 50 },
{ itemId = 5263, itemCount = 50, itemChance = 70 },
{ itemId = 2160, itemCount = 30, itemChance = true }, -- set itemChance = true for 100%
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
local storageValue = getCreatureStorage(cid, storage)
if storageValue - os.time() >= 1 then
doPlayerSendTextMessage(cid, MSG_STATUS_SMALL, "You have received this reward, must wait.")
return true
end
local tmp = {}
for i = 1, #items do
local chance = items[i].itemChance
if (chance == true or math.random(1, 100) <= chance) then
local id = items[i].itemId
local count = items[i].itemCount
if not getItemInfo(id).stackable then
for i = 1, count do
doPlayerAddItem(cid, id, 1)
end
else
doPlayerAddItem(cid, id, count)
end
table.insert(tmp, count .. " " .. getItemNameById(id))
break
end
end
if effect then
doSendMagicEffect(getThingPosition(cid), effect)
end
local text = #tmp == 0 and "You have no received nothing. :(" or string.format("You have received %s.", table.concat(tmp, ", "))
doPlayerSendTextMessage(cid, MESSAGE_STATUS_SMALL, text)
doCreatureSetStorage(cid, storage, os.time() + (60 * 60 * cooldown))
return true
end