Action Time Chest (with random reward)

OP
Limos

Limos

Senator
Premium User
Joined
Jun 7, 2010
Messages
10,018
Solutions
8
Reaction score
3,017
Location
Netherlands
Depense on how you want it to work, but if you change %A to %B and have the months instead of the days in the table, which reward people get will depend on which month it is.
The rest is how often, so if you keep that it will still be daily. If you want players to only open it once in a month you can change %w to %m and change 24*60*60 to a month.
 
OP
Limos

Limos

Senator
Premium User
Joined
Jun 7, 2010
Messages
10,018
Solutions
8
Reaction score
3,017
Location
Netherlands
24*60*60 means 24 hours, you can also remove that extra storage part and only use %m since people probable won't wait a year before opening the chest again.
 
OP
Limos

Limos

Senator
Premium User
Joined
Jun 7, 2010
Messages
10,018
Solutions
8
Reaction score
3,017
Location
Netherlands
Yes, or well 744 then, for months with 31 days.
 

LordVissie

( ͡°( ͡° ͜ʖ( ͡° ͜ʖ ͡°) ͜ʖ ͡°) ͡°)
Joined
Aug 4, 2015
Messages
1,635
Solutions
2
Reaction score
629
Location
The Earth
I got an error:

Code:
[23/08/2015 12:44:44] [Error - Action Interface]
[23/08/2015 12:44:44] data/actions/scripts/quests/timechest.lua:onUse
[23/08/2015 12:44:44] Description:
[23/08/2015 12:44:44] data/actions/scripts/quests/timechest.lua:68: attempt to get length of field '?' (a nil value)
[23/08/2015 12:44:44] stack traceback:
[23/08/2015 12:44:44]     data/actions/scripts/quests/timechest.lua:68: in function <data/actions/scripts/quests/timechest.lua:7>

added this in actions.xml: <action uniqueid="4005" event="script" value="quests/timechest.lua"/>
Putted the lua file in "quests" folder.

the lua:

Code:
local config = {
exhausttime = 7200, -- time in seconds
exhauststorage = 2301,
level = 100 -- minimum level to open the chest
}

function onUse(cid, item, fromPosition, itemEx, toPosition)

local rewarditems = {
[25] = {
tilllevel = 50,
{id = 3982, chance = 5, count = 1}, -- start with the lowest chances
{id = 2476, chance = 10, count = 1},
{id = 2479, chance = 15, count = 1},
{id = 2148, chance = 70, count = math.random(10, 50)}
},
[50] = {
tilllevel = 100,
{id = 7730, chance = 5, count = 1},
{id = 2466, chance = 10, count = 1},
{id = 2497, chance = 15, count = 1},
{id = 2152, chance = 70, count = math.random(1, 20)}
},
[100] = {
tilllevel = 200,
{id = 2472, chance = 5, count = 1},
{id = 2496, chance = 10, count = 1},
{id = 2520, chance = 15, count = 1},
{id = 2160, chance = 70, count = math.random(20, 50)}
},
[200] = {
tilllevel = 10000,
{id = 2472, chance = 5, count = 1},
{id = 2470, chance = 10, count = 1},
{id = 2157, chance = 15, count = 1},
{id = 2160, chance = 70, count = math.random(1, 5)}
}
}

if(getPlayerLevel(cid) < config.level) then
doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
doPlayerSendCancel(cid, "You need to be level "..config.level.." to open the chest.")
return true
end

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 "hour" or "hours")..", "..minutes.." "..(minutes == 1 and "minute" or "minutes").." and "..seconds.." "..(seconds == 1 and "second" or "seconds")
elseif time >= 120 then
text = minutes.." "..(minutes == 1 and "minute" or "minutes").." and "..seconds.." "..(seconds == 1 and "second" or "seconds")
else
text = seconds.." "..(seconds == 1 and "second" or "seconds")
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 v, x in pairs(rewarditems) do
if(getPlayerLevel(cid) >= v and getPlayerLevel(cid) < x.tilllevel) then
level = v
end
end

