Quote:
Originally Posted by HamletEagle
There is still room for improvement, like caching get_user_msgid("ScoreInfo"), because it won't change. static is misused in the command, new is more appropiate.
Btw, when using offsets you should use their real name. This is better for readability and helps the others to understand your code. When using real names we can search in HLSDK/CSSDK(if the offset is cs related) and see how it is used, thus understanding better what it does. For example const OFFSET_TEAMS should be named m_iTeam, OFFSET_DEATH should be m_iDeaths.
|
I saw a post of yours saying static is better for getting names, perhaps I misunderstood it, can you tell me what is the difference between static and new? Perhaps steam chat would be better than flooding off this thread?
Updated:
PHP Code:
/* ===========================================================================
-------------------
-*- Reset Score -*-
-------------------
(c) 2015 - Chilimax
Website: http://8bits-gaming.com
=========================================================================== */
#include < amxmodx >
#include < cstrike >
#include < fun >
#define PLUGIN_NAME "Reset Score"
#define PLUGIN_VERSION "1.0"
#define PLUGIN_AUTHOR "Chilimax"
new const g_szClientCommands[][] =
{
"say /rs", "say_team /rs",
"say /resetscore", "say_team /resetscore",
"say /restartscore", "say_team /restartscore"
}
new g_MsgScoreInfo;
public plugin_init()
{
register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR);
register_cvar("reset_score_version", PLUGIN_VERSION, FCVAR_SERVER | FCVAR_SPONLY);
set_cvar_string("reset_score_version", PLUGIN_VERSION);
new Index, iMaxLoops = sizeof(g_szClientCommands);
for(Index = 0; Index < iMaxLoops; Index++)
register_clcmd(g_szClientCommands[Index], "ClientCommand_ResetScore");
g_MsgScoreInfo = get_user_msgid("ScoreInfo");
}
public ClientCommand_ResetScore(Index)
{
if( !get_user_frags(Index) && !cs_get_user_deaths(Index) )
{
client_print(Index, print_chat, "Your score is already reset");
return PLUGIN_HANDLED;
}
set_user_frags(Index, 0);
cs_set_user_deaths(Index, 0);
UpdateClientScore(Index, 0, 0);
new szName[32];
get_user_name(Index, szName, charsmax(szName));
client_print(0, print_chat, "%s has just reset his/her score");
return PLUGIN_HANDLED;
}
UpdateClientScore(Index, iFrags, iDeaths)
{
message_begin(MSG_ALL, g_MsgScoreInfo);
write_byte(Index);
write_short(iFrags);
write_short(iDeaths);
write_short(0);
write_short(get_user_team(Index));
message_end();
}
Steam profile:
http://steamcommunity.com/id/zombies_win/
__________________