Parent Directory | Revision Log
Revision 17 - (view) (download)
1 : | ian | 1 | /* AMX Mod X |
2 : | * Commands Menu 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 : | ian | 17 | // Precache sounds from speech.ini - comment this line to disable |
39 : | #define PRECACHE_SPEECHINI | ||
40 : | |||
41 : | ian | 1 | /* Commands Menus */ |
42 : | |||
43 : | #define MAX_CMDS_LAYERS 3 | ||
44 : | |||
45 : | new g_cmdMenuName[MAX_CMDS_LAYERS][] = | ||
46 : | { | ||
47 : | "CMD_MENU", | ||
48 : | "CONF_MENU", | ||
49 : | "SPE_MENU" | ||
50 : | } | ||
51 : | |||
52 : | new g_cmdMenuCmd[MAX_CMDS_LAYERS][] = | ||
53 : | { | ||
54 : | "amx_cmdmenu", | ||
55 : | "amx_cfgmenu", | ||
56 : | "amx_speechmenu" | ||
57 : | } | ||
58 : | |||
59 : | new g_cmdMenuCfg[MAX_CMDS_LAYERS][] = | ||
60 : | { | ||
61 : | "cmds.ini", | ||
62 : | "configs.ini", | ||
63 : | "speech.ini" | ||
64 : | } | ||
65 : | |||
66 : | new g_cmdMenuHelp[MAX_CMDS_LAYERS][] = | ||
67 : | { | ||
68 : | "- displays commands menu", | ||
69 : | "- displays configs menu", | ||
70 : | "- displays speech menu" | ||
71 : | } | ||
72 : | |||
73 : | /* End of Commands Menu */ | ||
74 : | |||
75 : | #define MAX_CMDS 32 | ||
76 : | #define MAX_CVARS 48 | ||
77 : | |||
78 : | new g_cmdName[MAX_CMDS*MAX_CMDS_LAYERS][32] | ||
79 : | new g_cmdCmd[MAX_CMDS*MAX_CMDS_LAYERS][64] | ||
80 : | new g_cmdMisc[MAX_CMDS*MAX_CMDS_LAYERS][2] | ||
81 : | new g_cmdNum[MAX_CMDS_LAYERS] | ||
82 : | |||
83 : | new g_cvarNames[MAX_CVARS][32] | ||
84 : | new g_cvarMisc[MAX_CVARS][3] | ||
85 : | new g_cvarCmd[MAX_CVARS*5][32] | ||
86 : | new g_cvarCmdNum | ||
87 : | new g_cvarNum | ||
88 : | |||
89 : | new g_menuPosition[33] | ||
90 : | new g_menuSelect[33][64] | ||
91 : | new g_menuSelectNum[33] | ||
92 : | new g_menuLayer[33] | ||
93 : | |||
94 : | new g_coloredMenus | ||
95 : | |||
96 : | ian | 17 | |
97 : | ian | 1 | public plugin_init() |
98 : | { | ||
99 : | register_plugin("Commands Menu", AMXX_VERSION_STR, "AMXX Dev Team") | ||
100 : | register_dictionary("cmdmenu.txt") | ||
101 : | register_dictionary("common.txt") | ||
102 : | |||
103 : | new configsDir[64], config[64] | ||
104 : | get_configsdir(configsDir, 63) | ||
105 : | |||
106 : | for (new a = 0; a < MAX_CMDS_LAYERS; ++a) | ||
107 : | { | ||
108 : | new MenuName[64] | ||
109 : | |||
110 : | format(MenuName, 63, "%L", "en", g_cmdMenuName[a]) | ||
111 : | register_menucmd(register_menuid(MenuName), 1023, "actionCmdMenu") | ||
112 : | register_clcmd(g_cmdMenuCmd[a], "cmdCmdMenu", ADMIN_MENU, g_cmdMenuHelp[a]) | ||
113 : | format(config, 63, "%s/%s", configsDir, g_cmdMenuCfg[a]) | ||
114 : | loadCmdSettings(config, a) | ||
115 : | } | ||
116 : | |||
117 : | register_menucmd(register_menuid("Cvars Menu"), 1023, "actionCvarMenu") | ||
118 : | register_clcmd("amx_cvarmenu", "cmdCvarMenu", ADMIN_CVAR, "- displays cvars menu") | ||
119 : | |||
120 : | new cvars_ini_file[64]; | ||
121 : | format(cvars_ini_file, 63, "%s/%s", configsDir, "cvars.ini"); | ||
122 : | loadCvarSettings(cvars_ini_file) | ||
123 : | |||
124 : | g_coloredMenus = colored_menus() | ||
125 : | } | ||
126 : | |||
127 : | ian | 17 | #if defined PRECACHE_SPEECHINI |
128 : | public plugin_precache( ) | ||
129 : | { | ||
130 : | new configsDir[64], config[64]; | ||
131 : | get_configsdir( configsDir, 63 ); | ||
132 : | formatex( config, 63, "%s/%s", configsDir, "speech.ini" ); | ||
133 : | |||
134 : | new fp = fopen( config, "rt" ); // Read file as text | ||
135 : | |||
136 : | if ( ! fp ) // File doesn't exists | ||
137 : | return 0; | ||
138 : | |||
139 : | new szText[256]; | ||
140 : | new line = 0; | ||
141 : | new szName[32], szSound[128], sndExt[5]; | ||
142 : | new field1[32], field2[64], field3[64]; | ||
143 : | new fieldNums = 0; | ||
144 : | |||
145 : | while ( line < MAX_CMDS && ! feof( fp ) ) // Loop till MAX_CMDS or EOF | ||
146 : | { | ||
147 : | fgets( fp, szText, 255 ); // Store line content | ||
148 : | |||
149 : | /* Strips newline */ | ||
150 : | new len = strlen( szText ); | ||
151 : | if ( len != 0 && szText[len-1] == '^n' ) // len != 0 because if the last line of the file is empty, there's no newline | ||
152 : | szText[--len] = 0; | ||
153 : | |||
154 : | if ( len == 0 || szText[0] == ';' || szText[0] == '/' ) // Line is empty or a comment | ||
155 : | continue; | ||
156 : | |||
157 : | parse( szText, szName, 31, szSound, 127 ); | ||
158 : | fieldNums = parse( szSound, field1, 31, field2, 63, field3, 63 ); | ||
159 : | if ( fieldNums == 2 && field1[0] == 's' ) // .wav (spk) | ||
160 : | { | ||
161 : | copy( szSound, 127, field2 ); | ||
162 : | copy( sndExt, 4, ".wav" ); | ||
163 : | } | ||
164 : | else if ( fieldNums == 3 && field1[0] == 'm' && ( field2[0] == 'p' || field2[0] == 'l' ) ) // .mp3 (mp3 play | mp3 loop) | ||
165 : | { | ||
166 : | copy( szSound, 127, field3 ); | ||
167 : | copy( sndExt, 4, ".mp3" ); | ||
168 : | } | ||
169 : | else // WTH is this sound, drop it. | ||
170 : | continue; | ||
171 : | |||
172 : | replace_all( szSound, 127, "\'", "" ); // Strips all ugly (and sometimes useless) \' | ||
173 : | |||
174 : | if ( szSound[0] == '/' ) | ||
175 : | replace( szSound, 127, "/", "" ); // Strip leading slash | ||
176 : | |||
177 : | if ( sndExt[1] == 'm' || ( ! equali( szSound, "vox", 3 ) && ! equali( szSound, "fvox", 4 ) && ! equali( szSound, "barney", 6 ) && ! equali( szSound, "hgrunt", 6 ) ) ) | ||
178 : | { | ||
179 : | // SzSound is a mp3, or a custom wav (not a vox, fvox, or default sound from HL pak) | ||
180 : | if ( !equali( szSound[strlen(szSound)-4], sndExt ) ) | ||
181 : | add( szSound, 127, sndExt ); // Add filetype extension if it isn't already specified | ||
182 : | if ( sndExt[1] == 'w' ) | ||
183 : | format( szSound, 127, "sound/%s", szSound ); // spk basedir is $moddir/sound, but mp3 play is $moddir, fix this for the file_exists check | ||
184 : | if ( file_exists( szSound ) ) | ||
185 : | { | ||
186 : | if ( sndExt[1] == 'm') | ||
187 : | { | ||
188 : | precache_generic( szSound ); // mp3 | ||
189 : | } | ||
190 : | else | ||
191 : | { | ||
192 : | replace( szSound, 127, "sound/", "" ); // wav, strip the leading sound/ we added for our file_exists check | ||
193 : | precache_sound( szSound ); | ||
194 : | } | ||
195 : | } | ||
196 : | } | ||
197 : | line++ | ||
198 : | } | ||
199 : | fclose( fp ); // Close file | ||
200 : | return line; | ||
201 : | } | ||
202 : | #endif | ||
203 : | |||
204 : | ian | 1 | /* Commands menu */ |
205 : | |||
206 : | public actionCmdMenu(id, key) | ||
207 : | { | ||
208 : | switch (key) | ||
209 : | { | ||
210 : | case 8: displayCmdMenu(id, ++g_menuPosition[id]) | ||
211 : | case 9: displayCmdMenu(id, --g_menuPosition[id]) | ||
212 : | default: | ||
213 : | { | ||
214 : | new option = g_menuSelect[id][g_menuPosition[id] * 8 + key] | ||
215 : | new flags = g_cmdMisc[option][1] | ||
216 : | |||
217 : | if (flags & 1) | ||
218 : | server_cmd("%s", g_cmdCmd[option]) | ||
219 : | else if (flags & 2) | ||
220 : | client_cmd(id, "%s", g_cmdCmd[option]) | ||
221 : | else if (flags & 4) | ||
222 : | client_cmd(0, "%s", g_cmdCmd[option]) | ||
223 : | |||
224 : | if (flags & 8) | ||
225 : | displayCmdMenu(id, g_menuPosition[id]) | ||
226 : | } | ||
227 : | } | ||
228 : | |||
229 : | return PLUGIN_HANDLED | ||
230 : | } | ||
231 : | |||
232 : | displayCmdMenu(id, pos) | ||
233 : | { | ||
234 : | if (pos < 0) | ||
235 : | return | ||
236 : | |||
237 : | new menuBody[512] | ||
238 : | new b = 0 | ||
239 : | new start = pos * 8 | ||
240 : | |||
241 : | if (start >= g_menuSelectNum[id]) | ||
242 : | start = pos = g_menuPosition[id] = 0 | ||
243 : | |||
244 : | new limit = (g_menuSelectNum[id] / 8 + ((g_menuSelectNum[id] % 8))) | ||
245 : | new len = format(menuBody, 511, g_coloredMenus ? "\y%L\R%d/%d^n\w^n" : "%L %d/%d^n^n", id, g_cmdMenuName[g_menuLayer[id]], pos + 1, (limit == 0) ? 1 : limit) | ||
246 : | new end = start + 8 | ||
247 : | new keys = MENU_KEY_0 | ||
248 : | |||
249 : | if (end > g_menuSelectNum[id]) | ||
250 : | end = g_menuSelectNum[id] | ||
251 : | |||
252 : | for (new a = start; a < end; ++a) | ||
253 : | { | ||
254 : | if (g_cmdCmd[g_menuSelect[id][a]][0] == '-') | ||
255 : | { | ||
256 : | if (g_coloredMenus) | ||
257 : | len += format(menuBody[len], 511-len, "\d%s^n\w", g_cmdName[g_menuSelect[id][a]]) | ||
258 : | else | ||
259 : | len += format(menuBody[len], 511-len, "%s^n", g_cmdName[g_menuSelect[id][a]]) | ||
260 : | ++b | ||
261 : | } else { | ||
262 : | keys |= (1<<b) | ||
263 : | len += format(menuBody[len], 511-len, "%d. %s^n", ++b, g_cmdName[g_menuSelect[id][a]]) | ||
264 : | } | ||
265 : | } | ||
266 : | |||
267 : | if (end != g_menuSelectNum[id]) | ||
268 : | { | ||
269 : | format(menuBody[len], 511-len, "^n9. %L...^n0. %L", id, "MORE", id, pos ? "BACK" : "EXIT") | ||
270 : | keys |= MENU_KEY_9 | ||
271 : | } | ||
272 : | else | ||
273 : | format(menuBody[len], 511-len, "^n0. %L", id, pos ? "BACK" : "EXIT") | ||
274 : | |||
275 : | new MenuName[64] | ||
276 : | |||
277 : | format(MenuName, 63, "%L", "en", g_cmdMenuName[g_menuLayer[id]]) | ||
278 : | show_menu(id, keys, menuBody, -1, MenuName) | ||
279 : | } | ||
280 : | |||
281 : | public cmdCmdMenu(id, level, cid) | ||
282 : | { | ||
283 : | if (!cmd_access(id, level, cid, 1)) | ||
284 : | return PLUGIN_HANDLED | ||
285 : | |||
286 : | new szCmd[32] | ||
287 : | read_argv(0, szCmd, 31) | ||
288 : | new lvl = 0 | ||
289 : | |||
290 : | while (lvl < MAX_CMDS_LAYERS) | ||
291 : | { | ||
292 : | if (equal(g_cmdMenuCmd[lvl], szCmd)) | ||
293 : | break | ||
294 : | ++lvl | ||
295 : | } | ||
296 : | |||
297 : | g_menuLayer[id] = lvl | ||
298 : | g_menuSelectNum[id] = 0 | ||
299 : | |||
300 : | new a = lvl * MAX_CMDS | ||
301 : | new d, c = 0 | ||
302 : | |||
303 : | while (c < g_cmdNum[lvl]) | ||
304 : | { | ||
305 : | d = a + c | ||
306 : | |||
307 : | ian | 17 | if (access(id, g_cmdMisc[d][0])) |
308 : | ian | 1 | { |
309 : | g_menuSelect[id][g_menuSelectNum[id]++] = d | ||
310 : | } | ||
311 : | |||
312 : | ++c | ||
313 : | } | ||
314 : | |||
315 : | displayCmdMenu(id, g_menuPosition[id] = 0) | ||
316 : | |||
317 : | return PLUGIN_HANDLED | ||
318 : | } | ||
319 : | |||
320 : | loadCmdSettings(szFilename[], level) | ||
321 : | { | ||
322 : | if (!file_exists(szFilename)) | ||
323 : | return 0 | ||
324 : | |||
325 : | new text[256], szFlags[32], szAccess[32] | ||
326 : | new a, pos = 0, c, d = level * MAX_CMDS | ||
327 : | |||
328 : | while (g_cmdNum[level] < MAX_CMDS && read_file(szFilename, pos++, text, 255, a)) | ||
329 : | { | ||
330 : | if (text[0] == ';') continue | ||
331 : | c = d + g_cmdNum[level] | ||
332 : | |||
333 : | if (parse(text, g_cmdName[c], 31, g_cmdCmd[c], 63, szFlags, 31, szAccess, 31) > 3) | ||
334 : | { | ||
335 : | while (replace(g_cmdCmd[c], 63, "\'", "^"")) | ||
336 : | { | ||
337 : | // do nothing | ||
338 : | } | ||
339 : | |||
340 : | g_cmdMisc[c][1] = read_flags(szFlags) | ||
341 : | g_cmdMisc[c][0] = read_flags(szAccess) | ||
342 : | g_cmdNum[level]++ | ||
343 : | } | ||
344 : | } | ||
345 : | |||
346 : | return 1 | ||
347 : | } | ||
348 : | |||
349 : | /* Cvars menu */ | ||
350 : | |||
351 : | public actionCvarMenu(id, key) | ||
352 : | { | ||
353 : | switch (key) | ||
354 : | { | ||
355 : | case 8: displayCvarMenu(id, ++g_menuPosition[id]) | ||
356 : | case 9: displayCvarMenu(id, --g_menuPosition[id]) | ||
357 : | default: | ||
358 : | { | ||
359 : | new option = g_menuSelect[id][g_menuPosition[id] * 8 + key] | ||
360 : | new szValue[32] | ||
361 : | |||
362 : | get_cvar_string(g_cvarNames[option], szValue, 31) | ||
363 : | |||
364 : | new end = g_cvarMisc[option][2] | ||
365 : | new start = g_cvarMisc[option][1] | ||
366 : | |||
367 : | for (new i = start; ; ++i) | ||
368 : | { | ||
369 : | if (i < end) | ||
370 : | { | ||
371 : | if (equal(szValue, g_cvarCmd[i])) | ||
372 : | { | ||
373 : | if (++i >= end) | ||
374 : | { | ||
375 : | i = start | ||
376 : | } | ||
377 : | |||
378 : | set_cvar_string(g_cvarNames[option], g_cvarCmd[i]) | ||
379 : | break | ||
380 : | } | ||
381 : | } else { | ||
382 : | set_cvar_string(g_cvarNames[option], g_cvarCmd[start]) | ||
383 : | break | ||
384 : | } | ||
385 : | } | ||
386 : | displayCvarMenu(id, g_menuPosition[id]) | ||
387 : | } | ||
388 : | } | ||
389 : | |||
390 : | return PLUGIN_HANDLED | ||
391 : | } | ||
392 : | |||
393 : | displayCvarMenu(id, pos) | ||
394 : | { | ||
395 : | if (pos < 0) | ||
396 : | return | ||
397 : | |||
398 : | new menuBody[512] | ||
399 : | new b = 0 | ||
400 : | new start = pos * 8 | ||
401 : | |||
402 : | if (start >= g_menuSelectNum[id]) | ||
403 : | start = pos = g_menuPosition[id] = 0 | ||
404 : | |||
405 : | new len = format(menuBody, 511, g_coloredMenus ? "\yCvars Menu\R%d/%d^n\w^n" : "Cvars Menu %d/%d^n^n", pos + 1, (g_menuSelectNum[id] / 8 + ((g_menuSelectNum[id] % 8) ? 1 : 0))) | ||
406 : | |||
407 : | new end = start + 8 | ||
408 : | new keys = MENU_KEY_0 | ||
409 : | new szValue[64] | ||
410 : | |||
411 : | if (end > g_menuSelectNum[id]) | ||
412 : | end = g_menuSelectNum[id] | ||
413 : | |||
414 : | for (new a = start; a < end; ++a) | ||
415 : | { | ||
416 : | get_cvar_string(g_cvarNames[g_menuSelect[id][a]], szValue, 31) | ||
417 : | keys |= (1<<b) | ||
418 : | ++b | ||
419 : | |||
420 : | if (g_coloredMenus) | ||
421 : | len += format(menuBody[len], 511-len, "%d. %s\R%s^n\w", b, g_cvarNames[g_menuSelect[id][a]], szValue) | ||
422 : | else | ||
423 : | len += format(menuBody[len], 511-len, "%d. %s %s^n", b, g_cvarNames[g_menuSelect[id][a]], szValue) | ||
424 : | } | ||
425 : | |||
426 : | if (end != g_menuSelectNum[id]) | ||
427 : | { | ||
428 : | format(menuBody[len], 511-len, "^n9. %L...^n0. %L", id, "MORE", id, pos ? "BACK" : "EXIT") | ||
429 : | keys |= MENU_KEY_9 | ||
430 : | } | ||
431 : | else | ||
432 : | format(menuBody[len], 511-len, "^n0. %L", id, pos ? "BACK" : "EXIT") | ||
433 : | |||
434 : | show_menu(id, keys, menuBody) | ||
435 : | } | ||
436 : | |||
437 : | public cmdCvarMenu(id, level, cid) | ||
438 : | { | ||
439 : | if (!cmd_access(id, level, cid, 1)) | ||
440 : | return PLUGIN_HANDLED | ||
441 : | |||
442 : | g_menuSelectNum[id] = 0 | ||
443 : | |||
444 : | for (new a = 0; a < g_cvarNum; ++a) | ||
445 : | ian | 17 | if (access(id, g_cvarMisc[a][0])) |
446 : | ian | 1 | g_menuSelect[id][g_menuSelectNum[id]++] = a |
447 : | |||
448 : | displayCvarMenu(id, g_menuPosition[id] = 0) | ||
449 : | |||
450 : | return PLUGIN_HANDLED | ||
451 : | } | ||
452 : | |||
453 : | loadCvarSettings(szFilename[]) | ||
454 : | { | ||
455 : | if (!file_exists(szFilename)) | ||
456 : | return 0 | ||
457 : | |||
458 : | new text[256], szValues[12][32] | ||
459 : | new inum, a, pos = 0 | ||
460 : | new cvar_values = MAX_CVARS * 5 | ||
461 : | |||
462 : | // a b c d | ||
463 : | while (g_cvarNum < MAX_CVARS && read_file(szFilename, pos++, text, 255, a)) | ||
464 : | { | ||
465 : | if (text[0] == ';') continue | ||
466 : | |||
467 : | inum = parse(text, g_cvarNames[g_cvarNum], 31, | ||
468 : | szValues[0], 31, szValues[1], 31, szValues[2], 31, | ||
469 : | szValues[3], 31, szValues[4], 31, szValues[5], 31, | ||
470 : | szValues[6], 31, szValues[7], 31, szValues[8], 31, | ||
471 : | szValues[9], 31, szValues[10], 31, szValues[11], 31) | ||
472 : | |||
473 : | inum -= 2 | ||
474 : | if (inum < 2) continue | ||
475 : | g_cvarMisc[g_cvarNum][1] = g_cvarCmdNum | ||
476 : | |||
477 : | for (a = 0; a < inum && g_cvarCmdNum < cvar_values; ++a) | ||
478 : | { | ||
479 : | while (replace(szValues[a], 31, "\'", "^"")) | ||
480 : | { | ||
481 : | // do nothing | ||
482 : | } | ||
483 : | |||
484 : | copy(g_cvarCmd[g_cvarCmdNum], 31, szValues[a]) | ||
485 : | g_cvarCmdNum++ | ||
486 : | } | ||
487 : | |||
488 : | g_cvarMisc[g_cvarNum][2] = g_cvarCmdNum | ||
489 : | g_cvarMisc[g_cvarNum][0] = read_flags(szValues[inum]) | ||
490 : | g_cvarNum++ | ||
491 : | } | ||
492 : | |||
493 : | return 1 | ||
494 : | } |
Contact | ViewVC Help |
Powered by ViewVC 1.0.4 |