for i = 1, #rewarditems[level], 1 do
if(chance < rewarditems[level].chance) then
local info = getItemInfo(rewarditems[level].id)
if(rewarditems[level].count > 1) then
text = rewarditems[level].count .. " " .. info.plural
else
text = info.article .. " " .. info.name
end

local item = doCreateItemEx(rewarditems[level].id, rewarditems[level].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, config.exhauststorage, config.exhausttime)
end
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, text)
return true
else
chance = chance - rewarditems[level].chance
end
end
end

I only changed the minium level and the ID's (of level 100 reward).

I'm using cryingdamson 0.3.6 (8.60) V8.2. I don't know whats wrong.

Kr,
LordVissie
 
Last edited:

Caduceus

Unknown Member
Joined
May 10, 2010
Messages
321
Solutions
2
Reaction score
24
Updated to [1.2]

With level & chance:

Code:
-- Time Chest by Limos
local config = {
     exhausttime = 24*60*60, -- time
     exhauststorage = 2302,
     level = 25 -- minimum level to open the chest
}

local rewarditems = {
         [25] = {
             nextlevel = 50,
             {id = 3982, chance = 5, count = 1}, -- start with the lowest chances
             {id = 2476, chance = 10, count = 1},
             {id = 2479, chance = 15, count = 1},
             {id = 2148, chance = 70, count = math.random(1, 50)}
         },
         [50] = {
             nextlevel = 100,
             {id = 7730, chance = 5, count = 1},
             {id = 2466, chance = 10, count = 1},
             {id = 2497, chance = 15, count = 1},
             {id = 2152, chance = 70, count = math.random(1, 20)}
         },
         [100] = {
             nextlevel = 200,
             {id = 2492, chance = 5, count = 1},
             {id = 2498, chance = 10, count = 1},
             {id = 2195, chance = 15, count = 1},
             {id = 2152, chance = 70, count = math.random(20, 50)}
         },
         [200] = {
             nextlevel = 400,
             {id = 2472, chance = 5, count = 1},
             {id = 2470, chance = 10, count = 1},
             {id = 2157, chance = 15, count = 1},
             {id = 2160, chance = 70, count = math.random(1, 5)}
         }
     }
     function onUse(player, item, fromPosition, target, toPosition, isHotkey)
     if player:getLevel() < config.level then
         doSendMagicEffect(pos, CONST_ME_POFF)
         player:sendTextMessage(MESSAGE_STATUS_SMALL, "You need to be level "..config.level.." to open the box.")
         return true
     end

     if player:getStorageValue(config.exhauststorage) > os.time() then
         local time = player:getStorageValue(config.exhauststorage) - os.time()
         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 "hour" or "hours")..", "..minutes.." "..(minutes == 1 and "minute" or "minutes").." and "..seconds.." "..(seconds == 1 and "second" or "seconds")
         elseif time >= 60 then
             text = minutes.." "..(minutes == 1 and "minute" or "minutes").." and "..seconds.." "..(seconds == 1 and "second" or "seconds")
         else
             text = seconds.." "..(seconds == 1 and "second" or "seconds")
         end
         doSendMagicEffect(pos, CONST_ME_POFF)
         player:sendTextMessage(MESSAGE_INFO_DESCR, "You need to wait "..text.." before you can get a reward again.")
         return true
     end

     local chance = math.random(1,100)
     for v, x in pairs(rewarditems) do
         if player:getLevel() >= v and player:getLevel() < x.nextlevel then
             level = v
         end
     end

     for i = 1, #rewarditems[level], 1 do
         if chance < rewarditems[level][i].chance then
             local info = getItemInfo(rewarditems[level][i].id)
             if rewarditems[level][i].count > 1 then
                 text = rewarditems[level][i].count .. " " .. info.plural
             else
                 text = info.article .. " " .. info.name
             end

             local reward = player:addItem(rewarditems[level][i].id, rewarditems[level][i].count)
                 text = "You have found " .. text .. "."
                 player:addItem(reward)
                 player:setStorageValue(config.exhauststorage, os.time() + 24*60*60)
                player:sendTextMessage(MESSAGE_INFO_DESCR, text)
                Item(item.uid):remove(1)
             return true
         else
             chance = chance - rewarditems[level][i].chance
         end
     end
