local config = {
exhausttime = 7200, -- time in seconds
exhauststorage = 2301
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
local rewarditems = {
{id = 2160, count = math.random(1, 2)},
{id = 2160, count = math.random(1, 5)},
{id = 2160, count = math.random(1, 10)},
{id = 2160, count = math.random(1, 15)}
}
if exhaustion.check(cid, config.exhauststorage) then
local time = exhaustion.get(cid, config.exhauststorage)
local hours, minutes, seconds = math.floor (time / 3600), math.floor ((time - ((math.floor (time / 3600)) * 3600))/ 60), time - ((math.floor (time/60)) * 60)
if time >= 3600 then
text = hours.." "..(hours > 1 and "hours" or "hour")..", "..minutes.." "..(minutes > 1 and "minutes" or "minute").." and "..seconds.." "..(seconds > 1 and "seconds" or "second")
elseif time >= 120 then
text = minutes.." "..(minutes > 1 and "minutes" or "minute").." and "..seconds.." "..(seconds > 1 and "seconds" or "second")
else
text = seconds.." "..(seconds > 1 and "seconds" or "second")
end
doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "It is empty. You need to wait "..text.." before you can get a reward again.")
return true
end
local i = math.random(1, #rewarditems)
local info = getItemInfo(rewarditems[i].id)
if rewarditems[i].count > 1 then
text = rewarditems[i].count .. " " .. info.plural
else
text = info.article .. " " .. info.name
end
local item = doCreateItemEx(rewarditems[i].id, rewarditems[i].count)
if doPlayerAddItemEx(cid, item, false) ~= RETURNVALUE_NOERROR then
doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
text = "You have found a reward. It is too heavy or you have not enough space."
else
text = "You have found " .. text .. "."
exhaustion.set(cid, config.exhauststorage, config.exhausttime)
end
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, text)
return true
end