AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   print wrong message value (https://forums.alliedmods.net/showthread.php?t=342827)

Fuck For Fun 05-19-2023 12:44

print wrong message value
 
The purpose of the code is that I write
!rt 9
It should show in the ad that you changed to time 9 but it says 0.00 to me


Message console/chat:
Quote:

[Cmd] CheezPuff has set RoundTime to "0.00"
"mp_roundtime" changed to "9.000000"
Code:
PHP Code:

/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"

enum _:CMD_STRUCT
{
    
CMD_NAME    [32],
    
CMD_INCHAT    [32],
    
CMD_SRV        [32],
    
CMD_USAGE    [128],
    
CMD_LEVEL,
};

enum _:Commands
{
    
ROUND_TIME
}

new const 
CommandsList[Commands][CMD_STRUCT] = 
{
    
// !rt     - flag o (SuperAdmin)            
    
{"RoundTime",            "rt",        "mp_roundtime"""ADMIN_LEVEL_C},
}

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd    ("say""HandleSay");
    
register_clcmd    ("say_team""HandleSay");
}

// Say Command Handler.
public HandleSay(client)
{
    new 
said[32];
    new 
param[32];
    new 
szMessage[charsmax(said) + charsmax(param) + 2];
   
    
read_argv(1szMessagecharsmax(szMessage));
    
argbreak(szMessagesaidcharsmax(param), paramcharsmax(param));
 
    for (new 
0Commandsi++)
    {
        if (
equali(said[1], CommandsList[i][CMD_INCHAT]))
        {
            if (!(
get_user_flags(client) & CommandsList[i][CMD_LEVEL]))
            {
                
client_print_color(clientprint_team_default"%s ^3Error^1: You don't have Access Level."PREFIX);
                continue;
            }
            
CommandSelector(iclientparam);
            return 
PLUGIN_HANDLED;
        }
    }
    return 
PLUGIN_CONTINUE;
}

// Say Command Handler (Selector).
CommandSelector(cmdclientparam[])
{
    switch(
cmd)
    {
        case 
ROUND_TIME:    CmdRoundTime    (clientparam);

    }
}

// Command: Round Time.
CmdRoundTime(clientparam[])
{
    new 
num;
    if (
CheckMinMax(clientparamnum19))
    {
        
set_pcvar_float(gCmdPointer[ROUND_TIME], float(num));
        
PrintHasSetCmd(0clientROUND_TIMEfmt("%.1f"num));
    }
   
    return;
}

PrintHasSetCmd(idclientcmdparam[])
{
    
client_print_color(idprint_team_default"%s ^3%n ^1has set ^4%s ^1to ^4^"%s^""PREFIXclientCommandsList[cmd][CMD_NAME], param);
}

