[Half-Life AMXX] / menufront.sma Repository:
ViewVC logotype

Annotation of /menufront.sma

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (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 :     AddMenuLang("KICK_PLAYER", "amx_kickmenu", ADMIN_KICK, "Players Menu")
129 :     AddMenuLang("BAN_PLAYER", "amx_banmenu", ADMIN_BAN, "Players Menu")
130 :     AddMenuLang("SLAP_SLAY", "amx_slapmenu", ADMIN_SLAY, "Players Menu")
131 :     AddMenuLang("TEAM_PLAYER", "amx_teammenu", ADMIN_LEVEL_A, "Players Menu")
132 :     AddMenuLang("CHANGEL", "amx_mapmenu", ADMIN_MAP, "Maps Menu")
133 :     AddMenuLang("VOTE_MAPS", "amx_votemapmenu", ADMIN_VOTE, "Maps Menu")
134 :     AddMenuLang("SPECH_STUFF", "amx_speechmenu", ADMIN_MENU, "Commands Menu")
135 :     AddMenuLang("CLIENT_COM", "amx_clcmdmenu", ADMIN_LEVEL_A, "Players Menu")
136 :     AddMenuLang("SERVER_COM", "amx_cmdmenu", ADMIN_MENU, "Commands Menu")
137 :     AddMenuLang("CVARS_SET", "amx_cvarmenu", ADMIN_CVAR, "Commands Menu")
138 :     AddMenuLang("CONFIG", "amx_cfgmenu", ADMIN_MENU, "Commands Menu")
139 :     AddMenuLang("LANG_SET", "amx_langmenu", ADMIN_CFG, "Multi-Lingual System")
140 :     AddMenuLang("STATS_SET", "amx_statscfgmenu", ADMIN_CFG, "Stats Configuration")
141 :     AddMenuLang("PAUSE_PLUG", "amx_pausecfgmenu", ADMIN_CFG, "Pause Plugins")
142 :     AddMenuLang("RES_WEAP", "amx_restmenu", ADMIN_CFG, "Restrict Weapons")
143 :     AddMenuLang("TELE_PLAYER", "amx_teleportmenu", ADMIN_CFG, "Teleport Menu")
144 :     }
145 :    
146 :     public actionMenu(id, key)
147 :     {
148 :     switch (key)
149 :     {
150 :     case 8: displayMenu(id, ++g_menuPosition[id])
151 :     case 9: displayMenu(id, --g_menuPosition[id])
152 :     default: client_cmd(id, "%s", g_menuCmd[g_menuPosition[id] * 8 + key])
153 :     }
154 :    
155 :     return PLUGIN_HANDLED
156 :     }
157 :    
158 :     public clientActionMenu(id, key)
159 :     {
160 :     switch (key)
161 :     {
162 :     case 8: clientDisplayMenu(id, ++g_clientMenuPosition[id])
163 :     case 9: clientDisplayMenu(id, --g_clientMenuPosition[id])
164 :     default: client_cmd(id, "%s", g_clientMenuCmd[g_clientMenuPosition[id] * 8 + key])
165 :     }
166 :    
167 :     return PLUGIN_HANDLED
168 :     }
169 :    
170 :     displayMenu(id, pos)
171 :     {
172 :     if (pos < 0)
173 :     return
174 :    
175 :     new menuBody[512]
176 :     new b = 0
177 :     new start = pos * MENUITEMSPERPAGE
178 :    
179 :     if (start >= g_menusNumber) // MENUS_NUMBER
180 :     start = pos = g_menuPosition[id] = 0
181 :    
182 :     new len = format(menuBody, 511,
183 :    
184 :     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))
185 :    
186 :     new end = start + MENUITEMSPERPAGE
187 :     new keys = MENU_KEY_0
188 :    
189 :     if (end > g_menusNumber) // MENUS_NUMBER
190 :     end = g_menusNumber // MENUS_NUMBER
191 :    
192 :     new flags = get_user_flags(id)
193 :    
194 :     for (new a = start; a < end; ++a)
195 :     {
196 :     if ((flags & g_menuAccess[a]) && (is_plugin_loaded(g_menuPlugin[a]) != -1))
197 :     {
198 :     keys |= (1<<b)
199 :    
200 :     if (g_menuBodyPhrase[a])
201 :     len += format(menuBody[len], 511-len, "%d. %L^n", ++b, id, g_menuBody[a])
202 :     else
203 :     len += format(menuBody[len], 511-len, "%d. %s^n", ++b, g_menuBody[a])
204 :     } else {
205 :     ++b
206 :    
207 :     if (g_coloredMenus)
208 :     {
209 :     if (g_menuBodyPhrase[a])
210 :     len += format(menuBody[len], 511-len, "\d%d. %L^n\w", b, id, g_menuBody[a])
211 :     else
212 :     len += format(menuBody[len], 511-len, "\d%d. %s^n\w", b, g_menuBody[a])
213 :     } else {
214 :     if (g_menuBodyPhrase[a])
215 :     len += format(menuBody[len], 511-len, "#. %L^n", id, g_menuBody[a])
216 :     else
217 :     len += format(menuBody[len], 511-len, "#. %s^n", g_menuBody[a])
218 :     }
219 :     }
220 :     }
221 :    
222 :     if (end != g_menusNumber) // MENUS_NUMBER
223 :     {
224 :     format(menuBody[len], 511-len, "^n9. %L...^n0. %L", id, "MORE", id, pos ? "BACK" : "EXIT")
225 :     keys |= MENU_KEY_9
226 :     } else {
227 :     format(menuBody[len], 511-len, "^n0. %L", id, pos ? "BACK" : "EXIT")
228 :     }
229 :    
230 :     show_menu(id, keys, menuBody)
231 :     }
232 :    
233 :     clientDisplayMenu(id, pos)
234 :     {
235 :     if (pos < 0)
236 :     return
237 :    
238 :     new menuBody[512]
239 :     new b = 0
240 :     new start = pos * MENUITEMSPERPAGE
241 :    
242 :     if (start >= g_clientMenusNumber) // MENUS_NUMBER
243 :     start = pos = g_clientMenuPosition[id] = 0
244 :    
245 :     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))
246 :    
247 :     new end = start + MENUITEMSPERPAGE
248 :     new keys = MENU_KEY_0
249 :    
250 :     if (end > g_clientMenusNumber) // MENUS_NUMBER
251 :     end = g_clientMenusNumber // MENUS_NUMBER
252 :    
253 :     new flags = get_user_flags(id)
254 :    
255 :     for (new a = start; a < end; ++a)
256 :     {
257 :     if ((flags & g_clientMenuAccess[a]) && (is_plugin_loaded(g_clientMenuPlugin[a]) != -1))
258 :     {
259 :     keys |= (1<<b)
260 :    
261 :     if (g_clientMenuBodyPhrase[a])
262 :     len += format(menuBody[len], 511-len, "%d. %L^n", ++b, id, g_clientMenuBody[a])
263 :     else
264 :     len += format(menuBody[len], 511-len, "%d. %s^n", ++b, g_clientMenuBody[a])
265 :     } else {
266 :     ++b
267 :    
268 :     if (g_coloredMenus)
269 :     {
270 :     if (g_clientMenuBodyPhrase[a])
271 :     len += format(menuBody[len], 511-len, "\d%d. %L^n\w", b, id, g_clientMenuBody[a])
272 :     else
273 :     len += format(menuBody[len], 511-len, "\d%d. %s^n\w", b, g_clientMenuBody[a])
274 :     } else {
275 :     if (g_clientMenuBodyPhrase[a])
276 :     len += format(menuBody[len], 511-len, "#. %L^n", id, g_clientMenuBody[a])
277 :     else
278 :     len += format(menuBody[len], 511-len, "#. %s^n", g_clientMenuBody[a])
279 :     }
280 :     }
281 :     }
282 :    
283 :     if (end != g_clientMenusNumber) // MENUS_NUMBER
284 :     {
285 :     format(menuBody[len], 511-len, "^n9. %L...^n0. %L", id, "MORE", id, pos ? "BACK" : "EXIT")
286 :     keys |= MENU_KEY_9
287 :     }
288 :     else {
289 :     format(menuBody[len], 511-len, "^n0. %L", id, pos ? "BACK" : "EXIT")
290 :     }
291 :    
292 :     show_menu(id, keys, menuBody)
293 :     }
294 :    
295 :     public cmdMenu(id, level, cid)
296 :     {
297 :     if (cmd_access(id, level, cid, 1))
298 :     displayMenu(id, g_menuPosition[id] = 0)
299 :    
300 :     return PLUGIN_HANDLED
301 :     }
302 :     public clientCmdMenu(id, level, cid)
303 :     {
304 :     if (cmd_access(id, level, cid, 1))
305 :     clientDisplayMenu(id, g_clientMenuPosition[id] = 0)
306 :    
307 :     return PLUGIN_HANDLED
308 :     }
309 :    
310 :     public addmenuitem_cmd(id, level, cid)
311 :     {
312 :     if (!cmd_access(id, level, cid, 5))
313 :     return PLUGIN_HANDLED
314 :    
315 :     // AddMenu(const menuBody[], const menuCmd[], const menuAccess, const menuPlugin[])
316 :     new menuBody[STRINGSIZE], menuCmd[STRINGSIZE], flags[STRINGSIZE], menuAccess = 0, menuPlugin[STRINGSIZE]
317 :     read_argv(1, menuBody, STRINGLENGTH)
318 :     read_argv(2, menuCmd, STRINGLENGTH)
319 :     read_argv(3, flags, STRINGLENGTH)
320 :     menuAccess = read_flags(flags)
321 :     read_argv(4, menuPlugin, STRINGLENGTH)
322 :    
323 :     AddMenu(menuBody, menuCmd, menuAccess, menuPlugin)
324 :    
325 :     return PLUGIN_HANDLED
326 :     }
327 :    
328 :     public addclientmenuitem_cmd(id, level, cid)
329 :     {
330 :     if (!cmd_access(id, level, cid, 5))
331 :     return PLUGIN_HANDLED
332 :    
333 :     // AddMenu(const menuBody[], const menuCmd[], const menuAccess, const menuPlugin[])
334 :     new menuBody[STRINGSIZE], menuCmd[STRINGSIZE], flags[STRINGSIZE], menuAccess = 0, menuPlugin[STRINGSIZE]
335 :     read_argv(1, menuBody, STRINGLENGTH)
336 :     read_argv(2, menuCmd, STRINGLENGTH)
337 :     read_argv(3, flags, STRINGLENGTH)
338 :     menuAccess = read_flags(flags)
339 :     read_argv(4, menuPlugin, STRINGLENGTH)
340 :    
341 :     AddClientMenu(menuBody, menuCmd, menuAccess, menuPlugin)
342 :    
343 :     return PLUGIN_HANDLED
344 :     }
345 :    
346 :     public plugin_init()
347 :     {
348 :     register_plugin("Menus Front-End", AMXX_VERSION_STR, "AMXX Dev Team")
349 :     register_dictionary("menufront.txt")
350 :     register_dictionary("common.txt")
351 :    
352 :     register_menucmd(register_menuid("AMX Mod X Menu"), 1023, "actionMenu")
353 :     register_menucmd(register_menuid("AMX Mod X Client Menu"), 1023, "clientActionMenu")
354 :     register_clcmd("amxmodmenu", "cmdMenu", ADMIN_MENU, "- displays menus")
355 :     register_clcmd("amx_menu", "clientCmdMenu", 0, "- displays menus available to client")
356 :    
357 :     register_srvcmd("amx_addmenuitem", "addmenuitem_cmd", 0, "<menu text> <menu command> <access flags> <plugin name> - Add a menu item to Menus Front-End")
358 :     register_srvcmd("amx_addclientmenuitem", "addclientmenuitem_cmd", 0, "<menu text> <menu command> <access flags> <plugin name> - Add a menu item to Client Menus Front-End")
359 :    
360 :     g_coloredMenus = colored_menus()
361 :    
362 :     AddDefaultMenus()
363 :    
364 :     // Add custom menu items
365 :     new configs[128]
366 :     get_configsdir(configs, 127)
367 :     server_cmd("exec %s/custommenuitems.cfg", configs)
368 :     }

Contact
ViewVC Help
Powered by ViewVC 1.0.4