1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
function contains(table, element)
for _, value in pairs(table) do
if value == element then
return true
end
end
return false
end
function initArray2(f,v)
	local cmd={}
	for c=1,f do
		cmd[c]=v
	end
	return cmd
end
boxused=initArray2(32,false)
price=1000
restrictedweapons={88,45,78,77,87,75,79,80,81,82,83,84,54,72} -- put restricted weapons here
function randomweapon(id)
	weapon=math.rand(1,88)
	if not (contains(restrictedweapons,weapon)) then
		parse("equip "..id.." "..weapon)
	else
		randomweapon(id)
	end
end
addhook("use","randbox")
function randbox(id)
	if (player(id,"tilex")==BUTTONX and player(id,"tiley")==BUTTONY) then
		if (not boxused[id] and player(id,"money")>=price) then
		randomweapon(id)
		boxused[id]=true
		parse("setmoney "..id.." "..(player(id,"money")-price))
		timer((dur*1000),"parse","lua boxused["..id.."]=false")
	elseif (not boxused[id] and player(id,"money")<price) then
		msg2(id,"You don't have enough money!")
	elseif (boxused[id]) then
		msg2(id,"You've already used the random box!")
	end
end
BUTTONX and BUTTONY are the button position in tiles.