Raised This Month: $51 Target: $400
 12% 

Reset Score


Post New Thread Reply   
 
Thread Tools Display Modes
Amine Belokda
Senior Member
Join Date: Oct 2015
Location: ML_NOT_FOUND
Old 10-17-2015 , 15:25   Re: Reset Score
Reply With Quote #71

Nice Your Plugin
Amine Belokda is offline
Send a message via MSN to Amine Belokda
happy_2012
Senior Member
Join Date: Aug 2012
Old 10-17-2015 , 19:23   Re: Reset Score
Reply With Quote #72

How about this code/update?
PHP Code:
/* ===========================================================================
    
    -------------------
    -*- Reset Score -*-
    -------------------
    
    (c) 2015 - Chilimax
    Website: http://8bits-gaming.com
    
=========================================================================== */

#include < amxmodx >
#include < fakemeta >

#define PLUGIN_NAME        "Reset Score"
#define PLUGIN_VERSION    "1.0"
#define PLUGIN_AUTHOR    "Chilimax"

const OFFSET_TEAMS 114;
const 
OFFSET_DEATH 444;
const 
OFFSET_LINUX 5;

new const 
g_szClientCommands[][] =
{
    
"say /rs""say_team /rs",
    
"say /resetscore""say_team /resetscore",
    
"say /restartscore""say_team /restartscore"
}

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++)
    {
        if( 
g_szClientCommands[Index][0] )
            
register_clcmd(g_szClientCommands[Index], "ClientCommand_ResetScore");
    }
}

public 
ClientCommand_ResetScore(Index)
{
    if( !
fm_get_user_frags(Index) && !fm_get_user_deaths(Index) )
    {
        
client_print(Indexprint_chat"Your score is already reset");
        return 
PLUGIN_HANDLED;
    }
    
    
fm_set_user_frags(Index0);
    
fm_set_user_deaths(Index0);
    
    
UpdateClientScore(Index00);
    
    static 
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_ALLget_user_msgid("ScoreInfo"));
    
write_byte(Index);
    
write_short(iFrags);
    
write_short(iDeaths);
    
write_short(0);
    
write_short(fm_get_user_team(Index));
    
message_end();    
}

stock fm_get_user_frags(Index)
{
    return 
pev(Indexpev_frags);
}

stock fm_get_user_deaths(Index)
{
    return 
get_pdata_int(IndexOFFSET_DEATHOFFSET_LINUX);
}

stock fm_get_user_team(Index)
{
    return 
get_pdata_int(IndexOFFSET_TEAMSOFFSET_LINUX);
}

stock fm_set_user_frags(IndexiFrags)
{
    
set_pev(Indexpev_fragsiFrags);
}

stock fm_set_user_deaths(IndexiDeaths)
{
    
set_pdata_int(IndexOFFSET_DEATHiDeathsOFFSET_LINUX);

__________________
Discord contacts:
I rarely look at private messages here, but I am very active on Discord!
happy_2012 is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 10-18-2015 , 04:46   Re: Reset Score
Reply With Quote #73

That would be worth to be trashed right away, horrible in many ways. You have been told already to not not use any fm_ stocks which are slower than original function in modules.
__________________
Arkshine is offline
happy_2012
Senior Member
Join Date: Aug 2012
Old 10-18-2015 , 07:04   Re: Reset Score
Reply With Quote #74

Quote:
Originally Posted by Arkshine View Post
That would be worth to be trashed right away, horrible in many ways. You have been told already to not not use any fm_ stocks which are slower than original function in modules.
Have a look at zp4.3 it has a lot of fakemeta_util stocks, and it is approved? Apparently it has its own forum?
__________________
Discord contacts:
I rarely look at private messages here, but I am very active on Discord!
happy_2012 is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 10-18-2015 , 07:32   Re: Reset Score
Reply With Quote #75

It doesn't matter much what others plugins do, if you don't understand what you're doing/saying, you got a problem. Looks like you have the Fakemeta syndrome which happened to hit everyone not that far ago. This might help you to understand better: https://forums.alliedmods.net/showthread.php?t=88792.
__________________
Arkshine is offline
happy_2012
Senior Member
Join Date: Aug 2012
Old 10-18-2015 , 08:24   Re: Reset Score
Reply With Quote #76

I got it now
Thank you mate!

How about this one now?
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"
}

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++)
    {
        if( 
g_szClientCommands[Index][0] )
            
register_clcmd(g_szClientCommands[Index], "ClientCommand_ResetScore");
    }
}

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);
    
    static 
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_ALLget_user_msgid("ScoreInfo"));
    
write_byte(Index);
    
write_short(iFrags);
    
write_short(iDeaths);
    
write_short(0);
    
write_short(get_user_team(Index));
    
message_end();    

__________________
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 08:25. Reason: Code update.
happy_2012 is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 10-18-2015 , 09:14   Re: Reset Score
Reply With Quote #77

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.
__________________
HamletEagle is offline
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
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 10-18-2015 , 11:43   Re: Reset Score
Reply With Quote #79

I don't remember posting such thing, could you link to it ? I can PM you my steamid if you want, but there is not point to keep such discussions only for us, posting in the forum help other members too. Doesn't matter for what you are using the variables, it only matter to choose the right keyword in the right place(so saying that static is better for retrieving names is irelevant).
There is a tutorial about static variables by Hawk, but I would not recommed it because it does not explain when to use it and why.

Short version: static should be used in places that will be called a lot of times(and this is only the case of per frame forwards, like PreThink, CmdStart, AddToFullPack, etc) or on big arrays, to initialize them only one time, so to save some memory(notice the word big). Using it in places like connect, commands, init, spawn or sth like that is not needed. Initializing variables is fine, it only start to matter in the situations described above.
__________________

Last edited by HamletEagle; 10-18-2015 at 11:45.
HamletEagle is offline
happy_2012
Senior Member
Join Date: Aug 2012
Old 10-18-2015 , 11:46   Re: Reset Score
Reply With Quote #80

Quote:
Originally Posted by HamletEagle View Post
I don't remember posting such thing, could you link to it ? I can PM you my steamid if you want, but there is not point to keep such discussions only for us, posting in the forum help other members too. Doesn't matter for what you are using the variables, it only matter to choose the right keyword in the right place(so saying that static is better for retrieving names is irelevant).
There is a tutorial about static variables by Hawk, but I would not recommed it because it does not explain when to use it and why.

Short version: static should be used in places that will be called a lot of times(and this is only the case of per frame forwards, like PreThink, CmdStart, AddToFullPack, etc) or on big arrays, to initialize them only one time, so to save some memory(notice the word big). Using it in places like connect, commands, init, spawn or sth like that is not needed. Initializing variables is fine, it only start to matter in the situations described above.
Yea alright, I got it!
__________________
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:04.
happy_2012 is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 17:17.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode