View Single Post
lexzor
Veteran Member
Join Date: Nov 2020
Old 05-19-2023 , 16:07   Re: print wrong message value
Reply With Quote #7

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);

lexzor is offline