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
function checkwpn(id,wpn)
	for _, w in pairs(playerweapons(id)) do
		if w == wpn then
			return true
		end
	end
	return false
end
function playerguns(id)
	local pt = {}
	for _, w in pairs(playerweapons(id)) do
		local it = itemtype(w,"slot")
		if it == 1 or it == 2 then
			table.insert(pt,w)
		end
	end
	return pt
end
addhook("use","testuse")
function testuse(id,event,data,xtile,ytile)
	if xtile == 13 and ytile == 7 then -- or where ever is adjacent to the AK on the wall
		-- weapons which are not allowed to trade
		-- 50 KNIFE
		-- 69 MACHETE
		-- 51 HE
		-- 73 MOLOTOV
		local cw = player(id,"weapontype")
		if cw==50 or cw==69 or cw==51 or cw==73 then
			msg2(id,"©255000000Switch to a pistol or another weapon!")
		else
			if player(id,"score") >= Shop_AK47 then -- check if you can afford AK
				local pg = playerguns(id)
				if #pg >= 2 and not checkwpn(id,30) then -- check if you don't have AK in inventory AND you have 2 guns already
					parse("strip "..id.." "..cw)
					msg2(id,"©255000000function 1")
				else
					msg2(id,"©255000000function 2")
				end
				-- either way you are gonna give the weapon (at full ammo) and take the cost
				parse("equip "..id.." 30")
				parse("setscore "..id.." "..(player(id,"score")-Shop_AK47).."")
			else
				msg2(id,"©255000000Not enough money!")
			end
		end
	end
end