--- cmdmenu.sma 2007/10/30 09:08:11 1 +++ cmdmenu.sma 2007/11/16 15:29:57 17 @@ -35,6 +35,9 @@ #include #include +// Precache sounds from speech.ini - comment this line to disable +#define PRECACHE_SPEECHINI + /* Commands Menus */ #define MAX_CMDS_LAYERS 3 @@ -90,6 +93,7 @@ new g_coloredMenus + public plugin_init() { register_plugin("Commands Menu", AMXX_VERSION_STR, "AMXX Dev Team") @@ -120,6 +124,83 @@ g_coloredMenus = colored_menus() } +#if defined PRECACHE_SPEECHINI +public plugin_precache( ) +{ + new configsDir[64], config[64]; + get_configsdir( configsDir, 63 ); + formatex( config, 63, "%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; + + while ( line < MAX_CMDS && ! feof( fp ) ) // Loop till MAX_CMDS or EOF + { + fgets( fp, szText, 255 ); // 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, 31, szSound, 127 ); + fieldNums = parse( szSound, field1, 31, field2, 63, field3, 63 ); + if ( fieldNums == 2 && field1[0] == 's' ) // .wav (spk) + { + copy( szSound, 127, field2 ); + copy( sndExt, 4, ".wav" ); + } + else if ( fieldNums == 3 && field1[0] == 'm' && ( field2[0] == 'p' || field2[0] == 'l' ) ) // .mp3 (mp3 play | mp3 loop) + { + copy( szSound, 127, field3 ); + copy( sndExt, 4, ".mp3" ); + } + else // WTH is this sound, drop it. + continue; + + replace_all( szSound, 127, "\'", "" ); // Strips all ugly (and sometimes useless) \' + + if ( szSound[0] == '/' ) + replace( szSound, 127, "/", "" ); // Strip leading slash + + if ( sndExt[1] == 'm' || ( ! equali( szSound, "vox", 3 ) && ! equali( szSound, "fvox", 4 ) && ! equali( szSound, "barney", 6 ) && ! equali( szSound, "hgrunt", 6 ) ) ) + { + // 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, 127, sndExt ); // Add filetype extension if it isn't already specified + if ( sndExt[1] == 'w' ) + format( szSound, 127, "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, 127, "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) @@ -214,7 +295,6 @@ } g_menuLayer[id] = lvl - new flags = get_user_flags(id) g_menuSelectNum[id] = 0 new a = lvl * MAX_CMDS @@ -224,7 +304,7 @@ { d = a + c - if (g_cmdMisc[d][0] & flags) + if (access(id, g_cmdMisc[d][0])) { g_menuSelect[id][g_menuSelectNum[id]++] = d } @@ -359,11 +439,10 @@ if (!cmd_access(id, level, cid, 1)) return PLUGIN_HANDLED - new flags = get_user_flags(id) g_menuSelectNum[id] = 0 for (new a = 0; a < g_cvarNum; ++a) - if (g_cvarMisc[a][0] & flags) + if (access(id, g_cvarMisc[a][0])) g_menuSelect[id][g_menuSelectNum[id]++] = a displayCvarMenu(id, g_menuPosition[id] = 0)