Raised This Month: $ Target: $400
 0% 

Resetscore does't work.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Ratonel
Member
Join Date: Jul 2012
Location: Romania
Old 07-13-2012 , 14:16   Resetscore does't work.
Reply With Quote #1

Hi, i've made a resetscore plugin and for some reason it does't work. It's for a friend a he said that only the messages apear; the score remains the same.

Here's the code:

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <fun>

new contor[32]
new 
pcvar_hmtimes
public plugin_init()
{
    
register_plugin("Reset Score""1.0""Whatever")
    
    
register_clcmd("say /resetscore""reset_score")
    
register_clcmd("say /rs""reset_score")    
    
register_clcmd("say_team /resetscore""reset_score")
    
register_clcmd("say_team /rs""reset_score")        
    
pcvar_hmtimes register_cvar("resetscore_max""2")

}
public 
reset_score(id)
{
    new 
killdead
    kill 
get_user_frags(id); 
    
dead get_user_deaths(id); 
    
    if(!
kill && !dead){
        if(
get_user_flags(id) & ADMIN_LEVEL_F){
            
cs_set_user_deaths(id0)
            
set_user_frags(id0)
            
cs_set_user_deaths(id0)
            
set_user_frags(id0)
            
client_print(idprint_chat"Tocmai ti-ai resetat scorul!"// you've just reseted your score
        
}
        else{
                if(
contor[id]<=get_pcvar_num(pcvar_hmtimes)){
                    
cs_set_user_deaths(id0)
                    
set_user_frags(id0)
                    
cs_set_user_deaths(id0)
                    
set_user_frags(id0)
                    
client_print(idprint_chat"Tocmai ti-ai resetat scorul!"// you've just reseted your score
                    
contor[id]++
                }
                else
                
client_print(idprint_chat"Nu iti mai poti reseta scorul!"// you can't reset your score anymore
            
}
    }
    else 
        
client_print(idprint_chat"Scorul tau este deja 0-0"//your score is already 0-0

For regular players it's only meant to work 2 times (the value of pcvar_hmtimes) and for those who have the flag "r" to work all the time.

P.S.: Sorry for any grammar mistakes or writing mistakes.

Last edited by Ratonel; 07-13-2012 at 14:19.
Ratonel is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 07-13-2012 , 14:58   Re: Resetscore does't work.
Reply With Quote #2

Instead of if( !dead && !kill ) you should check if( dead || kill ) aka if( dead != 0 || kill != 0 ).

Try this :
PHP Code:
#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>

#define m_iDeaths 444

new connor[33]
new 
pcvar_hmtimes

public plugin_init()
{
    
register_plugin("Reset Score""1.1""Whatever")
    
    
register_clcmd("say /resetscore""reset_score")
    
register_clcmd("say /rs""reset_score")    
    
register_clcmd("say_team /resetscore""reset_score")
    
register_clcmd("say_team /rs""reset_score")

    
pcvar_hmtimes register_cvar("resetscore_max""2")

}

public 
client_putinserverid )
{
    
connorid ] = 0
}

public 
reset_score(id)
{
    new 
frags get_user_fragsid )

    if( 
frags || get_pdata_int(idm_iDeaths) )
    {
        if( 
get_user_flags(id) & ADMIN_LEVEL_F || ++connor[id] < get_pcvar_num(pcvar_hmtimes) )
        {
            
set_pdata_int(idm_iDeaths0)
            
ExecuteHam(Ham_AddPointsid, -frags1)
            
client_print(idprint_chat"Tocmai ti-ai resetat scorul!"// you've just reseted your score
        
}
        else
        {
            
client_print(idprint_chat"Nu iti mai poti reseta scorul!"// you can't reset your score anymor
        
}
    }
    else 
    {
        
client_print(idprint_chat"Scorul tau este deja 0-0"//your score is already 0-0
    
}

If you want to keep old method, replace :

cs_set_user_deaths(id, 0)
set_user_frags(id, 0)
cs_set_user_deaths(id, 0)
set_user_frags(id, 0)

with


set_user_frags(id, 0)
cs_set_user_deaths(id, 0) // make sure to place that one in 2nd position.
__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 07-13-2012 at 14:59.
ConnorMcLeod is offline
Ratonel
Member
Join Date: Jul 2012
Location: Romania
Old 07-14-2012 , 12:02   Re: Resetscore does't work.
Reply With Quote #3

I did't knew what was the problem because my friend haven't told me until today that the message shown was "your score is already 0-0" so I knew i had messed up that if.

Thanks for the alternative. I have a question about it:

PHP Code:
ExecuteHam(Ham_AddPointsid, -frags1
resets frags and deaths? I've never seen this method before. (I'm far from being a decent amxx scripter, but I would like to get there . We live and learn.)
Ratonel is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 07-14-2012 , 12:33   Re: Resetscore does't work.
Reply With Quote #4

This is HL code but i think cs code is the same :

Code:
void CBasePlayer::AddPoints( int score, BOOL bAllowNegativeScore )
{
	// Positive score always adds
	if ( score < 0 )
	{
		if ( !bAllowNegativeScore )
		{
			if ( pev->frags < 0 )		// Can't go more negative
				return;
			
			if ( -score > pev->frags )	// Will this go negative?
			{
				score = -pev->frags;		// Sum will be 0
			}
		}
	}

	pev->frags += score;

	MESSAGE_BEGIN( MSG_ALL, gmsgScoreInfo );
		WRITE_BYTE( ENTINDEX(edict()) );
		WRITE_SHORT( pev->frags );
		WRITE_SHORT( m_iDeaths );
		WRITE_SHORT( 0 );
		WRITE_SHORT( g_pGameRules->GetTeamIndex( m_szTeamName ) + 1 );
	MESSAGE_END();
}
Advantage on using this is that the message sent can be receives by any addon/plugin, that's not the case with the one sent by cs_set_user_deaths.
So, as you can see :
pev->frags += score;
There, score is equal to -frags, so frags + -frags = 0.
You we have previously set m_iDeaths to 0.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Ratonel
Member
Join Date: Jul 2012
Location: Romania
Old 07-14-2012 , 14:45   Re: Resetscore does't work.
Reply With Quote #5

Got it. Thank you very much
Ratonel 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 15:09.


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