• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Action Time Chest (with random reward)

Limos

Senator
Premium User
Joined
Jun 7, 2010
Messages
10,013
Solutions
8
Reaction score
3,055
Location
Netherlands
Tested with TFS 0.3.6pl1 8.54
From a request I made for Thylonn

dxrEu5.png


actions.xml
XML:
<action uniqueid="4005" event="script" value="quests/timechest.lua"/>

timechest.lua
Lua:
-- 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 = 2152, count = math.random(1, 50)},
	{id = 2498, count = 1},
	{id = 2492, count = 1},
	{id = 2488, count = 1}
}

	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 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 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
end

Version with chance

timechest.lua
Lua:
-- 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

Version with level and chance


timechest.lua
Lua:
-- Time Chest by Limos
local config = {
	exhausttime = 7200, -- time in seconds
	exhauststorage = 2301,
	level = 25 -- 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(1, 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 = 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] = {
		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][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 does it work:
Every amount of time (exhausttime) people can get a reward from the chest.
JJvx9t.png

This reward is a random item. You can change or add more items in the rewarditems.
 
Last edited:
Good release! A timed chest has been requested multiple times. Thanks for sharing. ^_^
 
Thanks for the comments and likes :)

Great idea to use that chest to obtain an amount of gold coins for new players. So they can get some cash when they just died. Thanks Limos!
Personaly I was more thinking about quests or hunting places, but in a city is also an idea, it should have a minimum level then so people don't make new characters to get rewards and different chances, so people don't get alot good items so easy.

Added second version with chance, also added minimum level.
 
Last edited:
Can you make a version with possibility to recieve experience or skills as reward?
 
This might be very handy to encourage new players. Thanks for sharing. :)
 
This is a very nice concept as it's not bound to being a chest, could be anything, from a bookshelf to a weapon rack.

@Limos could you update the tags? :)
 
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
 
Last edited:
I changed this would this work?
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
        local config = {
                storage = 45392,
                exstorage = 40822,
                months = {
                        ["January"] = {
                                {itemid = 2536, count = 1},
                                {itemid = 8871, count = 1},
                                {itemid = 5952, count = 1},
                                {itemid = 6579, count = 1},
                        },
                        ["February"] = {
                                {itemid = 11296, count = 1},
                                {itemid = 5952, count = 1},
                                {itemid = 6579, count = 1},
                                {itemid = 8109, count = 1},
                        },
                        ["March"] = {
                                {itemid = 8877, count = 1},
                                {itemid = 5952, count = 1},
                                {itemid = 6579, count = 1},
                                {itemid = 7368, count = 10},
                        },
                        ["April"] = {
                                {itemid = 11298, count = 1},
                                {itemid = 5952, count = 1},
                                {itemid = 6579, count = 1},
                                {itemid = 7750, count = 1},
                        },
                        ["May"] = {
                                {itemid = 2195, count = 1},
                                {itemid = 5952, count = 1},
                                {itemid = 6579, count = 1},
                                {itemid = 2466, count = 1},
                        },
                        ["June"] = {
                                {itemid = 8922, count = 1},
                                {itemid = 5952, count = 1},
                                {itemid = 6579, count = 1},
                                {itemid = 2160, count = 100},
                        },
                        ["July"] = {
                                {itemid = 8910, count = 1},
                                {itemid = 5952, count = 1},
                                {itemid = 6579, count = 1},
                                {itemid = 2534, count = 1},      
                        },
                        ["August"] = {
                                {itemid = 8910, count = 1},
                                {itemid = 5952, count = 1},
                                {itemid = 6579, count = 1},
                                {itemid = 2534, count = 1},
                        },
                        ["September"] = {
                                {itemid = 8910, count = 1},
                                {itemid = 5952, count = 1},
                                {itemid = 6579, count = 1},
                                {itemid = 2534, count = 1},
                        },
                        ["October"] = {
                                {itemid = 8910, count = 1},
                                {itemid = 5952, count = 1},
                                {itemid = 6579, count = 1},
                                {itemid = 2534, count = 1},
                        },
                        ["November"] = {
                                {itemid = 8910, count = 1},
                                {itemid = 5952, count = 1},
                                {itemid = 6579, count = 1},
                                {itemid = 2534, count = 1},      
                        },
                        ["December"] = {
                                {itemid = 8910, count = 1},
                                {itemid = 5952, count = 1},
                                {itemid = 6579, count = 1},
                                {itemid = 2534, count = 1},      
                        }
                }
        }
Code:
exhaustion.set(cid, config.exstorage, 24*60*60)
this one?
if not ill just change the exhaust time
 
So all i have to change is the %A to %B and thats it do i just leave the Exhuast?
 
Back
Top