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

Help with death count


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
siriusmd99
Veteran Member
Join Date: Oct 2013
Location: Republic of Moldova
Old 07-15-2015 , 07:24   Help with death count
Reply With Quote #1

Hello . I want to make csstats not count deaths if user is terrorist.
I can't use csx extended to make deaths= deaths - 1 because when i put on server it crashes.
So is there any way to do this with amxx. I mean not to edit deaths in amxx but to block csstats from doing that.

I tried with ham_round_respawn(player) and it works , it doesnt count death for victim but it also doesnt count frag for attacker.
I want attacker's frag to be added but it doesnt count both.

So i was thinking logicaly to block csstats from adding death.
In csx sourcecode i found that it doesnt add stats if user is bot (if csstats_bot = 0 , or something like this) and i searched for is_user_bot in amx source codeand i found :
HTML Code:
static cell AMX_NATIVE_CALL is_user_bot(AMX *amx, cell *params) /* 1 param */
{
	int index = params[1];
	
	if (index < 1 || index > gpGlobals->maxClients)
		return 0;
	
	return (GET_PLAYER_POINTER_I(index)->IsBot() ? 1 : 0);
}

So if id <1 or >32 it should return bot and not count death.
And i tried this :

HTML Code:
public ham_PlayerKilled(victim, attacker, corpse)
{
     
			victim=-1;
            		
}
Set victim id to -1 but it doesnt work . I don't now if its possible to change victim id.
Maybe there is a way to block for some time native actions on player . I'm confused , please help.
I have searched all internet and nothing found.
Don't remind me of csx_extended please. Tried , server crashes.
siriusmd99 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-15-2015 , 12:22   Re: Help with death count
Reply With Quote #2

It would be easier to make a separate stats system that works exactly as you want. I recommend using SQL to make your top15 easier and efficient. If you can, list your requirements and I can put it together when I get some type.
__________________
Bugsy is offline
siriusmd99
Veteran Member
Join Date: Oct 2013
Location: Republic of Moldova
Old 07-15-2015 , 13:05   Re: Help with death count
Reply With Quote #3

Quote:
Originally Posted by Bugsy View Post
It would be easier to make a separate stats system that works exactly as you want. I recommend using SQL to make your top15 easier and efficient. If you can, list your requirements and I can put it together when I get some type.
I want stats only with kills and deaths. And commands /top15 , /stats, /rankstats.

Just show me how to add, extract kills and deaths for players with sql or nvault (nvault better but i think impossible to store 2 keys : deaths and kills ) and how to sort both for top players.
siriusmd99 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-16-2015 , 19:06   Re: Help with death count
Reply With Quote #4

PHP Code:

#include <amxmodx>
#include <cstrike>
#include <sqlx>

//  Uncomment the below to enable real-time stats which will be less efficient because 2 SQL transactions
//  will occur for each kill. Leaving this commented will make kills and deaths save to the database when
//  the player disconnects or at map change.
//#define REALTIMESTATS

new const Version[] = "0.1";

const 
MAXPLAYERS 32;
new const 
SQLSTATS_DATABASE[] = "sqlstats";
new const 
SQLSTATS_TABLE[] = "tblStats";

enum PlayerInfo
{
    
PlayerName33 ],
    
PlayerSteamID34 ],
    
PlayerKills,
    
PlayerDeaths,
    
bool:IsBot
}
new 
g_piPlayerInfoMAXPLAYERS ][ PlayerInfo ];

enum QueryTypes
{
    
QryLoad 5,
    
QryStats,
    
QryTop15
}

new 
Handle:g_SQLTuple g_szQueryCache512 ] , g_QryData];

public 
plugin_init() 
{
    
register_plugin"SQL Stats" Version "bugsy" );
    
    
register_event"DeathMsg" "DeathMsg" "a" "1>0" );
    
    
register_clcmd"say /top15" "GetTop15" );
    
register_clcmd"say /stats" "GetStats" );
    
    
SQL_SetAffinity"sqlite" );
    
g_SQLTuple SQL_MakeDbTuple"" "" "" SQLSTATS_DATABASE );
    
    
formatexg_szQueryCachecharsmaxg_szQueryCache ) , "CREATE TABLE IF NOT EXISTS %s (SteamID VARCHAR(34) NOT NULL, PlayerName VARCHAR(32), Kills INT(7), Deaths INT(7), PRIMARY KEY (SteamID));" SQLSTATS_TABLE );
    
SQL_ThreadQueryg_SQLTuple "CreateTableHandle" g_szQueryCache );
}

public 
plugin_end()
{
    
SQL_FreeHandleg_SQLTuple );
}

public 
client_authorizedid )
{
    if ( ( 
g_piPlayerInfoid ][ IsBot ] = bool:!!is_user_botid ) ) == false )
    {
        
get_user_authidid g_piPlayerInfoid ][ PlayerSteamID ] , charsmaxg_piPlayerInfo[][ PlayerSteamID ] ) );
        
