• 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!

Randomly generated chest

Killzon32

There killing our dudes.
Joined
Aug 11, 2010
Messages
235
Reaction score
8
Location
mount olympus
Ok heres my idea

Action id a tile and make lots of them all over the map, a chest has a chance to spawn in one of the location's every x amount of time.
You need like a copper key or whatever key to open the chest.
The chest gives certain random item's and certain key's make it so you have chances to get better items.


Hope you understand, this I don't think has been done before and would be pretty cool for otland to have.
 
when you use key on chest it poof's and go's away allowing another chest to have a chance to be placed so you don't get every spot taken with them.
 
What I think you mean is that a chest creates in a chosen random position (I don't know how to find an actionid position on the map, so you have to make config it in the script) and when a player opens it, you have to wait until next chest creates? (every chest creates after 20 min forexample)
 
Oh well i was thinking of action id in map editor but If that does not work it could be manual positions
Yeah when you open it "use key on chest" It poof's or go's away and then it reset's and another chest has a chance to spawn every 20 min's <-- it's random so from 1 min to 20 min's
 
aha ok, then it's was like I thinked. Wait until I complete it (I hope i do xd)

- - - Updated - - -

Here you are. You cannot choose random time, because I don't know how to do it. Maybe someone else?

But here it is:

Actions:
XML:
	<action fromid="2086" toid="2092" event="script" value="randomchest.lua"/>

Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
	local keys = {2086, 2087, 2088, 2089, 2090, 2091, 2092}
	
	local chest = {
		chestid = 1740,
		chestactionid = 1001
	}
	local rewKey = {
		magical = {{id = 2472, count = 1}},
		wooden = {{id = 2472, count = 1}, {id = 2160, count = 3}},
		silver = {{{id = 2472, count = 1}}},
		cooper = {{{id = 2472, count = 1}}},
		crystal = {{{id = 2472, count = 1}}},
		golden = {{{id = 2472, count = 1}}},
		bone = {{{id = 2472, count = 1}}}
	}
	
	if(isInArray(keys, item.itemid)) then
		if(itemEx.itemid == chest.chestid) then
			if(itemEx.actionid == chest.chestactionid) then
				if(item.itemid == keys[1]) then
					local c = math.random(#rewKey.magical)
					doPlayerAddItem(cid, rewKey.magical[c].id, rewKey.magical[c].count)
				elseif(item.itemid == keys[2]) then
					local c = math.random(#rewKey.wooden)
					doPlayerAddItem(cid, rewKey.wooden[c].id, rewKey.wooden[c].count)
				elseif(item.itemid == keys[3]) then
					local c = math.random(#rewKey.silver)
					doPlayerAddItem(cid, rewKey.silver[c].id, rewKey.silver[c].count)
				elseif(item.itemid == keys[4]) then
					local c = math.random(#rewKey.cooper)
					doPlayerAddItem(cid, rewKey.cooper[c].id, rewKey.cooper[c].count)
				elseif(item.itemid == keys[5]) then
					local c = math.random(#rewKey.crystal)
					doPlayerAddItem(cid, rewKey.crystal[c].id, rewKey.crystal[c].count)
				elseif(item.itemid == keys[6]) then
					local c = math.random(#rewKey.golden)
					doPlayerAddItem(cid, rewKey.golden[c].id, rewKey.golden[c].count)
				elseif(item.itemid == keys[7]) then
					local c = math.random(#rewKey.bone)
					doPlayerAddItem(cid, rewKey.bone[c].id, rewKey.bone[c].count)
				end
			end
			
			doSendMagicEffect(toPosition, 2)
			doRemoveItem(itemEx.uid, 1)
		end
	else
		doPlayerSendCancel(cid, "You need a key to open this chest.")
		return false
	end
	return true
end

Globalevents:
XML:
	<globalevent name="RChest" interval="1200" event="script" value="randomchestg.lua"/>

Lua:
function onThink(interval, lastExecution, thinkInterval)
	local chest = {
		positions = {
			[1] = {x = 94, y = 125, z = 7},
			[2] = {x = 95, y = 125, z = 7}
		},
		chestid = 1740,
		chestactionid = 1001
	}

	local place = math.random(#chest.positions)
	
	for k, v in pairs(chest.positions) do
		if(getTileItemById(chest.positions[k], chest.chestid).uid ~= 0) then
			doRemoveItem(getTileItemById(chest.positions[k], chest.chestid).uid, 1)
		end
	end
	
	if(getTileItemById(chest.positions[place], chest.chestid).uid == 0) then
		local c = doCreateItem(cid, chest.chestid, 1, chest.positions[place])
		doItemSetAttribute(c, "aid", chest.chestactionid)
	else
		doRemoveItem(getTileItemById(chest.positions[place], chest.chestid).uid, 1)
		local c = doCreateItem(cid, chest.chestid, 1, chest.positions[place])
		doItemSetAttribute(c, "aid", chest.chestactionid)
	end

	return true
end
 
Last edited:
Bug's
any chest can be used by key, fixed by changing chest to the fancy one 1746 or w.e
Bug people can move the chest and or pick it up.

Changes I would like to see.
Key goes away after 1 use.
Ability to have multiple chests spawn, not on top of each other in random location's.
Like 100% chance for 1 70% chance for 2 50% chance for 3 30% chance for 4
Also would like it if it can put items into bag or backpack for person.
Ability to change gold chances like in monsters so like 1-10 gold not always 10gold
 
Last edited:
Back
Top