• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

Action [Fun] Mystery Item Box

BeniS

Advanced OT User
Senator
Joined
Aug 8, 2009
Messages
1,850
Reaction score
189
Location
New Zealand
Mystery Item Box

I made this script a while back and thought I'd release it :D

Info:
Its like a normal quest chest that gives you an item, but instead of giving the same item to people, it gives you a random item from a list of 10 items!

You can change all the items I have listed, they are just examples.

mysterybox.lua
Lua:
--[[
	!---------------------------------!
	!---Created by Teh Maverick-------!
	!-------www.otland.net------------!
	!---------------------------------!
]]

local mystery_items = 
	
	{
		[1]={id=8902, count=1, name='a Spellbook of Mind Control'},
		[2]={id=10521, count=1, name='a Moon Backpack'},
		[3]={id=7903, count=1, name='a Terra Hood'},
		[4]={id=2195, count=1, name='Boots of Haste'},
		[5]={id=2536, count=1, name='a Medusa Shield'},
		[6]={id=7404, count=1, name='an Assassin Dagger'},
		[7]={id=7414, count=1, name='an Abyss Hammer'},
		[8]={id=7411, count=1, name='an Ornamented Axe'},
		[9]={id=8857, count=1, name='a Silkweaver Bow'},
		[10]={id=8853, count=1, name='an Ironworker'}
	}

function onUse(cid, item, fromPosition, itemEx, toPosition)
   	if item.uid == 16200 then
	      queststatus = getPlayerStorageValue(cid,9100)
   		 if queststatus == -1 then
		   local random_pick = math.random(1,10)
   			doPlayerSendTextMessage(cid,MESSAGE_INFO_DESCR, "You recive " .. mystery_items[random_pick].name .. " as your mystery item.")
   			doPlayerAddItem(cid,mystery_items[random_pick].id,mystery_items[random_pick].count)
   			setPlayerStorageValue(cid,9100,1)
   		else
   			doPlayerSendTextMessage(cid,MESSAGE_INFO_DESCR, "It is empty.")
   		end
   	  return true
	end
end

edit actions.xml:
PHP:
<action uniqueid="16200" event="script" value="mysteryitem.lua"/>

Then add 16200 to the unique and action values of any chest or item in the map editor!

Hope this script comes in handy for some people, it did for me hehe. Rep++ if you like!

Note: This was written for 0.2+ compatibility! ;p not just 0.3+! (but ofc will work in 0.3)
 
Last edited:
Code:
--[[
	!---------------------------------!
	!---Created by Teh Maverick-------!
	!-------www.otland.net------------!
	!---------------------------------!
]]

local t = {
	{8902, 1},
	{10521, 1},
	{7903, 1},
	{2195, 1},
	{2536, 1},
	{7404, 1},
	{7414, 1},
	{7411, 1},
	{8857, 1},
	{8853, 1}
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
	if getPlayerStorageValue(cid, 9100) == -1 then
		local r = t[math.random(#t)]
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You received " .. (r[2] > 1 and r[2] or getItemInfo(r[1]).article) .. " " .. (r[2] > 1 and getItemInfo(r[1]).plural or getItemInfo(r[1]).name) .. " as your mystery item.")
		doPlayerAddItem(cid, r[1], r[2])
		setPlayerStorageValue(cid, 9100, 1)
	else
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "It is empty.")
	end
	return true
end
:D
 
Code:
--[[
	!---------------------------------!
	!---Created by Teh Maverick-------!
	!-------www.otland.net------------!
	!---------------------------------!
]]

local t = {
	{8902, 1},
	{10521, 1},
	{7903, 1},
	{2195, 1},
	{2536, 1},
	{7404, 1},
	{7414, 1},
	{7411, 1},
	{8857, 1},
	{8853, 1}
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
	if getPlayerStorageValue(cid, 9100) == -1 then
		local r = t[math.random(#t)]
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You received " .. (r[2] > 1 and r[2] or getItemInfo(r[1]).article) .. " " .. (r[2] > 1 and getItemInfo(r[1]).plural or getItemInfo(r[1]).name) .. " as your mystery item.")
		doPlayerAddItem(cid, r[1], r[2])
		setPlayerStorageValue(cid, 9100, 1)
	else
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "It is empty.")
	end
	return true
end
:D

lmao I like my way better!
 
lol to all you trolls out there that are like "stop failing code it like this!" this script was originally made for 0.2+ so ill leave it as this for compatibility !!!

Xeon your script is stupid, all you did was change the format of the array and make it less complex in the description oh and, this = 1? wtf is that sh** lol make it set a player storage value...
 
Nice one.


I have to admit Teh Maverick's version of this script looks best. D:
 
It looks better, it has better describtion, more user friendly.

Perhaps your code will save the server with 0.0005ms but its important that a code looks good, to the computer just as well as to the human.

If you work for a company as a programmer, and make code without any descriptions or anything, just pick random or short explained values, work with those values without telling what your doing you might end up loosing your job, since professional codes are made so good it should be no problems for a new programmer to step in and continue his work.

I hear this from my teacher 10x times a day, its really annoying, but its inserted into my brain. xD

Your code might be the fastest one. Which it most likely is.
 
Perhaps your code will save the server with 0.0005ms but its important that a code looks good, to the computer just as well as to the human.

If you work for a company as a programmer, and make code without any descriptions or anything, just pick random or short explained values, work with those values without telling what your doing you might end up loosing your job, since professional codes are made so good it should be no problems for a new programmer to step in and continue his work.
To be honest i tottaly agree with you,
It does
%s %d, 100% true; ++rep;
 
Back
Top Bottom