get_user_nameid g_piPlayerInfoid ][ PlayerName ] , charsmaxg_piPlayerInfo[][ PlayerName ] ) );
        
        
g_QryData] = _:QryLoad;
        
g_QryData] = id;
        
        
g_piPlayerInfoid ][ PlayerKills ] = 0;
        
g_piPlayerInfoid ][ PlayerDeaths ] = 0;
        
        
formatexg_szQueryCachecharsmaxg_szQueryCache ) , "SELECT Kills,Deaths FROM %s WHERE SteamID=^"%s^";" SQLSTATS_TABLE g_piPlayerInfoid ][ PlayerSteamID ] );
        
SQL_ThreadQueryg_SQLTuple "QueryHandle" g_szQueryCache g_QryData sizeofg_QryData ) );
    }
}

#if !defined SQLSTATS_REALTIME 
public client_disconnectid )
{
    if ( !
g_piPlayerInfoid ][ IsBot ] )
    {
        
formatexg_szQueryCachecharsmaxg_szQueryCache ) , "REPLACE INTO %s (SteamID,PlayerName,Kills,Deaths) VALUES (^"%s^",^"%s^",%d,%d);" 
                                            
SQLSTATS_TABLE ,
                                            
g_piPlayerInfoid ][ PlayerSteamID ] ,
                                            
g_piPlayerInfoid ][ PlayerName ] ,
                                            
g_piPlayerInfoid ][ PlayerKills ] ,
                                            
g_piPlayerInfoid ][ PlayerDeaths ] );
                                              
        
SQL_ThreadQueryg_SQLTuple "SetHandle" g_szQueryCache );
    }
}
#endif

public DeathMsg()
{
    new 
iKiller iVictim CsTeams:iVictimTeam;
    
    
iKiller read_data);
    
iVictim read_data);
    
    if ( 
cs_get_user_teamiKiller ) != ( iVictimTeam cs_get_user_teamiVictim ) ) )
    {
        
g_piPlayerInfoiKiller ][ PlayerKills ]++;
        
        if ( 
iVictimTeam != CS_TEAM_T )
            
g_piPlayerInfoiVictim ][ PlayerDeaths ]++;
        
        
#if defined REALTIMESTATS 
        
new iPlayer];
        
        
iPlayer] = iKiller;
        
iPlayer] = iVictim;
        for ( new 
i++ )
        {
            if ( !
g_piPlayerInfo][ IsBot ] )
            {
                
formatexg_szQueryCachecharsmaxg_szQueryCache ) , "REPLACE INTO %s (SteamID,PlayerName,Kills,Deaths) VALUES (^"%s^",^"%s^",%d,%d);" 
                                                    
SQLSTATS_TABLE ,
                                                    
g_piPlayerInfoiPlayer] ][ PlayerSteamID ] ,
                                                    
g_piPlayerInfoiPlayer] ][ PlayerName ] ,
                                                    
g_piPlayerInfoiPlayer] ][ PlayerKills ] ,
                                                    
g_piPlayerInfoiPlayer] ][ PlayerDeaths ] );
                                                      
                
SQL_ThreadQueryg_SQLTuple "SetHandle" g_szQueryCache );
            }
        }
        
#endif
    
}
}

public 
GetTop15id )
{
    
g_QryData] = _:QryTop15;
    
g_QryData] = id;
    
    
formatexg_szQueryCache charsmaxg_szQueryCache ) , "SELECT PlayerName, (Kills-Deaths) As NetKills FROM %s ORDER BY NetKills DESC LIMIT 15;" SQLSTATS_TABLE );
    
SQL_ThreadQueryg_SQLTuple "QueryHandle" g_szQueryCache g_QryData sizeofg_QryData ) );
}

public 
GetStatsid )
{
    
g_QryData] = _:QryStats;
    
g_QryData] = id;
    
    
formatexg_szQueryCache charsmaxg_szQueryCache ) , "SELECT p1.Kills,p1.Deaths,(SELECT Count(*) FROM %s) AS TotalCount,(SELECT Count(*) FROM %s AS p2 WHERE (p2.Kills-p2.Deaths) > (p1.Kills-p1.Deaths)) AS KillRank \
                                FROM %s AS p1 \
                                WHERE SteamID=^"
%s^";" SQLSTATS_TABLE SQLSTATS_TABLE SQLSTATS_TABLE g_piPlayerInfoid ][ PlayerSteamID ] );
    
SQL_ThreadQueryg_SQLTuple "QueryHandle" g_szQueryCache g_QryData sizeofg_QryData ) );
}

public 
CreateTableHandleFailState Handle:Query Error[] , Errcode Data[] , DataSize )
{
    if( 
FailState == TQUERY_CONNECT_FAILED )
        return 
set_fail_state"Could not connect to SQL database." );
    else if( 
FailState == TQUERY_QUERY_FAILED )
        return 
set_fail_state"Query failed." );
   
    if( 
Errcode )
        return 