// Check Min to Max.
bool:CheckMinMax(clientparam[], &num, const min, const max)
{
    
num str_to_num(param);
    if ( !( 
min <= num <= max ) || !param[0])
    {
        
client_print_color(client print_team_default"%s Value must be %d or %d"PREFIXminmax);
        return 
false;
    }
    
/*if ( !( min <= num && num <= max) || !param[0])
    {
        client_print_color(client, print_team_default, "%s Value must be between %d and %d", PREFIX, min, max);
        return false;
    }*/

    
return true;



lexzor 05-19-2023 14:11

Re: print wrong message value
 
you are creating the "num" variable as a cell then you are formating it with fmt using %.1f. there must be a float value.

also, as a suggestion for your plugin even if it's looking like it's useless:

expecting that you would change the value of a various cvars, some of them can be strings, cell, floats etc, you should do something like this

PHP Code:

enum (+=1
{
    
CMD_VALUE_INT 0,
    
CMD_VALUE_FLOAT
}

enum _:CMD_STRUCT
{
    
CMD_NAME    [32],
    
CMD_INCHAT    [32],
    
CMD_SRV        [32],
    
CMD_USAGE    [128],
    
CMD_LEVEL,
    
CMD_TYPE
};


new const 
CommandsList[Commands][CMD_STRUCT] = 
{
    
// !rt     - flag o (SuperAdmin)            
    
"RoundTime",            "rt",        "mp_roundtime"""ADMIN_LEVEL_CCMD_VALUE_FLOAT }


so you can use switch with CMD_TYPE for command to know which one of set_pcvar_float/string/int will be used.

Fuck For Fun 05-19-2023 15:19

Re: print wrong message value
 
Quote:

Originally Posted by lexzor (Post 2804645)
you are creating the "num" variable as a cell then you are formating it with fmt using %.1f. there must be a float value.

also, as a suggestion for your plugin even if it's looking like it's useless:

expecting that you would change the value of a various cvars, some of them can be strings, cell, floats etc, you should do something like this

PHP Code:

enum (+=1
{
    
CMD_VALUE_INT 0,
    
CMD_VALUE_FLOAT
}

enum _:CMD_STRUCT
{
    
CMD_NAME    [32],
    
CMD_INCHAT    [32],
    
CMD_SRV        [32],
    
CMD_USAGE    [128],
    
CMD_LEVEL,
    
CMD_TYPE
};


new const 
CommandsList[Commands][CMD_STRUCT] = 
{
    
// !rt     - flag o (SuperAdmin)            
    
"RoundTime",            "rt",        "mp_roundtime"""ADMIN_LEVEL_CCMD_VALUE_FLOAT }


so you can use switch with CMD_TYPE for command to know which one of set_pcvar_float/string/int will be used.

i will try
Because this is just an introduction from the code, I have a lot more commands in List
I use param and without

EDIT:
Nothing has changed, still writes to me in chat roundtime 0.00

lexzor 05-19-2023 15:23

Re: print wrong message value
 
i don't know which line is 89. post the code

Fuck For Fun 05-19-2023 15:46

Re: print wrong message value
 
Quote:

Originally Posted by lexzor (Post 2804658)
i don't know which line is 89. post the code

line 89 was your CMD_TYPE i missed it, but is still not that and not work but i think i found the prob
PHP Code:

// Command: Round Time.
CmdRoundTime(clientparam[])
{
    new 
num;
    if (
CheckMinMax(clientparamnum19))
    {
        
set_pcvar_float(gCmdPointer[ROUND_TIME], float(num));
        
PrintHasSetCmd(0clientROUND_TIMEfmt("%.1f"num));
    }
    return;


:arrow: Fixed, thanks for reply
PHP Code:

// Command: Freeze Time.
CmdFreezeTime(clientparam[])
{
    new 
num;
    if (
CheckMinMax(clientparamnum060))
    {
        
//set_pcvar_float(gCmdPointer[FREEZE_TIME], float(num));
        
set_cvar_float(gCmdPointer[FREEZE_TIME], float(num));
        
PrintHasSetCmd(0clientFREEZE_TIMEfmt("%.2f"float(num)));
    }
    return;



Natsheh 05-19-2023 15:57

Re: print wrong message value
 
Alternative solution is to use the console command
PHP Code:

amx_cvar mp_roundtime 


lexzor 05-19-2023 16:07

Re: print wrong message value
 
yes, i posted the fix for that problem

you overkill your mind doing what you want to do, there is a simpler way:

PHP Code:

#include <amxmodx>
#include <amxmisc>

#define PREFIX "^4[TAG]^1"

enum (+=1
{
    
CMD_VALUE_INT 0,
    
CMD_VALUE_FLOAT
}

enum _:CMD_STRUCT
{
    
CMD_NAME    [32],
    
CMD_INCHAT    [32],
    
CMD_SRV        [32],
    
CMD_USAGE    [128],
    
CMD_LEVEL,
    
CMD_TYPE
};


new const 
CommandsList[Commands][CMD_STRUCT] = 
{
    
// !rt     - flag o (SuperAdmin)            
    
"RoundTime",            "rt",        "mp_roundtime"""ADMIN_LEVEL_CCMD_VALUE_FLOAT },
    { 
"StartMoney",           "sm",        "mp_startmoney"""ADMIN_LEVEL_CCMD_VALUE_INT }
}

enum _:Commands
{
    
ROUND_TIME
}

public 
plugin_init()
{
    
register_clcmd    ("say""HandleSay");
    
register_clcmd    ("say_team""HandleSay");
}

// Say Command Handler.
public HandleSay(client)
{
    new 
said[32];
    new 
param[32];
    new 
szMessage[charsmax(said) + charsmax(param) + 2];
   
    
read_argv(1szMessagecharsmax(szMessage));
    
argbreak(szMessagesaidcharsmax(param), paramcharsmax(param));
 
    for (new 
0Commandsi++)
    {
        if (
equali(said[1], CommandsList[i][CMD_INCHAT]))
        {
            if (!(
get_user_flags(client) & CommandsList[i][CMD_LEVEL]))
            {
                
client_print_color(clientprint_team_default"%s ^3Error^1: You don't have Access Level."PREFIX);
                break 
// you want to break the loop here. you found the command, but the user doesn't has the access so is no reason to continue the loop
            
}

            
CommandSelector(iclientparam); //we know position of the command info, it's "i", so we just pass it as cmd_id
            
            
return PLUGIN_HANDLED;
        }
    }
    return 
PLUGIN_CONTINUE;
}

// Say Command Handler (Selector).
CommandSelector(cmd_idclientparam[])
{
    switch(
CommandsList[cmd_id][CMD_TYPE]) //we use cmd_type to know how we should set the value to the cvar pointer
    
{
        case 
CMD_VALUE_INT
        {
            
set_pcvar_num(gCmdPointer[cmd_id], str_to_num(param))
        }

        case 
CMD_VALUE_FLOAT:
        {
            
set_pcvar_float(gCmdPointer[cmd_id], str_to_float(param))
        }
    }

    
PrintHasSetCmd(0clientCMD_IDparam);
}

PrintHasSetCmd(idclientcmdparam[])
{
    
client_print_color(idprint_team_default"%s ^3%n ^1has set ^4%s ^1to ^4^"%s^""PREFIXclientCommandsList[cmd][CMD_NAME], param);



Fuck For Fun 05-19-2023 16:21

Re: print wrong message value
 
Quote:

Originally Posted by lexzor (Post 2804663)
yes, i posted the fix for that problem

you overkill your mind doing what you want to do, there is a simpler way:

PHP Code:

#include <amxmodx>
#include <amxmisc>

#define PREFIX "^4[TAG]^1"

enum (+=1
{
    
CMD_VALUE_INT 0,
    
CMD_VALUE_FLOAT
}

enum _:CMD_STRUCT
{
    
CMD_NAME    [32],
    
CMD_INCHAT    [32],
    
CMD_SRV        [32],
    
CMD_USAGE    [128],
    
CMD_LEVEL,
    
CMD_TYPE
};


new const 
CommandsList[Commands][CMD_STRUCT] = 
{
    
// !rt     - flag o (SuperAdmin)            
    
"RoundTime",            "rt",        "mp_roundtime"""ADMIN_LEVEL_CCMD_VALUE_FLOAT },
    { 
"StartMoney",           "sm",        "mp_startmoney"""ADMIN_LEVEL_CCMD_VALUE_INT }
}

enum _:Commands
{
    
ROUND_TIME
}

public 
plugin_init()
{
    
register_clcmd    ("say""HandleSay");
    
register_clcmd    ("say_team""HandleSay");
}

// Say Command Handler.
public HandleSay(client)
{
    new 
said[32];
    new 
param[32];
    new 
szMessage[charsmax(said) + charsmax(param) + 2];
   
    
read_argv(1szMessagecharsmax(szMessage));
    
argbreak(szMessagesaidcharsmax(param), paramcharsmax(param));
 
    for (new 
0Commandsi++)
    {
        if (
equali(said[1], CommandsList[i][CMD_INCHAT]))
        {
            if (!(
get_user_flags(client) & CommandsList[i][CMD_LEVEL]))
            {
                
client_print_color(clientprint_team_default"%s ^3Error^1: You don't have Access Level."PREFIX);
                break 
// you want to break the loop here. you found the command, but the user doesn't has the access so is no reason to continue the loop
            
}

            
CommandSelector(iclientparam); //we know position of the command info, it's "i", so we just pass it as cmd_id
            
            
return PLUGIN_HANDLED;
        }
    }
    return 
PLUGIN_CONTINUE;
}

// Say Command Handler (Selector).
CommandSelector(cmd_idclientparam[])
{
    switch(
CommandsList[cmd_id][CMD_TYPE]) //we use cmd_type to know how we should set the value to the cvar pointer
    
{
        case 
CMD_VALUE_INT
        {
            
set_pcvar_num(gCmdPointer[cmd_id], str_to_num(param))
        }

        case 
CMD_VALUE_FLOAT:
        {
            
set_pcvar_float(gCmdPointer[cmd_id], str_to_float(param))
        }
    }

    
PrintHasSetCmd(0clientCMD_IDparam);
}

PrintHasSetCmd(idclientcmdparam[])
{
    
client_print_color(idprint_team_default"%s ^3%n ^1has set ^4%s ^1to ^4^"%s^""PREFIXclientCommandsList[cmd][CMD_NAME], param);



Yes my mistake, If the user doesn't have the required access level for a command, there is no need to continue iterating through the loop

Quote:

I'm not going to use cmd_type because my code is really long and it will require me to spend more time on it, right now it's a quarter of my code I have 9 more commands that I'm slowly fixing for now it looks good, if you have another way to improve it all you're welcome
PHP Code:

/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"

#define    PREFIX            "^4[Cmd]^1"

enum _:ALIVE_MODE
{
    
ALL,
    
ALIVE_ONLY,
    
DEAD_ONLY,
};

enum _:CMD_STRUCT
{
    
CMD_NAME    [32],
    
CMD_INCHAT    [32],
    
CMD_SRV        [32],
    
CMD_USAGE    [128],
    
CMD_LEVEL,
};

enum _:Commands
{
    
RESTART_ROUND,
    
ALLTALK,
    
ROUND_TIME,
    
FREEZE_TIME
}

new const 
CommandsList[Commands][CMD_STRUCT] = 
{
    {
"Restart Round",         "rr",        "sv_restart",    "",     ADMIN_KICK    },    // !rr            - flag c (VIP+)
    
{"Alltalk",            "alltalk",    "sv_alltalk",    "",     ADMIN_LEVEL_C    },    // !alltalk     - flag c (SuperAdmin+),
    
{"RoundTime",            "rt",        "mp_roundtime",    "",     ADMIN_LEVEL_C    },    // !rt             - flag o (SuperAdmin)            
    
{"FreezeTime",            "ft",        "mp_freezetime","",     ADMIN_LEVEL_C    },    // !ft             - flag c (SuperAdmin+)
}

new 
gCmdPointer[Commands];

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)

    
register_clcmd("say""HandleSay");
    
register_clcmd("say_team""HandleSay");

    for (new 
0Commandsi++)
    {
        if (
strlen(CommandsList[i][CMD_SRV]) > 0)
            
gCmdPointer[i] = get_cvar_pointer(CommandsList[i][CMD_SRV]);
    }
}

// Say Command Handler.
public HandleSay(client)
{
    new 
said[32];
    new 
param[32];
    new 
szMessage[charsmax(said) + charsmax(param) + 2];
   
    
read_argv(1szMessagecharsmax(szMessage));
    
argbreak(szMessagesaidcharsmax(param), paramcharsmax(param));
 
    for (new 
0Commandsi++)
    {
        if (
equali(said[1], CommandsList[i][CMD_INCHAT]))
        {
            if (!(
get_user_flags(client) & CommandsList[i][CMD_LEVEL]))
            {
                
client_print_color(clientprint_team_default"%s ^3Error^1: You don't have Access Level."PREFIX);
                break;
            }
            
CommandSelector(iclientparam); // // Pass the command / don't need to modify the loop itself.
            
return PLUGIN_HANDLED;
        }
    }
    return 
PLUGIN_CONTINUE;
}

// Say Command Handler (Selector).
CommandSelector(cmdclientparam[])
{
    switch(
cmd)
    {
        case 
RESTART_ROUND:    CmdRoundRestart (clientparam);
        case 
ALLTALK:        CmdTalk         (clientparam);
        case 
ROUND_TIME:        CmdRoundTime    (clientparam);
        case 
FREEZE_TIME:    CmdFreezeTime   (clientparam);
    }
}

// -------------Command Logic. ------------------------------
// Command: Round Restart.
CmdRoundRestart(clientparam[])
{
    new 
num 0;
    if (
CheckMinMax(clientparamnum01))
    {
        
set_pcvar_num(gCmdPointer[RESTART_ROUND], num);
        
PrintHasSetCmd(0clientRESTART_ROUNDfmt("%d"num));
    }
    return;
}
// Command: All Talk.
CmdTalk(clientparam[])
{
    new 
num 0;
    if (
CheckMinMax(clientparamnum01))
    {
        
set_pcvar_num(gCmdPointer[ALLTALK], num);
        
PrintHasSetCmd(0clientALLTALKfmt("%d"num));
    }
    return;
}
// Command: Round Time.
CmdRoundTime(clientparam[])
{
    new 
num;
    if (
CheckMinMax(clientparamnum19))
    {
        
//set_pcvar_float(gCmdPointer[ROUND_TIME], float(num));
        //PrintHasSetCmd(0, client, ROUND_TIME, fmt("%.1f", num));
        
set_cvar_float(gCmdPointer[ROUND_TIME], float(num));
        
PrintHasSetCmd(0clientROUND_TIMEfmt("%.2f"float(num)));
    }
    return;
}
// Command: Freeze Time.
CmdFreezeTime(clientparam[])
{
    new 
num;
    if (
CheckMinMax(clientparamnum060))
    {
        
//set_pcvar_float(gCmdPointer[FREEZE_TIME], float(num));
        
set_cvar_float(gCmdPointer[FREEZE_TIME], float(num));
        
PrintHasSetCmd(0clientFREEZE_TIMEfmt("%.2f"float(num)));
    }
    return;
}

PrintHasSetCmd(idclientcmdparam[])
{
    
client_print_color(idprint_team_default"%s ^3%s^1 has set ^4%s^1 to ^4%s^1."PREFIXclientCommandsList[cmd][CMD_NAME], param);
}

// Check Min to Max.
bool:CheckMinMax(clientparam[], &num, const min, const max)
{
    
num str_to_num(param);
    if (
num min || num max || !param[0])
    {
        
client_print_color(clientprint_team_default"%s Value must be between %d and %d"PREFIXminmax);
        return 
false;
    }

    return 
true;



lexzor 05-19-2023 16:59

Re: print wrong message value
 
this is how i would improve your code

PHP Code:

/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"

#define    PREFIX            "^4[Cmd]^1"

enum _:ALIVE_MODE
{
    
ALL,
    
ALIVE_ONLY,
    
DEAD_ONLY,
};

enum (+=1
{
    
CMD_VALUE_INT 0,
    
CMD_VALUE_FLOAT
}

enum _:CMD_STRUCT
{
    
CMD_NAME    [32],
    
CMD_INCHAT    [32],
    
CMD_SRV        [32],
    
CMD_USAGE    [128],
    
CMD_LEVEL,
    
CMD_TYPE
};


enum _:Commands
{
    
RESTART_ROUND,
    
ALLTALK,
    
ROUND_TIME,
    
FREEZE_TIME
}

new const 
CommandsList[Commands][CMD_STRUCT] = 
{
    {
"Restart Round",           "rr",           "sv_restart",           "",         ADMIN_KICK,         CMD_VALUE_INT       },    // !rr            - flag c (VIP+)
    
{"Alltalk",                 "alltalk",      "sv_alltalk",           "",         ADMIN_LEVEL_C,      CMD_VALUE_INT       },    // !alltalk     - flag c (SuperAdmin+),
    
{"RoundTime",               "rt",           "mp_roundtime",         "",         ADMIN_LEVEL_C,      CMD_VALUE_FLOAT     },    // !rt             - flag o (SuperAdmin)            
    
{"FreezeTime",              "ft",           "mp_freezetime",        "",         ADMIN_LEVEL_C,      CMD_VALUE_FLOAT     }    // !ft             - flag c (SuperAdmin+)
}

new 
gCmdPointer[Commands];

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)

    
register_clcmd("say""HandleSay");
    
register_clcmd("say_team""HandleSay");

    for (new 
0Commandsi++)
    {
        if (
strlen(CommandsList[i][CMD_SRV]) > 0)
        {
            
gCmdPointer[i] = get_cvar_pointer(CommandsList[i][CMD_SRV]);
        }
    }
}

// Say Command Handler.
public HandleSay(client)
{
    static 
said[32];
    static 
param[32];
    static 
szMessage[32]; //32 should be enough. it is better to use static because this variable will be often overwriten
   
    
read_argv(1szMessagecharsmax(szMessage));
    
argbreak(szMessagesaidcharsmax(param), paramcharsmax(param));
 
    for (new 
0Commandsi++)
    {
        if (
equali(said[1], CommandsList[i][CMD_INCHAT]))
        {
            if (!(
get_user_flags(client) & CommandsList[i][CMD_LEVEL]))
            {
                
client_print_color(clientprint_team_default"%s ^3Error^1: You don't have Access Level."PREFIX);
                break;
            }
            
            
CommandSelector(iclientparam); // // Pass the command / don't need to modify the loop itself.
            
return PLUGIN_HANDLED;
        }
    }
    return 
PLUGIN_CONTINUE;
}

// Command: Round Restart.
CommandSelector(cmd_idclientparam[])
{
    switch(
CommandsList[cmd_id][CMD_TYPE]) //we use cmd_type to know how we should set the value to the cvar pointer
    
{
        case 
CMD_VALUE_INT
        {
            
set_pcvar_num(gCmdPointer[cmd_id], str_to_num(param))
        }

        case 
CMD_VALUE_FLOAT:
        {
            
set_pcvar_float(gCmdPointer[cmd_id], str_to_float(param))
        }
    }

    
PrintHasSetCmd(clientcmd_idparam); //what is the purpose of passing to who to display the message? as i can see in your code, you pass this just once.
}

PrintHasSetCmd(clientcmdparam[])
{
    
client_print_color(0print_team_default"%s ^3%s^1 has set ^4%s^1 to ^4%s^1."PREFIXclientCommandsList[cmd][CMD_NAME], param);


also, you need to create a new CheckMinMax function that know how to reinterpret your param[] value from string to float/int/string

Fuck For Fun 05-19-2023 17:03

Re: print wrong message value
 
Quote:

Originally Posted by lexzor (Post 2804668)
this is how i would improve your code

PHP Code:

/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"

#define    PREFIX            "^4[Cmd]^1"

enum _:ALIVE_MODE
{
    
ALL,
    
ALIVE_ONLY,
    
DEAD_ONLY,
};

enum (+=1
{
    
CMD_VALUE_INT 0,
    
CMD_VALUE_FLOAT
}

enum _:CMD_STRUCT
{
    
CMD_NAME    [32],
    
CMD_INCHAT    [32],
    
CMD_SRV        [32],
    
CMD_USAGE    [128],
    
CMD_LEVEL,
    
CMD_TYPE
};


enum _:Commands
{
    
RESTART_ROUND,
    
ALLTALK,
    
ROUND_TIME,
    
FREEZE_TIME
}

new const 
CommandsList[Commands][CMD_STRUCT] = 
{
    {
"Restart Round",           "rr",           "sv_restart",           "",         ADMIN_KICK,         CMD_VALUE_INT       },    // !rr            - flag c (VIP+)
    
{"Alltalk",                 "alltalk",      "sv_alltalk",           "",         ADMIN_LEVEL_C,      CMD_VALUE_INT       },    // !alltalk     - flag c (SuperAdmin+),
    
{"RoundTime",               "rt",           "mp_roundtime",         "",         ADMIN_LEVEL_C,      CMD_VALUE_FLOAT     },    // !rt             - flag o (SuperAdmin)            
    
{"FreezeTime",              "ft",           "mp_freezetime",        "",         ADMIN_LEVEL_C,      CMD_VALUE_FLOAT     }    // !ft             - flag c (SuperAdmin+)
}

new 
gCmdPointer[Commands];

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)

    
register_clcmd("say""HandleSay");
    
register_clcmd("say_team""HandleSay");

    for (new 
0Commandsi++)
    {
        if (
strlen(CommandsList[i][CMD_SRV]) > 0)
        {
            
gCmdPointer[i] = get_cvar_pointer(CommandsList[i][CMD_SRV]);
        }
    }
}

// Say Command Handler.
public HandleSay(client)
{
    static 
said[32];
    static 
param[32];
    static 
szMessage[32]; //32 should be enough. it is better to use static because this variable will be often overwriten
   
    
read_argv(1szMessagecharsmax(szMessage));
    
argbreak(szMessagesaidcharsmax(param), paramcharsmax(param));
 
    for (new 
0Commandsi++)
    {
        if (
equali(said[1], CommandsList[i][CMD_INCHAT]))
        {
            if (!(
get_user_flags(client) & CommandsList[i][CMD_LEVEL]))
            {
                
client_print_color(clientprint_team_default"%s ^3Error^1: You don't have Access Level."PREFIX);
                break;
            }
            
            
CommandSelector(iclientparam); // // Pass the command / don't need to modify the loop itself.
            
return PLUGIN_HANDLED;
        }
    }
    return 
PLUGIN_CONTINUE;
}

// Command: Round Restart.
CommandSelector(cmd_idclientparam[])
{
    switch(
CommandsList[cmd_id][CMD_TYPE]) //we use cmd_type to know how we should set the value to the cvar pointer
    
{
        case 
CMD_VALUE_INT
        {
            
set_pcvar_num(gCmdPointer[cmd_id], str_to_num(param))
        }

        case 
CMD_VALUE_FLOAT:
        {
            
set_pcvar_float(gCmdPointer[cmd_id], str_to_float(param))
        }
    }

    
PrintHasSetCmd(clientcmd_idparam); //what is the purpose of passing to who to display the message? as i can see in your code, you pass this just once.
}

PrintHasSetCmd(clientcmdparam[])
{
    
client_print_color(0print_team_default"%s ^3%s^1 has set ^4%s^1 to ^4%s^1."PREFIXclientCommandsList[cmd][CMD_NAME], param);



so wish you goodluck
HTML Code:

enum _:ALIVE_MODE
{
        ALL,
        ALIVE_ONLY,
        DEAD_ONLY,
};

enum _:CMD_STRUCT
{
        CMD_NAME        [32],
        CMD_INCHAT        [32],
        CMD_SRV                [32],
        CMD_USAGE        [128],
        CMD_LEVEL
};

enum _:Commands
{
        RESTART_ROUND,
        ALLTALK,
        ROUND_TIME,
        FREEZE_TIME,
        PASSWORD,
        RESTART,
        YALLA,
        SLAY,
        SLAP,
        KICK,
        TEAM_T,
        TEAM_CT,
        TEAM_SPEC,
        FREEZE,
        REVIVE,
        HEALTH,
        ARMOR,
        TELEPORT,
        GODMODE,
        GRAVITY,
        NOCLIP,
        MAP,
        MMENU

};

new const CommandsList[Commands][CMD_STRUCT] =
{
        {"Restart Round",                "rr",                "sv_restart",        "",        ADMIN_KICK        },        // !rr                        - flag c (VIP+)
        {"Alltalk",                        "alltalk",        "sv_alltalk",        "",        ADMIN_LEVEL_C        },        // !alltalk        - flag c (SuperAdmin+),
        {"RoundTime",                        "rt",                "mp_roundtime",        "",        ADMIN_LEVEL_C        },        // !rt                        - flag o (SuperAdmin)                       
        {"FreezeTime",                        "ft",                "mp_freezetime","",        ADMIN_LEVEL_C        },        // !ft                        - flag c (SuperAdmin+)
        {"Password",                        "pass",                "sv_password",        "",        ADMIN_IMMUNITY                },        // !pass                - flag a (Owner)
        {"Restart Server",                "restart",        "",                "",        ADMIN_RESERVATION        },        // !restart        - flag b (Manager+)

        {"׳¨׳‘׳› ׳§׳—׳©",                "yalla",        "",                "",        ADMIN_LEVEL_C                },        // !yalla                - flag c (SuperAdmin+)

        {"Slay",                        "slay",                "",        "<^3target^1>",                                ADMIN_SLAY                        },        // !slay                - flag c (VIP+)
        {"Slap",                        "slap",                "",        "<^3target^1> <^3damage^1>",                ADMIN_SLAY                        },        // !slap                - flag c (VIP+)
        {"Kick",                        "kick",                "",        "<^3target^1> [^3^"reason^"^1]",        ADMIN_KICK                },        // !kick                - flag c (VIP+)
        {"Terrorist Team",                "t",                "",        "<^3@all/@ct/@admin/target^1>",        ADMIN_KICK                        },        // !t                        - flag c (VIP+)
        {"CT Team",                        "ct",                "",        "<^3@all/@t/@admin/target^1>",                ADMIN_KICK                        },        // !ct                        - flag c (VIP+)
        {"Spec Team",                        "spec",                "",        "<^3target^1>",                        ADMIN_RESERVATION        },        // !spec                - flag b (Manager+)
        {"Freeze",                        "freeze",        "",        "<^3@all/@t/@ct/target^1>",                ADMIN_LEVEL_C                },        // !freeze                - flag b (Manager+)
        {"Revive",                        "revive",        "",        "<^3@all/@t/@ct/target^1>",                ADMIN_LEVEL_C                },        // !revive                - flag c (SuperAdmin+)

        {"Health",                        "heal",                "",        "<^3@all/@t/@ct/@admin/target^1> <^3health^1>",                        ADMIN_KICK                        },        // !heal                - flag c (VIP+)
        {"Armor",                        "armor",        "",        "<^3@all/@t/@ct/@admin/target^1> <^3armor^1>",                                ADMIN_KICK                        },        // !armor                - flag c (VIP+)
        {"Teleport",                        "teleport",        "",        "<^3From:@all/@t/@ct/@admin/target^1> <^3To:target/origin:X Y Z^1>",        ADMIN_KICK                        },        // !teleport        - flag c (VIP+)
        {"GodMode",                        "godmode",        "",        "<^3@all/@t/@ct/@admin/target^1>",                                        ADMIN_KICK                        },        // !godmode        - flag c (VIP+)
        {"Gravity",                        "gravity",        "",        "<^3@all/@t/@ct/@admin/target^1> <^3gravity 1.0=normal^1>",                ADMIN_KICK                        },        // !gravity        - flag c (VIP+)
        {"Noclip",                        "noclip",        "",        "<^3@all/@t/@ct/@admin/target^1>",                                        ADMIN_KICK                        },        // !noclip                - flag c (VIP+)
        {"Map Change",                        "map",        "",        "",                        ADMIN_BAN        },        // !map                - flag c (ADMIN+)
        {"Map List",                        "mmenu",        "",        "",                ADMIN_BAN        },        // !mmenu        - flag c (ADMIN+)
};

PHP Code:

// Say Command Handler (Selector).
CommandSelector(cmdclientparam[])
{
    switch(
cmd)
    {
        case 
RESTART_ROUNDCmdRoundRestart (clientparam);
        case 
ALLTALK:       CmdTalk         (clientparam);
        case 
ROUND_TIME:    CmdRoundTime    (clientparam);
        case 
FREEZE_TIME:   CmdFreezeTime   (clientparam);
        case 
PASSWORD:      CmdPassword     (clientparam);
        case 
RESTART:       CmdRestart      (client);  
        case 
YALLA:         CmdYalla        (client);
        case 
SLAY:          CmdSlay         (clientparam);    
        case 
SLAP:          CmdSlap         (clientparam);
        case 
KICK:          CmdKick         (clientparam);
        case 
TEAM_T:        CmdTerrorist    (clientparam);
        case 
TEAM_CT:       CmdCT           (clientparam);
        case 
TEAM_SPEC:     CmdSpec         (clientparam);
        case 
FREEZE:        CmdFreeze       (clientparam);
        case 
REVIVE:        CmdRevive       (clientparam);
        case 
HEALTH:        CmdHealth       (clientparam);
        case 
ARMOR:            CmdArmor         (clientparam);
        case 
TELEPORT:        CmdTeleport        (clientparam);
        case 
GODMODE:        CmdGodmode        (clientparam);
        case 
GRAVITY:        CmdGravity        (clientparam);
        case 
NOCLIP:        CmdNoclip        (clientparam);
        case 
MAP:        CmdMapChange        (clientparam);
        case 
MMENU:        CmdMapMenu        (client);
    }




All times are GMT -4. The time now is 03:24.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.