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

Diff of /cmdmenu.sma

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1, Tue Oct 30 09:08:11 2007 UTC revision 17, Fri Nov 16 15:29:57 2007 UTC
# Line 35  Line 35 
35  #include <amxmodx>  #include <amxmodx>
36  #include <amxmisc>  #include <amxmisc>
37    
38    // Precache sounds from speech.ini - comment this line to disable
39    #define PRECACHE_SPEECHINI
40    
41  /* Commands Menus */  /* Commands Menus */
42    
43  #define MAX_CMDS_LAYERS 3  #define MAX_CMDS_LAYERS 3
# Line 90  Line 93 
93    
94  new g_coloredMenus  new g_coloredMenus
95    
96    
97  public plugin_init()  public plugin_init()
98  {  {
99          register_plugin("Commands Menu", AMXX_VERSION_STR, "AMXX Dev Team")          register_plugin("Commands Menu", AMXX_VERSION_STR, "AMXX Dev Team")
# Line 120  Line 124 
124          g_coloredMenus = colored_menus()          g_coloredMenus = colored_menus()
125  }  }
126    
127    #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  /* Commands menu */  /* Commands menu */
205    
206  public actionCmdMenu(id, key)  public actionCmdMenu(id, key)
# Line 214  Line 295 
295          }          }
296    
297          g_menuLayer[id] = lvl          g_menuLayer[id] = lvl
         new flags = get_user_flags(id)  
298          g_menuSelectNum[id] = 0          g_menuSelectNum[id] = 0
299    
300          new a = lvl * MAX_CMDS          new a = lvl * MAX_CMDS
# Line 224  Line 304 
304          {          {
305                  d = a + c                  d = a + c
306    
307                  if (g_cmdMisc[d][0] & flags)                  if (access(id, g_cmdMisc[d][0]))
308                  {                  {
309                          g_menuSelect[id][g_menuSelectNum[id]++] = d                          g_menuSelect[id][g_menuSelectNum[id]++] = d
310                  }                  }
# Line 359  Line 439 
439          if (!cmd_access(id, level, cid, 1))          if (!cmd_access(id, level, cid, 1))
440                  return PLUGIN_HANDLED                  return PLUGIN_HANDLED
441    
         new flags = get_user_flags(id)  
442          g_menuSelectNum[id] = 0          g_menuSelectNum[id] = 0
443    
444          for (new a = 0; a < g_cvarNum; ++a)          for (new a = 0; a < g_cvarNum; ++a)
445                  if (g_cvarMisc[a][0] & flags)                  if (access(id, g_cvarMisc[a][0]))
446                          g_menuSelect[id][g_menuSelectNum[id]++] = a                          g_menuSelect[id][g_menuSelectNum[id]++] = a
447    
448          displayCvarMenu(id, g_menuPosition[id] = 0)          displayCvarMenu(id, g_menuPosition[id] = 0)

Legend:
Removed from v.1  
changed lines
  Added in v.17

Contact
ViewVC Help
Powered by ViewVC 1.0.4