Thread: Reset Score
View Single Post
happy_2012
Senior Member
Join Date: Aug 2012
Old 10-18-2015 , 11:18   Re: Reset Score
Reply With Quote #78

Quote:
Originally Posted by HamletEagle View Post
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_NAMEPLUGIN_VERSIONPLUGIN_AUTHOR);
    
    
register_cvar("reset_score_version"PLUGIN_VERSIONFCVAR_SERVER FCVAR_SPONLY);
    
set_cvar_string("reset_score_version"PLUGIN_VERSION);
    
    new 
IndexiMaxLoops sizeof(g_szClientCommands);
    for(
Index 0Index iMaxLoopsIndex++)
            
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(Indexprint_chat"Your score is already reset");
        return 
PLUGIN_HANDLED;
    }
    
    
set_user_frags(Index0);
    
cs_set_user_deaths(Index0);
    
    
UpdateClientScore(Index00);
    
    new 
szName[32];
    
get_user_name(IndexszNamecharsmax(szName));
    
    
client_print(0print_chat"%s has just reset his/her score");
    
    return 
PLUGIN_HANDLED;
}

UpdateClientScore(IndexiFragsiDeaths)
{
    
message_begin(MSG_ALLg_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/
__________________
Discord contacts:
I rarely look at private messages here, but I am very active on Discord!

Last edited by happy_2012; 10-18-2015 at 12:07.
happy_2012 is offline