1. you can define the needed access directly in register_clcmd, no need to check if user is admin in function
Quote:
Originally Posted by amxmodx.inc
/* Registers function which will be called from client console.
* Set FlagManager to 1 to make FlagManager always include this command
* Set FlagManager to 0 to make FlagManager never include this command
* Returns the command ID.
*/
native register_clcmd(const client_cmd[],const function[],flags=-1, const info[]="", FlagManager=-1);
|
2. you can just register all say commands and filter them inside a single function. see this code as an example:
PHP Code:
public plugin_init()
register_clcmd("say", "fwClCmdSay")
public fwClCmdSay(const iID)
{
new szTemp[1 + 1 + 7 + 1]; // first char will be " second char /
read_args(szTemp, charsmax(szTemp))
trim(szTemp)
remove_quotes(szTemp)
replace(szTemp, charsmax(szTemp), "/", "")
replace(szTemp, charsmax(szTemp), ".", "")
replace(szTemp, charsmax(szTemp), "!", "")
if (equali(szTemp, "restart") || equali(szTemp, "rr"))
{
fwConCmdRestart(iID)
return PLUGIN_HANDLED_MAIN;
}
else if (equali(szTemp, "warm") || equali(szTemp, "wrm"))
{
fwConCmdWarm(iID)
return PLUGIN_HANDLED_MAIN;
}
return PLUGIN_CONTINUE;
}
3. instead of looping through all player ids you can get them all filtered with a single native which is faster
Quote:
Originally Posted by amxmodx.inc
/* Sets indexes of players.
* Flags:
* "a" - don't collect dead players.
* "b" - don't collect alive players.
* "c" - skip bots.
* "d" - skip real players.
* "e" - match with team.
* "f" - match with part of name.
* "g" - ignore case sensitivity.
* "h" - skip HLTV.
* Example: Get all alive CTs: get_players(players,num,"ae","CT") */
native get_players(players[32], &num ,const flags[]="", const team[]="");
|
Usage example:
PHP Code:
new iCVarHUD = get_pcvar_num(g_iIDPCVarHUD), i, iIDsPlayers[32], iCountPlayers;
//client_print(0, print_chat, "[fwTaskShowHUD] C4: (%d)%s.", iIDsPlayers[i], szTemp)
if (iCVarHUD > 1)
{
// red = 0, green = 160, blue = 0, Float:x = -1.0, Float:y = 0.65,
// effects = 2, Float:fxtime = 6.0, Float:holdtime = 3.0,
// Float:fadeintime = 0.1, Float:fadeouttime = 1.5, bool:reliable = true
#if defined _dhudmessage_included
set_dhudmessage
(
255, 0, 0, -1.0, 0.9, 0, 0.0,
0.1 + BOMBMSG_INTERVAL1, 0.0, 0.0, false
)
#else
set_dhudmessage
(
255, 0, 0, -1.0, 0.9, 0, 0.0,
0.1 + BOMBMSG_INTERVAL1, 0.0, 0.0
)
#endif
}
else
set_hudmessage(255, 0, 0, -1.0, 0.9, 0, 0.0, 0.1 + BOMBMSG_INTERVAL1, 0.0, 0.0)
get_players(iIDsPlayers, iCountPlayers, "ec", "SPECTATOR")
for (i = 0; i < iCountPlayers; i++)
{
if (iCVarHUD > 1)
show_dhudmessage(iIDsPlayers[i], "C4: %s%s%.1f m%s", g_szName[0] ? g_szName : "", g_szName[0] ? "(" : "", fm_entity_range(g_iIDEntBomb, iIDsPlayers[i]) / 25.4, g_szName[0] ? ")" : "")
else
show_hudmessage(iIDsPlayers[i], "C4: %s%s%.1f m%s", g_szName[0] ? g_szName : "", g_szName[0] ? "(" : "", fm_entity_range(g_iIDEntBomb, iIDsPlayers[i]) / 25.4, g_szName[0] ? ")" : "")
}
4. instead of having 2 variables you can just have 1 and store the hp which should be set on the players
5. you should try using dhud since your message is displayed only once and not spammed. unlike default hud, it has auto resize and looks better. if you're using amxx <= 182 download the necessarry include file from here otherwise this step is not needed:
https://forums.alliedmods.net/attach...4&d=1583426083
Very good job overall for your first plugin. Congrats.
__________________