/
unimenu_menus.lua
208 lines (172 loc) · 7.81 KB
/
unimenu_menus.lua
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
-- OLD METHOD OF CREATING MENUS - A LOT OF TIME REQUIRED TO MAKE A LITTLE CHANGE
unimenu_menus["example_menu_old"] = {
title = "Weapon Shop - OLD@b",
items = {
{"AK-47","$2500",{}, function(id)
if player(id,"money")>=2500 then
parse("equip "..id.." 30")
parse("setmoney "..id.." "..player(id,"money")-2500)
else
msg2(id,"You don't have enough money!")
end
end},
{"AWP","$3000", {}, function(id)
if player(id,"money")>=3000 then
parse("equip "..id.." 35")
parse("setmoney "..id.." "..player(id,"money")-3000)
else
msg2(id,"You don't have enough money!")
end
end},
{"M4A1","$2600", {}, function(id)
if player(id,"money")>=2600 then
parse("equip "..id.." 32")
parse("setmoney "..id.." "..player(id,"money")-2600)
else
msg2(id,"You don't have enough money!")
end
end},
{"Five-Seven","$500", {}, function(id)
if player(id,"money")>=500 then
parse("equip "..id.." 6")
parse("setmoney "..id.." "..player(id,"money")-500)
else
msg2(id,"You don't have enough money!")
end
end},
{"Message: Red","$10", {}, function(id)
parse("setmoney "..id.." "..player(id,"money")-10)
msg("©255000000Red Message")
end},
{"Message: Green","$10", {}, function(id)
parse("setmoney "..id.." "..player(id,"money")-10)
msg("©000255000Green Message")
end},
{"Message: Blue","$10", {}, function(id)
parse("setmoney "..id.." "..player(id,"money")-10)
msg("©000000255Blue Message")
end},
{"Message: White","$10", {}, function(id)
parse("setmoney "..id.." "..player(id,"money")-10)
msg("©255255255White Message")
end},
{"Message: Black","$10", {}, function(id)
parse("setmoney "..id.." "..player(id,"money")-10)
msg("©000000000Black Message")
end},
{"Set money", "$1337", {money = 1337}, function (id, data)
parse("setmoney ".. id .." ".. data.money)
end},
{"Set money", "$9000", {}, function (id, data)
parse("setmoney ".. id .." 9000")
end}
},
}
-- NEW METHOD OF CREATING MENUS
do -- to eliminate the copy-paste job, we'll use locals so we can edit the menuID by changing a single line
local menuID = "example_menu_new"
unimenu_newMenu(menuID, "Weapon Shop - NEW@b")
local weaponName = function (id, data) -- we'll use this function as buttonName
return data.weapon
end
local weaponPrice = function (id, data) -- this is for buttonDesc-ription
return "$" .. data.price
end
local onClick = function (id, data) -- equip weapon and set money based on the data values
local weaponName, weaponPrice, weaponID = data.weapon, data.price, data.id
if player(id,"money") >= weaponPrice then
parse("equip "..id.." " .. weaponID)
parse("setmoney "..id.." "..player(id,"money") - weaponPrice)
else
msg2(id,"You don't have enough money to buy '".. weaponName .."'!")
end
end
-- here we have the option execute weaponName and weaponPrice directly, turning the values into returned strings
-- because these functions rely on the data table which we're not planning to change during gameplay
-- You only can do this optimization if you want
-- To do this, append boolean TRUE to the addButton arguments. The first True after the onClick function is for buttonName,
-- the following for buttonDesc and the third for buttonData
-- For example:
--
-- unimenu_addButton(menuID, weaponName, weaponPrice, tempData, onClick, true, true, false) -- false because data is a table; we can leave "false" out
--
unimenu_addButton(menuID, weaponName, weaponPrice, {weapon = "AK-47", price = 2500, id = 30}, onClick)
unimenu_addButton(menuID, weaponName, weaponPrice, {weapon = "AWP", price = 3000, id = 35}, onClick)
unimenu_addButton(menuID, weaponName, weaponPrice, {weapon = "M4A1", price = 2600, id = 32}, onClick, true, true)
unimenu_addButton(menuID, weaponName, weaponPrice, {weapon = "Five-Seven", price = 500, id = 6}, onClick, true, true)
--
local messageColorName = function (id, data)
return data.colorName .. " colored message"
end
local messageColorPrice = function (id, data)
return "$" .. data.price
end
local messageOnClick = function (id, data)
local colorName, color, price = data.colorName, data.colorcode, data.price
if player(id,"money") >= price then
msg("©".. color .."Hello, this is a ".. colorName .."!")
parse("setmoney "..id.." "..player(id,"money") - price)
else
msg2(id,"You don't have enough money to send a '".. colorName .."'!")
end
end
-- same here, the messageColorName and messageColorPrice will stay the same all game long, so we COULD turn them into strings as well
unimenu_addButton(menuID, messageColorName, messageColorPrice, {colorName = "Red", colorcode = "255000000", price = 50}, messageOnClick, true, true)
unimenu_addButton(menuID, messageColorName, messageColorPrice, {colorName = "Green", colorcode = "000255000", price = 30}, messageOnClick)
unimenu_addButton(menuID, messageColorName, messageColorPrice, {colorName = "Blue", colorcode = "000000255", price = 20}, messageOnClick)
unimenu_addButton(menuID, messageColorName, messageColorPrice, {colorName = "White", colorcode = "255255255", price = 250}, messageOnClick)
unimenu_addButton(menuID, messageColorName, messageColorPrice, {colorName = "Black", colorcode = "000000000", price = 100}, messageOnClick)
--
local randomMessageOnClick = function (id)
local r, g, b = tostring(math.random(0, 255)), tostring(math.random(0, 255)), tostring(math.random(0, 255))
local color = "©" .. string.rep("0", 3 - #r) .. r .. string.rep("0", 3 - #g) .. g .. string.rep("0", 3 - #b) .. b
local price = math.random(30, 250)
if player(id,"money") >= price then
msg(color .."Hello, this is a randomly colored message!")
parse("setmoney "..id.." "..player(id,"money") - price)
else
msg2(id,"You don't have enough money to send a randomly colored message!")
end
end
unimenu_addButton(menuID, "[Static] Randomly colored message", "30-250$", {}, randomMessageOnClick)
--
local function dynRandomMessageData(id)
local r, g, b = tostring(math.random(0, 255)), tostring(math.random(0, 255)), tostring(math.random(0, 255))
local color = "©" .. string.rep("0", 3 - #r) .. r .. string.rep("0", 3 - #g) .. g .. string.rep("0", 3 - #b) .. b
local price = math.random(30, 250)
return {["color"] = color, ["price"] = price} -- this table will be used as data and regenerate everytime the menu is constructed
end
local function dynRandomMessageButtonName(id, data)
return "[Dynamic] " .. data.color .. "colored message"
end
local function dynRandomMessageButtonDescription(id, data)
return "$" .. data.price
end
local function dynRandomMessageOnClick(id, data)
if player(id,"money") >= data.price then
msg(data.color .."Hello, this is a randomly colored message!")
parse("setmoney "..id.." "..player(id,"money") - data.price)
else
msg2(id,"You don't have enough money to send a randomly colored message!")
end
end
unimenu_addButton(menuID, dynRandomMessageButtonName, dynRandomMessageButtonDescription, dynRandomMessageData, dynRandomMessageOnClick)
--
local setMoney = function (id, data)
parse("setmoney ".. id .." ".. data.money)
end
unimenu_addButton(menuID, "Set money", "$1337", {money = 1337}, setMoney)
unimenu_addButton(menuID, "Set money", "$9000", {money = 9000}, setMoney)
--
local playersOnline = function ()
return #player(0, "table") .. " out of ".. game("sv_maxplayers")
end
local playersOnlineOnClick = function ()
local online = playersOnline
return "There are " .. online() .. " players on the server!"
end
-- unlike in the examples above, playersOnline function may change it's return value at any time during the gameplay.
-- that's why we'll leave it a function and let UniMenu call it when the menu is calculated
unimenu_addButton(menuID, "Players online:", playersOnline, {}, playersOnlineOnClick)
end
-- add more of those * do ... end * blocks if you need more menus.