// vim: set ts=4 sw=4 tw=99 noet: // // AMX Mod X, based on AMX Mod by Aleksander Naszko ("OLO"). // Copyright (C) The AMX Mod X Development Team. // // This software is licensed under the GNU General Public License, version 3 or higher. // Additional exceptions apply. For full license details, see LICENSE.txt or visit: // https://alliedmods.net/amxmodx-license // // Commands Menu Plugin // #include #include // Precache sounds from speech.ini - comment this line to disable #define PRECACHE_SPEECHINI /* Commands Menus */ #define MAX_CMDS_LAYERS 3 new g_cmdMenuName[MAX_CMDS_LAYERS][] = { "CMD_MENU", "CONF_MENU", "SPE_MENU" }; new g_cmdMenuCmd[MAX_CMDS_LAYERS][] = { "amx_cmdmenu", "amx_cfgmenu", "amx_speechmenu" }; new g_cmdMenuCfg[MAX_CMDS_LAYERS][] = { "cmds.ini", "configs.ini", "speech.ini" }; new g_cmdMenuHelp[MAX_CMDS_LAYERS][] = { "- displays commands menu", "- displays configs menu", "- displays speech menu" }; /* End of Commands Menu */ #define MAX_CMDS 64 #define MAX_CVARS 48 new g_cmdName[MAX_CMDS*MAX_CMDS_LAYERS][32]; new g_cmdCmd[MAX_CMDS*MAX_CMDS_LAYERS][64]; new g_cmdMisc[MAX_CMDS*MAX_CMDS_LAYERS][2]; new g_cmdNum[MAX_CMDS_LAYERS]; new g_cvarNames[MAX_CVARS][32]; new g_cvarMisc[MAX_CVARS][3]; new g_cvarCmd[MAX_CVARS*5][32]; new g_cvarCmdNum; new g_cvarNum; new g_menuPosition[MAX_PLAYERS + 1]; new g_menuSelect[MAX_PLAYERS + 1][MAX_CMDS]; new g_menuSelectNum[MAX_PLAYERS + 1]; new g_menuLayer[MAX_PLAYERS + 1]; new g_coloredMenus; public plugin_init() { register_plugin("Commands Menu", AMXX_VERSION_STR, "AMXX Dev Team"); register_dictionary("cmdmenu.txt"); register_dictionary("common.txt"); new configsDir[64], config[64]; get_configsdir(configsDir, charsmax(configsDir)); for (new a = 0; a < MAX_CMDS_LAYERS; ++a) { new MenuName[64]; formatex(MenuName, charsmax(MenuName), "%L", "en", g_cmdMenuName[a]); register_menucmd(register_menuid(MenuName), 1023, "actionCmdMenu"); register_clcmd(g_cmdMenuCmd[a], "cmdCmdMenu", ADMIN_MENU, g_cmdMenuHelp[a]); formatex(config, charsmax(config), "%s/%s", configsDir, g_cmdMenuCfg[a]); loadCmdSettings(config, a); } register_menucmd(register_menuid("Cvars Menu"), 1023, "actionCvarMenu"); register_clcmd("amx_cvarmenu", "cmdCvarMenu", ADMIN_CVAR, "- displays cvars menu"); new cvars_ini_file[64]; formatex(cvars_ini_file, charsmax(cvars_ini_file), "%s/%s", configsDir, "cvars.ini"); loadCvarSettings(cvars_ini_file); g_coloredMenus = colored_menus(); } #if defined PRECACHE_SPEECHINI public plugin_precache( ) { new configsDir[64], config[64]; get_configsdir(configsDir, charsmax(configsDir)); formatex( config, charsmax(config), "%s/%s", configsDir, "speech.ini" ); new fp = fopen( config, "rt" ); // Read file as text if ( ! fp ) // File doesn't exists { return 0; } new szText[256]; new line = 0; new szName[32], szSound[128], sndExt[5]; new field1[32], field2[64], field3[64]; new fieldNums = 0; new const voxIdent[] = "vox", fvoxIdent[] = "fvox", barneyIdent[] = "barney", hgruntIdent[] = "hgrunt"; while ( line < MAX_CMDS && ! feof( fp ) ) // Loop till MAX_CMDS or EOF { fgets( fp, szText, charsmax(szText) ); // Store line content /* Strips newline */ new len = strlen( szText ); if ( len != 0 && szText[len-1] == '^n' ) // len != 0 because if the last line of the file is empty, there's no newline { szText[--len] = 0; } if ( len == 0 || szText[0] == ';' || szText[0] == '/' ) // Line is empty or a comment { continue; } parse( szText, szName, charsmax(szName), szSound, charsmax(szSound) ); fieldNums = parse( szSound, field1, charsmax(field1), field2, charsmax(field2), field3, charsmax(field3) ); if ( fieldNums == 2 && field1[0] == 's' ) // .wav (spk) { copy( szSound, charsmax(szSound), field2 ); copy( sndExt, charsmax(sndExt), ".wav" ); } else if ( fieldNums == 3 && field1[0] == 'm' && ( field2[0] == 'p' || field2[0] == 'l' ) ) // .mp3 (mp3 play | mp3 loop) { copy( szSound, charsmax(szSound), field3 ); copy( sndExt, charsmax(sndExt), ".mp3" ); } else // WTH is this sound, drop it. continue; replace_all( szSound, charsmax(szSound), "\'", "" ); // Strips all ugly (and sometimes useless) \' if ( szSound[0] == '/' ) { replace( szSound, charsmax(szSound), "/", "" ); // Strip leading slash } if ( sndExt[1] == 'm' || ( ! equali( szSound, voxIdent, charsmax(voxIdent) ) && ! equali( szSound, fvoxIdent, charsmax(fvoxIdent) ) && ! equali( szSound, barneyIdent, charsmax(barneyIdent) ) && ! equali( szSound, hgruntIdent, charsmax(hgruntIdent) ) ) ) { // SzSound is a mp3, or a custom wav (not a vox, fvox, or default sound from HL pak) if ( !equali( szSound[strlen(szSound)-4], sndExt ) ) { add( szSound, charsmax(szSound), sndExt ); // Add filetype extension if it isn't already specified } if ( sndExt[1] == 'w' ) { format( szSound, charsmax(szSound), "sound/%s", szSound ); // spk basedir is $moddir/sound, but mp3 play is $moddir, fix this for the file_exists check } if ( file_exists( szSound ) ) { if ( sndExt[1] == 'm') { precache_generic( szSound ); // mp3 } else { replace( szSound, charsmax(szSound), "sound/", "" ); // wav, strip the leading sound/ we added for our file_exists check precache_sound( szSound ); } } } line++; } fclose( fp ); // Close file return line; } #endif /* Commands menu */ public actionCmdMenu(id, key) { switch (key) { case 8: { displayCmdMenu(id, ++g_menuPosition[id]); } case 9: { displayCmdMenu(id, --g_menuPosition[id]); } default: { new option = g_menuSelect[id][g_menuPosition[id] * 8 + key]; new flags = g_cmdMisc[option][1]; if (flags & 1) server_cmd("%s", g_cmdCmd[option]) else if (flags & 2) client_cmd(id, "%s", g_cmdCmd[option]) else if (flags & 4) client_cmd(0, "%s", g_cmdCmd[option]) if (flags & 8) { displayCmdMenu(id, g_menuPosition[id]); } } } return PLUGIN_HANDLED; } displayCmdMenu(id, pos) { if (pos < 0) { return; } new menuBody[512]; new b = 0; new start = pos * 8; if (start >= g_menuSelectNum[id]) { start = pos = g_menuPosition[id] = 0; } new limit = (g_menuSelectNum[id] / 8 + ((g_menuSelectNum[id] % 8))); new len = formatex(menuBody, charsmax(menuBody), 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); new end = start + 8; new keys = MENU_KEY_0; if (end > g_menuSelectNum[id]) { end = g_menuSelectNum[id]; } for (new a = start; a < end; ++a) { if (g_cmdCmd[g_menuSelect[id][a]][0] == '-') { if (g_coloredMenus) { len += formatex(menuBody[len], charsmax(menuBody) - len, "\d%s^n\w", g_cmdName[g_menuSelect[id][a]]); } else { len += formatex(menuBody[len], charsmax(menuBody) - len, "%s^n", g_cmdName[g_menuSelect[id][a]]); } ++b; } else { keys |= (1< 3) { while (replace(g_cmdCmd[c], charsmax(g_cmdCmd[]), "\'", "^"")) { // do nothing } g_cmdMisc[c][1] = read_flags(szFlags); g_cmdMisc[c][0] = read_flags(szAccess); g_cmdNum[level]++; } } return 1; } /* Cvars menu */ public actionCvarMenu(id, key) { switch (key) { case 8: { displayCvarMenu(id, ++g_menuPosition[id]); } case 9: { displayCvarMenu(id, --g_menuPosition[id]); } default: { new option = g_menuSelect[id][g_menuPosition[id] * 8 + key]; new szValue[32]; get_cvar_string(g_cvarNames[option], szValue, charsmax(szValue)); new end = g_cvarMisc[option][2]; new start = g_cvarMisc[option][1]; for (new i = start; ; ++i) { if (i < end) { if (equal(szValue, g_cvarCmd[i])) { if (++i >= end) { i = start; } set_cvar_string(g_cvarNames[option], g_cvarCmd[i]); break; } } else { set_cvar_string(g_cvarNames[option], g_cvarCmd[start]); break; } } displayCvarMenu(id, g_menuPosition[id]); } } return PLUGIN_HANDLED; } displayCvarMenu(id, pos) { if (pos < 0) { return; } new menuBody[512]; new b = 0; new start = pos * 8; if (start >= g_menuSelectNum[id]) { start = pos = g_menuPosition[id] = 0; } new len = formatex(menuBody, charsmax(menuBody), 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))); new end = start + 8; new keys = MENU_KEY_0; new szValue[64]; if (end > g_menuSelectNum[id]) { end = g_menuSelectNum[id]; } for (new a = start; a < end; ++a) { get_cvar_string(g_cvarNames[g_menuSelect[id][a]], szValue, charsmax(szValue)); keys |= (1<