View Single Post
Fuck For Fun
Veteran Member
Join Date: Nov 2013
Old 05-19-2023 , 17:03   Re: print wrong message value
Reply With Quote #10

Quote:
Originally Posted by lexzor View Post
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);
    }

Fuck For Fun is offline
Send a message via Skype™ to Fuck For Fun