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
-- requested on http://unrealsoftware.de/forum_posts.php?post=386462
addhook("usebutton", "shop_onbutton")
function shop_onbutton(id, buttonX, buttonY)
	local buttonName = string.lower(entity(buttonX, buttonY, "name"))
	
	local findStart, findEnd, weaponID, price = string.find(buttonName, "shop%:(%d*)=(%d*)")
	weaponID, price = tonumber(weaponID), tonumber(price)
	--msg("wpnID: ".. weaponID .." price: " .. price)
	
	if weaponID and price then	-- found values?
		if player(id, "money") >= price then
			parse("setmoney ".. id .." ".. (player(id, "money") - price))
			shop_equip(id, weaponID)
			msg2(id, "©154255154Thanks for the purchase!")
		else
			msg2(id, "©154255154You need $".. price .." to buy this!")
		end
	end
end
-- code snippet from TooManyWeapons: http://unrealsoftware.de/files_show.php?file=16041
shop_unequipable = {}
shop_unequipable[56] = true
shop_unequipable[59] = true
shop_unequipable[60] = true
shop_unequipable[63] = true
shop_unequipable[70] = true
shop_unequipable[71] = true
function shop_equip(id, itemID)
	if not shop_unequipable[itemID] then
		parse("equip " .. id .. " " ..itemID)
		--timer(500, "parse", "equip " .. id .. " " ..itemID)
		--msg("equip " .. id .. " " ..itemID)
	else
		shop_equipUnequipable(id, itemID)
	end
end
function shop_equipUnequipable(id, itemID)
	local playerTileX, playerTileY = player(id, "tilex"), player(id, "tiley")
	parse("spawnitem ".. itemID .." ".. playerTileX .." ".. playerTileY)
	
	local minX, maxX = -1, 1
	local minY, maxY = -1, 1
	
	repeat
		for x = minX, maxX, 1 do
			for y = minY, maxY, 1 do
				if tile(x, y, "deadly") == false and (x ~= playerTileY and y ~= playerTileY) then
					--tp
					parse("setpos ".. id .." ".. (playerTileX + x) * 32 + 16 .." ".. (playerTileY + y) * 32 + 16)
					parse("setpos ".. id .." ".. (playerTileX) * 32 + 16 .." ".. (playerTileY) * 32 + 16)
					
					return true
				end
			end
		end
		
		minX, maxX = minX - 1, maxX - 1
		mixY, maxY = minY - 1, maxY - 1
	until maxX >= 10
	
	return false
end