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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
local settings = --Settings
{
	--Shop menu settings
	menuTitle = "Shop", --Title of menu
	menuPageNext = "Next page", --Text of next page button
	menuPagePrev = "Previous page", --Text of previous page button
	
	--Chat command settings
	commandShop = "shop", --Chat command to open shop (dont include "!")
	commandHelp = "shophelp", --Chat command to see shop help? (dont include "!")
	helpColor = "000200000", --Color the help text got
	hideCommands = 1, --Hide chat commands? (1 = yes, 0 = no)
	
	--Point settings
	startPoints = 300, --Amount of points each player got at start
	killPoints = 300, --Amount per kill, the amount will be a random one between the 2 numbers
	freePointsTime = 10, --How many secs between each player get free points
	freePointsAmount = 20, --The amount of money they get each time
	
	--HUD settings
	pointId = 10, --The id of this hud text, if it dont shop up in server you may need to change it
	pointText = "Gold: ", --Text in front of the point number
	pointColor = "200200000", --Color the point text got
	pointPos = {10, 200}, --The x and y position of the text
	
	--No money settings
	noMoneyText = "You dont have enough points!", --Text it will say if the player dont have enough money
	noMoneyColor = 255000000 --Color of text for no money
}
local commands = {}
function ChatCommands(id, msg) --My chat command system
local cmd = string.lower(msg)
if commands[cmd] then
commands[cmd](id)
return settings.hideCommands
end
chatInput(id,msg)
end
addhook("say", "ChatCommands")
local function AddCommand(cmd, OnSay) --Used to add a chat command
	commands["!"..string.lower(cmd)] = OnSay
end
AddCommand(settings.commandHelp, function(id) --Chat command to display help
	parse('msg2 '..id..' "©'..settings.helpColor.."-----------------------Shop help-----------------------")
	parse('msg2 '..id..' "©'..settings.helpColor.."Kill enemies to get points (you will get "..settings.killPoints.." points")
	parse('msg2 '..id..' "©'..settings.helpColor.."Type "..settings.commandShop.." to open the shop")
	parse('msg2 '..id..' "©'..settings.helpColor.."Type "..settings.commandHelp.." to see this")
	parse('msg2 '..id..' "©'..settings.helpColor.."--------------------------------------------------------")
end)
local playerData = {} --Table containing all player info
local function SetPoints(id, points) --Used to set point of a player
	if player(id, "bot") == false then
		playerData[id].points = points
		
		parse('hudtxt2 '..id..' '..settings.pointId..' "©'..settings.pointColor..settings.pointText..playerData[id].points..'" '..settings.pointPos[1]..' '..settings.pointPos[2])
	end
end
function SetupPlayer(id) --setup player info
	if player(id, "bot") == false then
		playerData[id] = {}
		playerData[id].page = 1
		
		SetPoints(id, settings.startPoints)
	end
end
addhook("join", "SetupPlayer")
function AddPointsWhenKill(killer, victim, weapon, x, y) --When a player kills another player he will get points
	if player(killer, "bot") == false then
		SetPoints(killer, playerData[killer].points+settings.killPoints)
	end
end
addhook("kill", "AddPointsWhenKill")
local items = {} --Table containing all item info
local function AddItem(name, price, OnBuy) --Used to add a item to the shop
	table.insert(items, {name = name, price =price, OnBuy = OnBuy})
end
local function AddItemWeapon(weapon, price) --Used to add a weapon to the shop
	AddItem(itemtype(weapon, "name"), price, function(id)
		parse('equip '..id..' '..weapon)
		parse('setweapon '..id..' '..weapon)
	end)