end
 

froie

Expert Mapper
Joined
May 27, 2013
Messages
196
Reaction score
5
Location
Canada
Is there a way to make this work but instead of a time, you have to use a key on it that makes the key a one time use? so whenever you get a special key you can goto the chest and use it to get a reward but the key breaks?
 

Xadic

「SADISTIC」 「SATIRICAL」
Joined
Jun 8, 2014
Messages
55
Reaction score
116
Location
・ 「ZONE-83」
Fixed/Updated @Limos one
Tested at TFS 1.3 / OTX 3.7

Code:
-- Time Chest by Limos 
local config = {
     exhausttime = 24*60*60, -- time
     exhauststorage = 2300,
     level = 100 -- minimum level to open the chest
}

local rewarditems = {
         [100] = {
             nextlevel = 200,
             {id = 3982, chance = 5, count = 1}, -- start with the lowest chances
             {id = 2476, chance = 10, count = 1},
             {id = 2479, chance = 15, count = 1},
             {id = 2148, chance = 70, count = math.random(1, 50)}
         },
         [200] = {
             nextlevel = 300,
             {id = 7730, chance = 5, count = 1},
             {id = 2466, chance = 10, count = 1},
             {id = 2497, chance = 15, count = 1},
             {id = 2152, chance = 70, count = math.random(1, 20)}
         },
         [300] = {
             nextlevel = 400,
             {id = 2492, chance = 5, count = 1},
             {id = 2498, chance = 10, count = 1},
             {id = 2195, chance = 15, count = 1},
             {id = 2152, chance = 70, count = math.random(20, 50)}
         },
         [400] = {
             nextlevel = 500,
             {id = 2472, chance = 5, count = 1},
             {id = 2470, chance = 10, count = 1},
             {id = 2157, chance = 15, count = 1},
             {id = 2160, chance = 70, count = math.random(1, 5)}
         }
     }
     function onUse(player, item, fromPosition, target, toPosition, isHotkey)
     if player:getLevel() < config.level then
         doSendMagicEffect(pos, CONST_ME_POFF)
         player:sendTextMessage(MESSAGE_STATUS_SMALL, "You need to be level "..config.level.." to open the box.")
         return true
     end

     if player:getStorageValue(config.exhauststorage) > os.time() then
         local time = player:getStorageValue(config.exhauststorage) - os.time()
         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 "hour" or "hours")..", "..minutes.." "..(minutes == 1 and "minute" or "minutes").." and "..seconds.." "..(seconds == 1 and "second" or "seconds")
         elseif time >= 60 then
             text = minutes.." "..(minutes == 1 and "minute" or "minutes").." and "..seconds.." "..(seconds == 1 and "second" or "seconds")
         else
             text = seconds.." "..(seconds == 1 and "second" or "seconds")
         end
         doSendMagicEffect(pos, CONST_ME_POFF)
         player:sendTextMessage(MESSAGE_INFO_DESCR, "You need to wait "..text.." before you can get a reward again.")
         return true
     end

     local chance = math.random(1,100)
     for v, x in pairs(rewarditems) do
         if player:getLevel() >= v and player:getLevel() < x.nextlevel then
             level = v
         end
     end

     for i = 1, #rewarditems[level], 1 do
         if chance < rewarditems[level][i].chance then
             local itemType = ItemType(rewarditems[level][i].id)
             if rewarditems[level][i].count > 1 then
                 text = rewarditems[level][i].count .. " " .. itemType:getPluralName()
             else
                 text = itemType:getArticle() .. " " .. itemType:getName()
             end

             local reward = player:addItem(rewarditems[level][i].id, rewarditems[level][i].count)
                 text = "You have found " .. text .. "."
                 player:addItem(reward)
                 player:setStorageValue(config.exhauststorage, os.time() + 24*60*60)
                player:sendTextMessage(MESSAGE_INFO_DESCR, text)
             return true
         else
             chance = chance - rewarditems[level][i].chance
         end
     end
end
 

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,403
Solutions
361
Reaction score
3,513
Fixed/Updated @Limos one
Tested at TFS 1.3 / OTX 3.7

Code:
-- Time Chest by Limos
local config = {
     exhausttime = 24*60*60, -- time
     exhauststorage = 2300,
     level = 100 -- minimum level to open the chest
}

local rewarditems = {
         [100] = {
             nextlevel = 200,
             {id = 3982, chance = 5, count = 1}, -- start with the lowest chances
             {id = 2476, chance = 10, count = 1},
             {id = 2479, chance = 15, count = 1},
             {id = 2148, chance = 70, count = math.random(1, 50)}
         },
         [200] = {
             nextlevel = 300,
             {id = 7730, chance = 5, count = 1},
             {id = 2466, chance = 10, count = 1},
             {id = 2497, chance = 15, count = 1},
             {id = 2152, chance = 70, count = math.random(1, 20)}
         },
         [300] = {
             nextlevel = 400,
             {id = 2492, chance = 5, count = 1},
             {id = 2498, chance = 10, count = 1},
             {id = 2195, chance = 15, count = 1},
             {id = 2152, chance = 70, count = math.random(20, 50)}
         },
         [400] = {
             nextlevel = 500,
             {id = 2472, chance = 5, count = 1},
             {id = 2470, chance = 10, count = 1},
             {id = 2157, chance = 15, count = 1},
             {id = 2160, chance = 70, count = math.random(1, 5)}
         }
     }
     function onUse(player, item, fromPosition, target, toPosition, isHotkey)
     if player:getLevel() < config.level then
         doSendMagicEffect(pos, CONST_ME_POFF)
         player:sendTextMessage(MESSAGE_STATUS_SMALL, "You need to be level "..config.level.." to open the box.")
         return true
     end

     if player:getStorageValue(config.exhauststorage) > os.time() then
         local time = player:getStorageValue(config.exhauststorage) - os.time()
         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 "hour" or "hours")..", "..minutes.." "..(minutes == 1 and "minute" or "minutes").." and "..seconds.." "..(seconds == 1 and "second" or "seconds")
         elseif time >= 60 then
             text = minutes.." "..(minutes == 1 and "minute" or "minutes").." and "..seconds.." "..(seconds == 1 and "second" or "seconds")
         else
             text = seconds.." "..(seconds == 1 and "second" or "seconds")
         end
         doSendMagicEffect(pos, CONST_ME_POFF)
         player:sendTextMessage(MESSAGE_INFO_DESCR, "You need to wait "..text.." before you can get a reward again.")
         return true
     end

     local chance = math.random(1,100)
     for v, x in pairs(rewarditems) do
         if player:getLevel() >= v and player:getLevel() < x.nextlevel then
             level = v
         end
     end

     for i = 1, #rewarditems[level], 1 do
         if chance < rewarditems[level][i].chance then
             local itemType = ItemType(rewarditems[level][i].id)
             if rewarditems[level][i].count > 1 then
                 text = rewarditems[level][i].count .. " " .. itemType:getPluralName()
             else
                 text = itemType:getArticle() .. " " .. itemType:getName()
             end

             local reward = player:addItem(rewarditems[level][i].id, rewarditems[level][i].count)
                 text = "You have found " .. text .. "."
                 player:addItem(reward)
                 player:setStorageValue(config.exhauststorage, os.time() + 24*60*60)
                player:sendTextMessage(MESSAGE_INFO_DESCR, text)
             return true
         else
             chance = chance - rewarditems[level][i].chance
         end
     end
end
god dammit.
Your picture with the scroll bar..
Sigh. :p
 

ralke

(҂ ͠❛ ෴ ͡❛)ᕤ
Joined
Dec 17, 2011
Messages
780
Solutions
18
Reaction score
319
Location
Santiago - Chile
Fixed/Updated @Limos one
Tested at TFS 1.3 / OTX 3.7

Code:
-- Time Chest by Limos
local config = {
     exhausttime = 24*60*60, -- time
     exhauststorage = 2300,
     level = 100 -- minimum level to open the chest
}

local rewarditems = {
         [100] = {
             nextlevel = 200,
             {id = 3982, chance = 5, count = 1}, -- start with the lowest chances
             {id = 2476, chance = 10, count = 1},
             {id = 2479, chance = 15, count = 1},
             {id = 2148, chance = 70, count = math.random(1, 50)}
         },
         [200] = {
             nextlevel = 300,
             {id = 7730, chance = 5, count = 1},
             {id = 2466, chance = 10, count = 1},
             {id = 2497, chance = 15, count = 1},
             {id = 2152, chance = 70, count = math.random(1, 20)}
         },
         [300] = {
             nextlevel = 400,
             {id = 2492, chance = 5, count = 1},
             {id = 2498, chance = 10, count = 1},
             {id = 2195, chance = 15, count = 1},
             {id = 2152, chance = 70, count = math.random(20, 50)}
         },
         [400] = {
             nextlevel = 500,
             {id = 2472, chance = 5, count = 1},
             {id = 2470, chance = 10, count = 1},
             {id = 2157, chance = 15, count = 1},
             {id = 2160, chance = 70, count = math.random(1, 5)}
         }
     }
     function onUse(player, item, fromPosition, target, toPosition, isHotkey)
     if player:getLevel() < config.level then
         doSendMagicEffect(pos, CONST_ME_POFF)
         player:sendTextMessage(MESSAGE_STATUS_SMALL, "You need to be level "..config.level.." to open the box.")
         return true
     end

     if player:getStorageValue(config.exhauststorage) > os.time() then
         local time = player:getStorageValue(config.exhauststorage) - os.time()
         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 "hour" or "hours")..", "..minutes.." "..(minutes == 1 and "minute" or "minutes").." and "..seconds.." "..(seconds == 1 and "second" or "seconds")
         elseif time >= 60 then
             text = minutes.." "..(minutes == 1 and "minute" or "minutes").." and "..seconds.." "..(seconds == 1 and "second" or "seconds")
         else
             text = seconds.." "..(seconds == 1 and "second" or "seconds")
         end
         doSendMagicEffect(pos, CONST_ME_POFF)
         player:sendTextMessage(MESSAGE_INFO_DESCR, "You need to wait "..text.." before you can get a reward again.")
         return true
     end

     local chance = math.random(1,100)
     for v, x in pairs(rewarditems) do
         if player:getLevel() >= v and player:getLevel() < x.nextlevel then
             level = v
         end
     end

     for i = 1, #rewarditems[level], 1 do
         if chance < rewarditems[level][i].chance then
             local itemType = ItemType(rewarditems[level][i].id)
             if rewarditems[level][i].count > 1 then
                 text = rewarditems[level][i].count .. " " .. itemType:getPluralName()
             else
                 text = itemType:getArticle() .. " " .. itemType:getName()
             end

             local reward = player:addItem(rewarditems[level][i].id, rewarditems[level][i].count)
                 text = "You have found " .. text .. "."
                 player:addItem(reward)
                 player:setStorageValue(config.exhauststorage, os.time() + 24*60*60)
                player:sendTextMessage(MESSAGE_INFO_DESCR, text)
             return true
         else
             chance = chance - rewarditems[level][i].chance
         end
     end
end

Sorry for reviving this, I have this error if someone could help me with this system ^^

timechest.png
 

TekLakus

New Member
Joined
Oct 27, 2020
Messages
3
Reaction score
0
I'm in that moment where my chest just opens and do nothing, in console not even a 1 error appears. I don't know if it's better or worse xD.
 

Kabo Flow

New Member
Joined
May 17, 2020
Messages
50
Reaction score
4
Location
Mexico
Twitch
KaboFlow18
It won't let me edit it, but here it is.
Code:
-- Time Chest by Limos
local config = {
     exhausttime = 7200, -- time in seconds
     exhauststorage = 2301
}

function onUse(cid, item, fromPosition, itemEx, toPosition)

     local rewarditems = {
         {id = 2152, count = math.random(1, 50)},
         {id = 2498, count = 1},
         {id = 2492, count = 1},
         {id = 2488, count = 1}
     }

     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

With chance
Code:
-- Time Chest by Limos
local config = {
   exhausttime = 7200, -- time in seconds
   exhauststorage = 2301,
   level = 50 -- minimum level to open the chest
}

function onUse(cid, item, fromPosition, itemEx, toPosition)

     local rewarditems = {
         {id = 2492, chance = 5, count = 1}, -- start with the lowest chances
         {id = 2498, chance = 10, count = 1},
         {id = 2488, chance = 15, count = 1},
         {id = 2152, chance = 70, count = math.random(1, 50)}
     }

     if getPlayerLevel(cid) < config.level then
         doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
         doPlayerSendCancel(cid, "You need to be level "..config.level.." to open the chest.")
         return true
     end

     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 chance = math.random(1,100)
     for i = 1, #rewarditems, 1 do
         if chance < rewarditems[i].chance then
             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 to 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
         else
             chance = chance - rewarditems[i].chance
         end
     end
end

Level and chance
Code:
-- Time Chest by Limos
local config = {
     exhausttime = 7200, -- time in seconds
     exhauststorage = 2302,
     level = 25 -- minimum level to open the chest
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
     local rewarditems = {
         [25] = {
             nextlevel = 50,
             {id = 3982, chance = 5, count = 1}, -- start with the lowest chances
             {id = 2476, chance = 10, count = 1},
             {id = 2479, chance = 15, count = 1},
             {id = 2148, chance = 70, count = math.random(1, 50)}
         },
         [50] = {
             nextlevel = 100,
             {id = 7730, chance = 5, count = 1},
             {id = 2466, chance = 10, count = 1},
             {id = 2497, chance = 15, count = 1},
             {id = 2152, chance = 70, count = math.random(1, 20)}
         },
         [100] = {
             nextlevel = 200,
             {id = 2492, chance = 5, count = 1},
             {id = 2498, chance = 10, count = 1},
             {id = 2195, chance = 15, count = 1},
             {id = 2152, chance = 70, count = math.random(20, 50)}
         },
         [200] = {
             nextlevel = 10000,
             {id = 2472, chance = 5, count = 1},
             {id = 2470, chance = 10, count = 1},
             {id = 2157, chance = 15, count = 1},
             {id = 2160, chance = 70, count = math.random(1, 5)}
         }
     }
     if getPlayerLevel(cid) < config.level then
         doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
         doPlayerSendCancel(cid, "You need to be level "..config.level.." to open the chest.")
         return true
     end

     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 "hour" or "hours")..", "..minutes.." "..(minutes == 1 and "minute" or "minutes").." and "..seconds.." "..(seconds == 1 and "second" or "seconds")
         elseif time >= 120 then
             text = minutes.." "..(minutes == 1 and "minute" or "minutes").." and "..seconds.." "..(seconds == 1 and "second" or "seconds")
         else
             text = seconds.." "..(seconds == 1 and "second" or "seconds")
         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 v, x in pairs(rewarditems) do
         if getPlayerLevel(cid) >= v and getPlayerLevel(cid) < x.nextlevel then
             level = v
         end
     end

     for i = 1, #rewarditems[level], 1 do
         if chance < rewarditems[level][i].chance then
             local info = getItemInfo(rewarditems[level][i].id)
             if rewarditems[level][i].count > 1 then
                 text = rewarditems[level][i].count .. " " .. info.plural
             else
                 text = info.article .. " " .. info.name
             end

             local item = doCreateItemEx(rewarditems[level][i].id, rewarditems[level][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, config.exhauststorage, config.exhausttime)
             end
             doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, text)
             return true
         else
             chance = chance - rewarditems[level][i].chance
         end
     end
end


How do I do so that it can be taken as long as you have finished another quest? I mean, put storage from another quest
 
Top