log_amx("Error on query: %s",Error);
    
    return 
PLUGIN_CONTINUE;
}

public 
SetHandleFailState Handle:Query Error[] , Errcode Data[] , DataSize )
{
    if( 
FailState == TQUERY_CONNECT_FAILED )
        return 
set_fail_state"Could not connect to SQL database." );
    else if( 
FailState == TQUERY_QUERY_FAILED )
        return 
set_fail_state"Query failed." );
    
    if( 
Errcode )
        return 
log_amx"Error on query: %s" Error );
   
    return 
PLUGIN_CONTINUE;
}

public 
QueryHandleFailState Handle:Query Error[] , Errcode Data[] , DataSize )
{
    if( 
FailState == TQUERY_CONNECT_FAILED )
        return 
set_fail_state("Could not connect to SQL database." );
    else if( 
FailState == TQUERY_QUERY_FAILED )
        return 
set_fail_state"Query failed." );
    
    if( 
Errcode )
        return 
log_amx("Error on query: %s",Error);
    
    new 
iRank iKills iDeaths szName33 ] , szHTML1000 ] , iHTMLPos;
    
    switch ( 
Data] )    
    {
        case 
QryLoad:
        {
            if ( 
SQL_NumResultsQuery ) )
            {
                
g_piPlayerInfoData] ][ PlayerKills ] = SQL_ReadResultQuery );
                
g_piPlayerInfoData] ][ PlayerDeaths ] = SQL_ReadResultQuery );
            }
        }
        case 
QryStats:
        {
            if ( 
SQL_NumResultsQuery ) )
            {
                
client_printData] , print_chat "* Rank %d of %d - %d Kills and %d Deaths" SQL_ReadResultQuery ) + SQL_ReadResultQuery ) , SQL_ReadResultQuery ) , SQL_ReadResultQuery ) )
            }    
        }
        case 
QryTop15:
        {
            if ( 
SQL_NumResultsQuery ) )
            {
                
iHTMLPos copyszHTMLiHTMLPos ] , charsmaxszHTML ) , "<html><body bgcolor=^"black^"><table style=^"color:white^">><th><b>Rank</b></th><th><b>Name</b></th><th><b>Net Kills</b></th>" );
                
                while ( 
SQL_MoreResultsQuery ) )
                {
                    
SQL_ReadResultQuery szName charsmaxszName ) );
                    
iKills SQL_ReadResultQuery );

                    
iHTMLPos += formatexszHTMLiHTMLPos ] , charsmaxszHTML ) - iHTMLPos "<tr><td><center>%d</center></td><td><center>%s</center></td><td><center>%d</center></td></tr>" , ++iRank szName iKills iDeaths );
                    
                    
SQL_NextRowQuery );
                }
                
                
copyszHTMLiHTMLPos ] , charsmaxszHTML ) - iHTMLPos "</tr></table></body></html>" );
                
show_motdData] , szHTML );
            }
        }
    }
    
    return 
PLUGIN_CONTINUE;

__________________

Last edited by Bugsy; 07-16-2015 at 19:48.
Bugsy is offline
siriusmd99
Veteran Member
Join Date: Oct 2013
Location: Republic of Moldova
Old 07-17-2015 , 04:46   Re: Help with death count
Reply With Quote #5

Thanks, but it calculates rank by steamid? I don't want by steamid because some players have fake steam and it can be changed and they will loose their rank.
siriusmd99 is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 07-17-2015 , 05:23   Re: Help with death count
Reply With Quote #6

No no steam stuffs here. To change the param you can use HamSetParam function(or how it is called).
__________________

Last edited by HamletEagle; 07-17-2015 at 05:24.
HamletEagle is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-17-2015 , 08:36   Re: Help with death count
Reply With Quote #7

It doesn't 'calculate' by steamid, but that is used as the users database primary key. Are you running a non steam server?

Hamlet.Eagle... What?? Lol
__________________
Bugsy is offline
siriusmd99
Veteran Member
Join Date: Oct 2013
Location: Republic of Moldova
Old 07-17-2015 , 09:33   Re: Help with death count
Reply With Quote #8

Compiles great , put on server and some errors . When i type /top15 it shows this :
[IMG]http://s1.************/yc762nw4f/hl_2015_07_17_16_31_39_215.png[/IMG]

Last edited by siriusmd99; 07-17-2015 at 09:33.
siriusmd99 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-17-2015 , 12:48   Re: Help with death count
Reply With Quote #9

Hmm I'll have to look. Net kills is calculated as kills-deaths.
__________________
Bugsy is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-17-2015 , 23:57   Re: Help with death count
Reply With Quote #10

It's working for me. I deleted my database to make it a fresh install. I played a game and killed 2 enemies then used /stats and /top15 and it did not reflect these kills. I disconnected and reconnected and the top15 and stats show me having 2 kills.
__________________

Last edited by Bugsy; 07-17-2015 at 23:58.
Bugsy 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 23:36.


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