It's a suggestion nothing more, but I would use trie instead of using numerous equal(). Trie is a lot more faster than equal() and code will be more neat. Here an example, absolutely not tested nor if it compiles or not, just fastly done to show you :
Code:
enum Nuke_e { Nuke, NukeAdmin, NukeTimer, NukeCooldown, NukeDropAdmin, NukeDrop };
new gCvarPointer[ Nuke_e - 1 ];
new Trie:gVarsName;
Code:
gVarsName = TrieCreate();
new const CvarName [][] = { "sv_nuke" , "sv_nuke_admin" , "sv_nuke_timer" , "sv_nuke_cooldown" };
new const ConsoleCommandName[][] = { "amx_nuke", "amx_nuke_admin", "amx_nuke_timer", "amx_nuke_cooldown", "amx_nuke_drop" };
new const ClientCommandName [] = "drop_nuke";
new const CvarDefaultValue[] = { "1", NUKE_ADMIN, NUKE_TIMER, NUKE_COOLDOWN };
new i;
for ( i = 0; i < sizeof CvarName; i++ )
{
gCvarPointer[ i ] = register_cvar( CvarName[ i ], CvarDefaultValue[ i ] );
TrieSetCell( gVarsName, CvarName[ i ], i );
}
for ( i = 0; i < sizeof ConsoleCommandName; i++ )
{
register_concmd( ConsoleCommandName[ i ], "HandlerCommand", ADMIN_FLAG );
TrieSetCell( gVarsName, ConsoleCommandName[ i ], i );
}
register_clcmd( ClientCommandName, "HandlerCommand" );
TrieSetCell( gVarsName, ClientCommandName, NukeDrop );
Then,
Code:
public HandlerCommand( id, level, cid )
{
if ( !cmd_access( id, level, cid, 1 ) )
{
return PLUGIN_HANDLED;
}
static Command[ 32 ];
static Arg1 [ 32 ];
static Value;
read_argv( 0, Command, charsmax( Command ) );
read_argv( 1, Arg1, charsmax( Arg1 ) );
if ( TrieGetCell( gVarsData, Command, Value ) )
{
switch( Value )
{
case Nuke : set_pcvar_num ( gCvarPointer[ Nuke ], clamp( str_to_num( Arg1 ), 0, 1 ) );
case NukeAdmin : set_pcvar_num ( gCvarPointer[ NukeAdmin ], clamp( str_to_num( Arg1 ), -1, 1 ) );
case NukeTimer : set_pcvar_num ( gCvarPointer[ NukeTimer ], min( str_to_num( Arg1 ), 10 ) );
case NukeCooldown : set_pcvar_float( gCvarPointer[ NukeCooldown ], str_to_float( Arg1 ) );
case NukeDropAdmin : admin_drop_nuke( id );
case NukeDrop : user_drop_nuke ( id );
}
}
return PLUGIN_HANDLED;
}
I think it's more readable like that. I've removed register_srvcmd() because by registering register_concmd() it registers both console. It may contains some errors but you get the idea.
Edit :
Code:
[fr]
INFO = Ce serveur utilise des Bombes Nucleaires, tape 'drop_nuke' dans la console pour en planter une.
WAIT = Tu dois attendre %d secondes avant de pouvoir planter une bombe.
ALREADY = Il y a deja une bombe sur la map, tu dois attendre jusqu'a ce qu'elle explose.
ONLY_ADMINS = Seulement les admins peuvent planter des bombes nucleaires !
ONLY_USER = Des Bombes Nucleaires peuvent etre seulement plantee avec la commande utilisateur.
__________________