Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Time Chests by Limos (with chance)
- function onUse(cid, item, fromPosition, itemEx, toPosition)
- local chests = {
- [9001] = {
- waittime = 14400, -- time in seconds
- storage = 3301,
- level = 50,
- rewarditems = {
- {id = 2647, count = 1, chance = 5}, -- start with the lowest chances
- {id = 2462, count = 1, chance = 10},
- {id = 2124, count = 1, chance = 15},
- {id = 2152, count = math.random(1, 50), chance = 70}
- }
- },
- [9002] = {
- waittime = 14400,
- storage = 3302,
- level = 50,
- rewarditems = {
- {id = 2488, count = 1, chance = 5},
- {id = 2498, count = 1, chance = 10},
- {id = 2492, count = 1, chance = 15},
- {id = 2160, count = math.random(1, 5), chance = 70}
- }
- },
- [9003] = {
- waittime = 14400,
- storage = 3303,
- level = 50,
- rewarditems = {
- {id = 2470, count = 1, chance = 5},
- {id = 7385, count = 1, chance = 10},
- {id = 2514, count = 1, chance = 15},
- {id = 2160, count = math.random(20, 50), chance = 70}
- }
- }
- }
- local x = chests[item.uid]
- if getPlayerLevel(cid) < x.level then
- doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
- doPlayerSendCancel(cid, "You need to be level "..x.level.." to open the chest.")
- return true
- end
- if exhaustion.check(cid, x.storage) then
- local time = exhaustion.get(cid, x.storage)
- 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 chance = math.random(1,100)
- for i = 1, #x.rewarditems, 1 do
- if chance < x.rewarditems[i].chance then
- local info = getItemInfo(x.rewarditems[i].id)
- if x.rewarditems[i].count > 1 then
- text = x.rewarditems[i].count .. " " .. info.plural
- else
- text = info.article .. " " .. info.name
- end
- local item = doCreateItemEx(x.rewarditems[i].id, x.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 to heavy or you have not enough space."
- else
- text = "You have found " .. text .. "."
- exhaustion.set(cid, x.storage, x.waittime)
- end
- doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, text)
- return true
- else
- chance = chance - x.rewarditems[i].chance
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement