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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
inventory = {}
inventory.items = {}
inventory.temp = {}
function inventory.getFreePos(id)
	for i=1, 9 do
		if (inventory.items[id][i] == nil) then
			return i
		end
	end
	return nil
end
addhook("join", "inventory.join")
function inventory.join(id)
	inventory.items[id] = {}
	inventory.temp[id] = {}
end
addhook("leave", "inventory.leave")
function inventory.leave(id)
	inventory.items[id] = nil
	inventory.temp[id] = nil
end
addhook("walkover", "inventory.walkover")
function inventory.walkover(id, iid, t)
	local alreadyOwned = false
	local itemlist=playerweapons(id)
	for _,id2 in pairs(itemlist) do
		if (t == id2) then
			alreadyOwned = true
		end
	end
	local pickable = true
	for _,id2 in pairs(itemlist) do
		if (itemtype(id2, "slot") == itemtype(t, "slot")) then
			pickable = false
		end
	end
	if (alreadyOwned == false) and (pickable == false) then
		if (inventory.getFreePos(id) ~= nil) then
			inventory.items[id][inventory.getFreePos(id)] = t
			parse("removeitem "..iid)
		end
	end
end
addhook("serveraction", "inventory.serveraction")
function inventory.serveraction(id, action)
	if (action == 2) then
		local str = ""
	
		for i=1, 9 do
			if (inventory.items[id][i] ~= nil) then
				str = str..","..itemtype(inventory.items[id][i], "name")
			else
				str = str..","
			end
		end
		if (#inventory.items[id] ~= 0) then
			menu(id, "Inventory menu"..str)
		else
			msg2(id, "You have no items in your inventory!")		
		end
	end
end
addhook("menu", "inventory.menu")
function inventory.menu(id, title, button)
	if (title == "Inventory menu") then
		for i=1, 9 do		
			if (button==i) then
				if (inventory.items[id][i] ~= nil) then
					menu(id, "Inventory menu - Item,"..itemtype(inventory.items[id][i], "name")..",,Equip item,Drop item")
					inventory.temp[id].button = button
					inventory.temp[id].select = inventory.items[id][i]
				end
			end
		end
	elseif (title == "Inventory menu - Item") then
		local wpnid = inventory.temp[id].select
		if (button == 3) then
			parse("equip "..id.." "..wpnid)
			inventory.items[id][inventory.temp[id].button] = nil
		elseif (button == 4) then
			parse("spawnitem "..wpnid.." "..player(id, "tilex").." "..player(id, "tiley"))
			inventory.items[id][inventory.temp[id].button] = nil
		end
	end
end