Advertisement
Guest User

Time Chests

a guest
Mar 14th, 2014
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.44 KB | None | 0 0
  1. -- Time Chests by Limos
  2. function onUse(cid, item, fromPosition, itemEx, toPosition)
  3.  
  4.     local chests = {
  5.         [8001] = {
  6.             waittime = 14400, -- time in seconds
  7.             storage = 2301,
  8.             rewarditems = {
  9.                 {id = 2152, count = math.random(1, 50)},
  10.                 {id = 2462, count = 1},
  11.                 {id = 2124, count = 1},
  12.                 {id = 2647, count = 1}
  13.             }
  14.         },
  15.         [8002] = {
  16.             waittime = 14400, -- time in seconds
  17.             storage = 2302,
  18.             rewarditems = {
  19.                 {id = 2160, count = math.random(1, 5)},
  20.                 {id = 2498, count = 1},
  21.                 {id = 2492, count = 1},
  22.                 {id = 2488, count = 1}
  23.             }
  24.         },
  25.         [8003] = {
  26.             waittime = 14400, -- time in seconds
  27.             storage = 2303,
  28.             rewarditems = {
  29.                 {id = 2160, count = math.random(20, 50)},
  30.                 {id = 7385, count = 1},
  31.                 {id = 2514, count = 1},
  32.                 {id = 2470, count = 1}
  33.             }
  34.         }          
  35.     }
  36.    
  37.     local x = chests[item.uid]
  38.     if exhaustion.check(cid, x.storage) then
  39.         local time = exhaustion.get(cid, x.storage)
  40.         local hours, minutes, seconds = math.floor (time / 3600), math.floor ((time - ((math.floor (time / 3600)) * 3600))/ 60), time - ((math.floor (time/60)) * 60)
  41.         if time >= 3600 then
  42.             text = hours.." "..(hours > 1 and "hours" or "hour")..", "..minutes.." "..(minutes > 1 and "minutes" or "minute").." and "..seconds.." "..(seconds > 1 and "seconds" or "second")
  43.         elseif time >= 120 then
  44.             text = minutes.." "..(minutes > 1 and "minutes" or "minute").." and "..seconds.." "..(seconds > 1 and "seconds" or "second")
  45.         else
  46.             text = seconds.." "..(seconds > 1 and "seconds" or "second")
  47.         end
  48.         doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
  49.         doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "It is empty. You need to wait "..text.." before you can get a reward again.")
  50.         return true
  51.     end
  52.     local chance = math.random(1, #x.rewarditems)
  53.     local info = getItemInfo(x.rewarditems[chance].id)
  54.     if x.rewarditems[chance].count > 1 then
  55.         text = x.rewarditems[chance].count .. " " .. info.plural
  56.     else
  57.         text = info.article .. " " .. info.name
  58.     end
  59.     local item = doCreateItemEx(x.rewarditems[chance].id, x.rewarditems[chance].count)
  60.     if(doPlayerAddItemEx(cid, item, false) ~= RETURNVALUE_NOERROR) then
  61.         doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
  62.         text = "You have found a reward. It is too heavy or you have not enough space."
  63.     else
  64.         text = "You have found " .. text .. "."
  65.         exhaustion.set(cid, x.storage, x.waittime)
  66.     end
  67.     doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, text)
  68.     return true
  69. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement