Parent Directory | Revision Log
Revision 44 - (view) (download)
1 : | ian | 1 | /* AMX Mod X |
2 : | * Menus Front-End Plugin | ||
3 : | * | ||
4 : | * by the AMX Mod X Development Team | ||
5 : | * originally developed by OLO | ||
6 : | * | ||
7 : | * This file is part of AMX Mod X. | ||
8 : | * | ||
9 : | * | ||
10 : | * This program is free software; you can redistribute it and/or modify it | ||
11 : | * under the terms of the GNU General Public License as published by the | ||
12 : | * Free Software Foundation; either version 2 of the License, or (at | ||
13 : | * your option) any later version. | ||
14 : | * | ||
15 : | * This program is distributed in the hope that it will be useful, but | ||
16 : | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 : | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
18 : | * General Public License for more details. | ||
19 : | * | ||
20 : | * You should have received a copy of the GNU General Public License | ||
21 : | * along with this program; if not, write to the Free Software Foundation, | ||
22 : | * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
23 : | * | ||
24 : | * In addition, as a special exception, the author gives permission to | ||
25 : | * link the code of this program with the Half-Life Game Engine ("HL | ||
26 : | * Engine") and Modified Game Libraries ("MODs") developed by Valve, | ||
27 : | * L.L.C ("Valve"). You must obey the GNU General Public License in all | ||
28 : | * respects for all of the code used other than the HL Engine and MODs | ||
29 : | * from Valve. If you modify this file, you may extend this exception | ||
30 : | * to your version of the file, but you are not obligated to do so. If | ||
31 : | * you do not wish to do so, delete this exception statement from your | ||
32 : | * version. | ||
33 : | */ | ||
34 : | |||
35 : | #include <amxmodx> | ||
36 : | #include <amxmisc> | ||
37 : | |||
38 : | #define MAXMENUS 128 | ||
39 : | #define STRINGSIZE 32 | ||
40 : | #define STRINGLENGTH STRINGSIZE - 1 | ||
41 : | #define MENUITEMSPERPAGE 8 | ||
42 : | //#define MENUS_NUMBER 16 | ||
43 : | |||
44 : | new g_menuPosition[33] | ||
45 : | new g_menusNumber = 0 | ||
46 : | new g_menuBody[MAXMENUS][STRINGSIZE] | ||
47 : | new bool:g_menuBodyPhrase[MAXMENUS] | ||
48 : | new g_menuCmd[MAXMENUS][STRINGSIZE] | ||
49 : | new g_menuAccess[MAXMENUS] | ||
50 : | new g_menuPlugin[MAXMENUS][STRINGSIZE] | ||
51 : | |||
52 : | new g_coloredMenus | ||
53 : | |||
54 : | new g_clientMenuPosition[33] | ||
55 : | new g_clientMenusNumber = 0 | ||
56 : | new g_clientMenuBody[MAXMENUS][STRINGSIZE] | ||
57 : | new bool:g_clientMenuBodyPhrase[MAXMENUS] | ||
58 : | new g_clientMenuCmd[MAXMENUS][STRINGSIZE] | ||
59 : | new g_clientMenuAccess[MAXMENUS] | ||
60 : | new g_clientMenuPlugin[MAXMENUS][STRINGSIZE] | ||
61 : | |||
62 : | // menuBody: Text that will be shown for this item in menu | ||
63 : | // menuCmd: Command that should be executed to start menu | ||
64 : | // menuAccess: Access required for menu | ||
65 : | // menuPlugin: The exact case-insensitive name of plugin holding the menu command | ||
66 : | public AddMenu(const menuBody[], const menuCmd[], const menuAccess, const menuPlugin[]) | ||
67 : | { | ||
68 : | if (g_menusNumber + 1 == MAXMENUS) | ||
69 : | { | ||
70 : | log_amx("Error: Plugin ^"%s^" tried to add a menu item to Menu Front-End plugin with maximum menu items reached!", menuPlugin) | ||
71 : | return | ||
72 : | } | ||
73 : | |||
74 : | copy(g_menuBody[g_menusNumber], STRINGLENGTH, menuBody) | ||
75 : | g_menuBodyPhrase[g_menusNumber] = false | ||
76 : | |||
77 : | copy(g_menuCmd[g_menusNumber], STRINGLENGTH, menuCmd) | ||
78 : | g_menuAccess[g_menusNumber] = menuAccess | ||
79 : | |||
80 : | copy(g_menuPlugin[g_menusNumber], STRINGLENGTH, menuPlugin) | ||
81 : | |||
82 : | g_menusNumber++ | ||
83 : | server_print("Menu item %d added to Menus Front-End: ^"%s^" from plugin ^"%s^"", g_menusNumber, menuBody, menuPlugin) | ||
84 : | } | ||
85 : | |||
86 : | public AddMenuLang(const menuBody[], const menuCmd[], const menuAccess, const menuPlugin[]) | ||
87 : | { | ||
88 : | if (g_menusNumber + 1 == MAXMENUS) | ||
89 : | { | ||
90 : | log_amx("Error: Plugin ^"%s^" tried to add a menu item to Menu Front-End plugin with maximum menu items reached!", menuPlugin) | ||
91 : | return | ||
92 : | } | ||
93 : | |||
94 : | copy(g_menuBody[g_menusNumber], STRINGLENGTH, menuBody) | ||
95 : | g_menuBodyPhrase[g_menusNumber] = true | ||
96 : | |||
97 : | copy(g_menuCmd[g_menusNumber], STRINGLENGTH, menuCmd) | ||
98 : | g_menuAccess[g_menusNumber] = menuAccess | ||
99 : | |||
100 : | copy(g_menuPlugin[g_menusNumber], STRINGLENGTH, menuPlugin) | ||
101 : | g_menusNumber++ | ||
102 : | |||
103 : | //server_print("Menu item %d added to Menus Front-End: ^"%s^" (LANG) from plugin ^"%s^"", g_menusNumber, menuBody, menuPlugin) | ||
104 : | } | ||
105 : | |||
106 : | public AddClientMenu(const menuBody[], const menuCmd[], const menuAccess, const menuPlugin[]) | ||
107 : | { | ||
108 : | if (g_clientMenusNumber + 1 == MAXMENUS) | ||
109 : | { | ||
110 : | log_amx("Error: Plugin ^"%s^" tried to add a menu item to Menu Front-End plugin with maximum menu items reached!", menuPlugin) | ||
111 : | return | ||
112 : | } | ||
113 : | |||
114 : | copy(g_clientMenuBody[g_clientMenusNumber], STRINGLENGTH, menuBody) | ||
115 : | g_clientMenuBodyPhrase[g_clientMenusNumber] = false | ||
116 : | |||
117 : | copy(g_clientMenuCmd[g_clientMenusNumber], STRINGLENGTH, menuCmd) | ||
118 : | g_clientMenuAccess[g_clientMenusNumber] = menuAccess | ||
119 : | |||
120 : | copy(g_clientMenuPlugin[g_clientMenusNumber], STRINGLENGTH, menuPlugin) | ||
121 : | |||
122 : | g_clientMenusNumber++ | ||
123 : | server_print("Client menu item %d added to Client Menus Front-End: ^"%s^" from plugin ^"%s^"", g_clientMenusNumber, menuBody, menuPlugin) | ||
124 : | } | ||
125 : | |||
126 : | AddDefaultMenus() | ||
127 : | { | ||
128 : | ian | 44 | new flags; |
129 : | AddMenuLang("KICK_PLAYER", "amx_kickmenu", get_clcmd_flags("amx_kickmenu", flags) ? flags : ADMIN_KICK , "Players Menu") | ||
130 : | AddMenuLang("BAN_PLAYER", "amx_banmenu", get_clcmd_flags("amx_banmenu", flags) ? flags : ADMIN_BAN, "Players Menu") | ||
131 : | AddMenuLang("SLAP_SLAY", "amx_slapmenu", get_clcmd_flags("amx_slapmenu", flags) ? flags : ADMIN_SLAY, "Players Menu") | ||
132 : | AddMenuLang("TEAM_PLAYER", "amx_teammenu", get_clcmd_flags("amx_teammenu", flags) ? flags : ADMIN_LEVEL_A, "Players Menu") | ||
133 : | AddMenuLang("CHANGEL", "amx_mapmenu", get_clcmd_flags("amx_mapmenu", flags) ? flags : ADMIN_MAP, "Maps Menu") | ||
134 : | AddMenuLang("VOTE_MAPS", "amx_votemapmenu", get_clcmd_flags("amx_votemapmenu", flags) ? flags : ADMIN_VOTE, "Maps Menu") | ||
135 : | AddMenuLang("SPECH_STUFF", "amx_speechmenu", get_clcmd_flags("amx_speechmenu", flags) ? flags : ADMIN_MENU, "Commands Menu") | ||
136 : | AddMenuLang("CLIENT_COM", "amx_clcmdmenu", get_clcmd_flags("amx_clcmdmenu", flags) ? flags : ADMIN_LEVEL_A, "Players Menu") | ||
137 : | AddMenuLang("SERVER_COM", "amx_cmdmenu", get_clcmd_flags("amx_cmdmenu", flags) ? flags : ADMIN_MENU, "Commands Menu") | ||
138 : | AddMenuLang("CVARS_SET", "amx_cvarmenu", get_clcmd_flags("amx_cvarmenu", flags) ? flags : ADMIN_CVAR, "Commands Menu") | ||
139 : | AddMenuLang("CONFIG", "amx_cfgmenu", get_clcmd_flags("amx_cfgmenu", flags) ? flags : ADMIN_MENU, "Commands Menu") | ||
140 : | AddMenuLang("LANG_SET", "amx_langmenu", get_clcmd_flags("amx_langmenu", flags) ? flags : ADMIN_CFG, "Multi-Lingual System") | ||
141 : | AddMenuLang("STATS_SET", "amx_statscfgmenu", get_clcmd_flags("amx_statscfgmenu", flags) ? flags : ADMIN_CFG, "Stats Configuration") | ||
142 : | AddMenuLang("PAUSE_PLUG", "amx_pausecfgmenu", get_clcmd_flags("amx_pausecfgmenu", flags) ? flags : ADMIN_CFG, "Pause Plugins") | ||
143 : | AddMenuLang("RES_WEAP", "amx_restmenu", get_clcmd_flags("amx_restmenu", flags) ? flags : ADMIN_CFG, "Restrict Weapons") | ||
144 : | AddMenuLang("TELE_PLAYER", "amx_teleportmenu", get_clcmd_flags("amx_teleportmenu", flags) ? flags : ADMIN_CFG, "Teleport Menu") | ||
145 : | ian | 1 | } |
146 : | ian | 44 | stock bool:get_clcmd_flags(const search_command[], &flags) |
147 : | { | ||
148 : | new count = get_clcmdsnum(-1); | ||
149 : | static cmd[128]; | ||
150 : | static info[1]; | ||
151 : | new _flags; | ||
152 : | ian | 1 | |
153 : | ian | 44 | for (new i = 0; i < count; i++) |
154 : | { | ||
155 : | get_clcmd(i, cmd, charsmax(cmd), _flags, info, charsmax(info), -1); | ||
156 : | |||
157 : | if (strcmp(cmd, search_command) == 0) | ||
158 : | { | ||
159 : | flags = _flags; | ||
160 : | return true; | ||
161 : | } | ||
162 : | } | ||
163 : | |||
164 : | return false; | ||
165 : | } | ||
166 : | ian | 1 | public actionMenu(id, key) |
167 : | { | ||
168 : | switch (key) | ||
169 : | { | ||
170 : | case 8: displayMenu(id, ++g_menuPosition[id]) | ||
171 : | case 9: displayMenu(id, --g_menuPosition[id]) | ||
172 : | default: client_cmd(id, "%s", g_menuCmd[g_menuPosition[id] * 8 + key]) | ||
173 : | } | ||
174 : | |||
175 : | return PLUGIN_HANDLED | ||
176 : | } | ||
177 : | |||
178 : | public clientActionMenu(id, key) | ||
179 : | { | ||
180 : | switch (key) | ||
181 : | { | ||
182 : | case 8: clientDisplayMenu(id, ++g_clientMenuPosition[id]) | ||
183 : | case 9: clientDisplayMenu(id, --g_clientMenuPosition[id]) | ||
184 : | default: client_cmd(id, "%s", g_clientMenuCmd[g_clientMenuPosition[id] * 8 + key]) | ||
185 : | } | ||
186 : | |||
187 : | return PLUGIN_HANDLED | ||
188 : | } | ||
189 : | |||
190 : | displayMenu(id, pos) | ||
191 : | { | ||
192 : | if (pos < 0) | ||
193 : | return | ||
194 : | |||
195 : | new menuBody[512] | ||
196 : | new b = 0 | ||
197 : | new start = pos * MENUITEMSPERPAGE | ||
198 : | |||
199 : | if (start >= g_menusNumber) // MENUS_NUMBER | ||
200 : | start = pos = g_menuPosition[id] = 0 | ||
201 : | |||
202 : | new len = format(menuBody, 511, | ||
203 : | |||
204 : | g_coloredMenus ? "\yAMX Mod X Menu\R%d/%d^n\w^n" : "AMX Mod X Menu %d/%d^n^n" , pos + 1, (g_menusNumber / MENUITEMSPERPAGE) + (((g_menusNumber % MENUITEMSPERPAGE) > 0) ? 1 : 0)) | ||
205 : | |||
206 : | new end = start + MENUITEMSPERPAGE | ||
207 : | new keys = MENU_KEY_0 | ||
208 : | |||
209 : | if (end > g_menusNumber) // MENUS_NUMBER | ||
210 : | end = g_menusNumber // MENUS_NUMBER | ||
211 : | |||
212 : | for (new a = start; a < end; ++a) | ||
213 : | { | ||
214 : | ian | 17 | if ( access(id, g_menuAccess[a]) && |
215 : | ((is_plugin_loaded(g_menuPlugin[a]) != -1) || // search plugins for registered name | ||
216 : | (is_plugin_loaded(g_menuPlugin[a], true) != -1))) // search plugins for filename | ||
217 : | ian | 1 | { |
218 : | keys |= (1<<b) | ||
219 : | |||
220 : | if (g_menuBodyPhrase[a]) | ||
221 : | len += format(menuBody[len], 511-len, "%d. %L^n", ++b, id, g_menuBody[a]) | ||
222 : | else | ||
223 : | len += format(menuBody[len], 511-len, "%d. %s^n", ++b, g_menuBody[a]) | ||
224 : | } else { | ||
225 : | ++b | ||
226 : | |||
227 : | if (g_coloredMenus) | ||
228 : | { | ||
229 : | if (g_menuBodyPhrase[a]) | ||
230 : | len += format(menuBody[len], 511-len, "\d%d. %L^n\w", b, id, g_menuBody[a]) | ||
231 : | else | ||
232 : | len += format(menuBody[len], 511-len, "\d%d. %s^n\w", b, g_menuBody[a]) | ||
233 : | } else { | ||
234 : | if (g_menuBodyPhrase[a]) | ||
235 : | len += format(menuBody[len], 511-len, "#. %L^n", id, g_menuBody[a]) | ||
236 : | else | ||
237 : | len += format(menuBody[len], 511-len, "#. %s^n", g_menuBody[a]) | ||
238 : | } | ||
239 : | } | ||
240 : | } | ||
241 : | |||
242 : | if (end != g_menusNumber) // MENUS_NUMBER | ||
243 : | { | ||
244 : | format(menuBody[len], 511-len, "^n9. %L...^n0. %L", id, "MORE", id, pos ? "BACK" : "EXIT") | ||
245 : | keys |= MENU_KEY_9 | ||
246 : | } else { | ||
247 : | format(menuBody[len], 511-len, "^n0. %L", id, pos ? "BACK" : "EXIT") | ||
248 : | } | ||
249 : | |||
250 : | show_menu(id, keys, menuBody) | ||
251 : | } | ||
252 : | |||
253 : | clientDisplayMenu(id, pos) | ||
254 : | { | ||
255 : | if (pos < 0) | ||
256 : | return | ||
257 : | |||
258 : | new menuBody[512] | ||
259 : | new b = 0 | ||
260 : | new start = pos * MENUITEMSPERPAGE | ||
261 : | |||
262 : | if (start >= g_clientMenusNumber) // MENUS_NUMBER | ||
263 : | start = pos = g_clientMenuPosition[id] = 0 | ||
264 : | |||
265 : | new len = format(menuBody, 511, g_coloredMenus ? "\yAMX Mod X Client Menu\R%d/%d^n\w^n" : "AMX Mod X Client Menu %d/%d^n^n" , pos + 1, (g_clientMenusNumber / MENUITEMSPERPAGE) + (((g_clientMenusNumber % MENUITEMSPERPAGE) > 0) ? 1 : 0)) | ||
266 : | |||
267 : | new end = start + MENUITEMSPERPAGE | ||
268 : | new keys = MENU_KEY_0 | ||
269 : | |||
270 : | if (end > g_clientMenusNumber) // MENUS_NUMBER | ||
271 : | end = g_clientMenusNumber // MENUS_NUMBER | ||
272 : | |||
273 : | for (new a = start; a < end; ++a) | ||
274 : | { | ||
275 : | ian | 17 | if ( access(id, g_clientMenuAccess[a]) && |
276 : | ((is_plugin_loaded(g_clientMenuPlugin[a]) != -1) || // search plugins for registered name | ||
277 : | (is_plugin_loaded(g_clientMenuPlugin[a], true) != -1))) // search plugins for file name | ||
278 : | ian | 1 | { |
279 : | keys |= (1<<b) | ||
280 : | |||
281 : | if (g_clientMenuBodyPhrase[a]) | ||
282 : | len += format(menuBody[len], 511-len, "%d. %L^n", ++b, id, g_clientMenuBody[a]) | ||
283 : | else | ||
284 : | len += format(menuBody[len], 511-len, "%d. %s^n", ++b, g_clientMenuBody[a]) | ||
285 : | } else { | ||
286 : | ++b | ||
287 : | |||
288 : | if (g_coloredMenus) | ||
289 : | { | ||
290 : | if (g_clientMenuBodyPhrase[a]) | ||
291 : | len += format(menuBody[len], 511-len, "\d%d. %L^n\w", b, id, g_clientMenuBody[a]) | ||
292 : | else | ||
293 : | len += format(menuBody[len], 511-len, "\d%d. %s^n\w", b, g_clientMenuBody[a]) | ||
294 : | } else { | ||
295 : | if (g_clientMenuBodyPhrase[a]) | ||
296 : | len += format(menuBody[len], 511-len, "#. %L^n", id, g_clientMenuBody[a]) | ||
297 : | else | ||
298 : | len += format(menuBody[len], 511-len, "#. %s^n", g_clientMenuBody[a]) | ||
299 : | } | ||
300 : | } | ||
301 : | } | ||
302 : | |||
303 : | if (end != g_clientMenusNumber) // MENUS_NUMBER | ||
304 : | { | ||
305 : | format(menuBody[len], 511-len, "^n9. %L...^n0. %L", id, "MORE", id, pos ? "BACK" : "EXIT") | ||
306 : | keys |= MENU_KEY_9 | ||
307 : | } | ||
308 : | else { | ||
309 : | format(menuBody[len], 511-len, "^n0. %L", id, pos ? "BACK" : "EXIT") | ||
310 : | } | ||
311 : | |||
312 : | show_menu(id, keys, menuBody) | ||
313 : | } | ||
314 : | |||
315 : | public cmdMenu(id, level, cid) | ||
316 : | { | ||
317 : | if (cmd_access(id, level, cid, 1)) | ||
318 : | displayMenu(id, g_menuPosition[id] = 0) | ||
319 : | |||
320 : | return PLUGIN_HANDLED | ||
321 : | } | ||
322 : | public clientCmdMenu(id, level, cid) | ||
323 : | { | ||
324 : | if (cmd_access(id, level, cid, 1)) | ||
325 : | clientDisplayMenu(id, g_clientMenuPosition[id] = 0) | ||
326 : | |||
327 : | return PLUGIN_HANDLED | ||
328 : | } | ||
329 : | |||
330 : | public addmenuitem_cmd(id, level, cid) | ||
331 : | { | ||
332 : | if (!cmd_access(id, level, cid, 5)) | ||
333 : | return PLUGIN_HANDLED | ||
334 : | |||
335 : | // AddMenu(const menuBody[], const menuCmd[], const menuAccess, const menuPlugin[]) | ||
336 : | new menuBody[STRINGSIZE], menuCmd[STRINGSIZE], flags[STRINGSIZE], menuAccess = 0, menuPlugin[STRINGSIZE] | ||
337 : | read_argv(1, menuBody, STRINGLENGTH) | ||
338 : | read_argv(2, menuCmd, STRINGLENGTH) | ||
339 : | read_argv(3, flags, STRINGLENGTH) | ||
340 : | menuAccess = read_flags(flags) | ||
341 : | read_argv(4, menuPlugin, STRINGLENGTH) | ||
342 : | |||
343 : | AddMenu(menuBody, menuCmd, menuAccess, menuPlugin) | ||
344 : | |||
345 : | return PLUGIN_HANDLED | ||
346 : | } | ||
347 : | |||
348 : | public addclientmenuitem_cmd(id, level, cid) | ||
349 : | { | ||
350 : | if (!cmd_access(id, level, cid, 5)) | ||
351 : | return PLUGIN_HANDLED | ||
352 : | |||
353 : | // AddMenu(const menuBody[], const menuCmd[], const menuAccess, const menuPlugin[]) | ||
354 : | new menuBody[STRINGSIZE], menuCmd[STRINGSIZE], flags[STRINGSIZE], menuAccess = 0, menuPlugin[STRINGSIZE] | ||
355 : | read_argv(1, menuBody, STRINGLENGTH) | ||
356 : | read_argv(2, menuCmd, STRINGLENGTH) | ||
357 : | read_argv(3, flags, STRINGLENGTH) | ||
358 : | menuAccess = read_flags(flags) | ||
359 : | read_argv(4, menuPlugin, STRINGLENGTH) | ||
360 : | |||
361 : | AddClientMenu(menuBody, menuCmd, menuAccess, menuPlugin) | ||
362 : | |||
363 : | return PLUGIN_HANDLED | ||
364 : | } | ||
365 : | |||
366 : | public plugin_init() | ||
367 : | { | ||
368 : | register_plugin("Menus Front-End", AMXX_VERSION_STR, "AMXX Dev Team") | ||
369 : | register_dictionary("menufront.txt") | ||
370 : | register_dictionary("common.txt") | ||
371 : | |||
372 : | register_menucmd(register_menuid("AMX Mod X Menu"), 1023, "actionMenu") | ||
373 : | register_menucmd(register_menuid("AMX Mod X Client Menu"), 1023, "clientActionMenu") | ||
374 : | register_clcmd("amxmodmenu", "cmdMenu", ADMIN_MENU, "- displays menus") | ||
375 : | register_clcmd("amx_menu", "clientCmdMenu", 0, "- displays menus available to client") | ||
376 : | |||
377 : | ian | 17 | register_srvcmd("amx_addmenuitem", "addmenuitem_cmd", 0, "<menu text> <menu command> <access flags> <plugin name | plugin filename> - Add a menu item to Menus Front-End") |
378 : | register_srvcmd("amx_addclientmenuitem", "addclientmenuitem_cmd", 0, "<menu text> <menu command> <access flags> <plugin name | plugin filename> - Add a menu item to Client Menus Front-End") | ||
379 : | ian | 1 | |
380 : | g_coloredMenus = colored_menus() | ||
381 : | |||
382 : | ian | 44 | |
383 : | } | ||
384 : | public plugin_cfg() | ||
385 : | { | ||
386 : | ian | 1 | AddDefaultMenus() |
387 : | |||
388 : | new configs[128] | ||
389 : | get_configsdir(configs, 127) | ||
390 : | server_cmd("exec %s/custommenuitems.cfg", configs) | ||
391 : | } |
Contact | ViewVC Help |
Powered by ViewVC 1.0.4 |