end
--Add items here----------------------------------------------------------------------------------------------------------------------
--Page 1/pontions
AddItem("Totem", 50, function(id)
parse("equip "..id.." 54")
end)
AddItem("Pontion of speed", 500, function(id)
	parse ("speedmod "..id.." 8")
end)
AddItem("Small Health Pontion (+25)", 25, function(id)
parse("sethealth "..id.." "..player(id,"health")+25)
	 msg2(id,"©000255000+25HP@C")
end)
AddItem("Medium Health Pontion (+50)", 50, function(id)
parse("sethealth "..id.." "..player(id,"health")+50)
	 msg2(id,"©000255000+50HP@C")
end)
AddItem("Big Health Pontion (+100)", 100, function(id)
parse("sethealth "..id.." "..player(id,"health")+100)
	 msg2(id,"©000255000+100HP@C")
end)
AddItem("Mega Health Pontion (FULL)", 300, function(id)
parse("equip "..id.." 64")
	 msg2(id,"©000255000You have already full HP!@C")
end)
--Page 2
AddItem("Rune of speed", 800, function(id)
	parse ("speedmod "..id.." 13")
end)
AddItem("Rune of health (250HP)", 800, function(id)
	local glow = image("gfx/sprites/flare2.bmp", 0, 0, 100+id)
	imagecolor(glow, 255, 0, 0)
	imagescale(glow, 0.7, 0.7)
	imageblend(glow, 1)
	imagealpha(glow, 0.5)
	parse ("setmaxhealth "..id.." 250")
end)
AddItem("Blue Rune of defence", 600, function(id)
	parse ("setarmor "..id.." 202")
end)
AddItem("Red Rune of defence", 800, function(id)
	local glow = image("gfx/sprites/flare2.bmp", 0, 0, 100+id)
	imagecolor(glow, 0, 255, 0)
	imagescale(glow, 0.7, 0.7)
	imageblend(glow, 1)
	imagealpha(glow, 0.5)
	parse ("setarmor "..id.." 203")
end)
AddItem("Rune of damage", 1250, function(id)
	local glow = image("gfx/sprites/flare2.bmp", 0, 0, 100+id)
	imagecolor(glow, 255, 0, 0)
	imagescale(glow, 0.7, 0.7)
	imageblend(glow, 1)
	imagealpha(glow, 0.5)
	parse ("mp_damagefactor "..id.." 2")
end)
AddItem("Medic Ring", 500, function(id)
	parse ("setarmor "..id.." 204")
	parse ("maxhealth "..id.." 100")
end)
--Page 3
AddItem("Angel Pine(Mage)", 1500, function(id)
if sample.classes.class[id] == 9 then
	local headcrab = image("gfx/wings/Angel.png<m>", 1, 0, 200+id)
	parse ("setmaxhealth "..id.." 50")
	parse ("speedmod "..id.." 10")
	parse ("setarmor "..id.." 204") --heatlsuit
	 else
msg2(id,"You arent mage!")
		 SetPoints(id, playerData[id].points+1500)
end
end)
AddItem("Demons Heart(Demon)", 1200, function(id)
if sample.classes.class[id] == 9 then
	local headcrab = image("gfx/wings/Dark_Angel.png<m>", 1, 0, 200+id)
	parse ("setmaxhealth "..id.." 250")
	parse ("setarmor "..id.." 202") --armor
	parse ("speedmod "..id.." 10")
	 else
msg2(id,"You arent demon!")
		 SetPoints(id, playerData[id].points+1200)
end
end)
--------------------------------------------------------------------------------------------------------------------------------------
local page = 1
local pages = {}
pages[page] = {}
local pageCheck = 0
for k, v in pairs(items) do --Here I am settings up the pages table so I can easly add items without worring about space in the menu
	pageCheck = pageCheck+1
	
	if pageCheck == 7 then
		page = page+1
		pages[page] = {}
		
		pageCheck = 1
	end
	
	table.insert(pages[page], k) --Insert the item index into the page
end
local function GenerateButtonString(item) --I made this so I dont have to type as much over and over
	if item then --If item is valid
		return item.name.."|"..item.price --Return the button text
	else
		return "" --Return no button
	end
end
local function OpenShopMenu(id) --Used to open the shop
	local indexes = pages[playerData[id].page] --Gets a table of the indexes for this page
	
	menu(id, settings.menuTitle..","..GenerateButtonString(items[indexes[1]])..","..GenerateButtonString(items[indexes[2]])..","..GenerateButtonString(items[indexes[3]])..","..GenerateButtonString(items[indexes[4]])..","..GenerateButtonString(items[indexes[5]])..","..GenerateButtonString(items[indexes[6]])..",,"..(pages[playerData[id].page+1] and settings.menuPageNext or "")..","..(pages[playerData[id].page-1] and settings.menuPagePrev or ""))
end
AddCommand(settings.commandShop, OpenShopMenu)
function ShopMenuHook(id, title, button)
	if title == settings.menuTitle then --If its my shop menu
		local index = pages[playerData[id].page][button] --Index of item
		local price = items[index] and items[index].price or nil --Price of item
		
		if button <= 6 then --If one of the 6 buttons is the one pressed then
			if playerData[id].points >= price then --If the players money is more than the price then
				items[index].OnBuy(id) --Do what the items gives
				SetPoints(id, playerData[id].points-price) --Take the players money
			else
				msg2(id, "©"..settings.noMoneyColor..settings.noMoneyText) --Message if the player dont have enough money
			end
		end
		
		if button == 8 then --If button is the "Next page" button
			playerData[id].page = playerData[id].page+1 --Increment the page number for that player
			OpenShopMenu(id) --And open the menu agian with the new page
		elseif button == 9 then --If button is the "Prev page" button
			playerData[id].page = playerData[id].page-1 --Decrement the page number for that player
			OpenShopMenu(id) --And open the menu agian with the new page
		end
		
	end
end
addhook("menu", "ShopMenuHook")
function AddPointsTimer() --Used to give all players some free points
	local playerList = player(0, "table") --Get all players in a table
	
	for k, v in pairs(playerList) do
		if player(v, "bot") == false then
			SetPoints(v, playerData[v].points+settings.freePointsAmount) --Give all existing players some points
		end
	end
end
timer(settings.freePointsTime*1000, "AddPointsTimer", "", 0) --Infinite timer