AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Help with sql plugin! (https://forums.alliedmods.net/showthread.php?t=131588)

VIDEN 07-06-2010 18:16

Help with sql plugin!
 
Hi

My friend did a plugin to me. It saves stats from the server, like kills, deaths, headshots and more to a database.

But i have a problem with it, when i but it on the server it creates tables in the database and starts with no errors but it saves no stats!

Code:

#include < amxmodx >
#include < csx >
#include < sqlx >

enum _:Stats
{
    STAT_KILLS = 0,
    STAT_DEATHS,
    STAT_HEADSHOTS,
    STAT_TEAMKILL,
    STAT_SHOTS,
    STAT_HITS,
    STAT_DAMAGE
};

new g_szSteamID[ 33 ][ 35 ];

new Handle:g_hSQLTuple;

public plugin_init( )
{
    register_plugin( "Toplist", "0.0.1", "Xellath" );
   
    PrepareDatabase( );
}

public client_authorized( iClient )
{
    if( !is_user_bot( iClient ) && !is_user_hltv( iClient ) )
    {
        get_user_authid( iClient, g_szSteamID[ iClient ], 34 );
    }
}

public client_disconnected( iClient )
{
    new iStats[ Stats + 1 ], szHits[ 8 ], szName[ 32 ], szQuery[ 512 ];
    get_stats( iClient, iStats, szHits, szName, 31 );
   
    formatex( szQuery, charsmax( szQuery ),\
        "REPLACE INTO player_stats ( steamid, nickname, kills, deaths, headshots, hits ) VALUES ( '%s', '%s', '%i', '%i', '%i', '%i' )",\
        g_szSteamID[ iClient ], szName, iStats[ STAT_KILLS ], iStats[ STAT_DEATHS ], iStats[ STAT_HEADSHOTS ], iStats[ STAT_HITS ]
        );
       
    SQL_ThreadQuery( g_hSQLTuple, "QueryHandler", szQuery );
}

PrepareDatabase( )
{
    g_hSQLTuple = SQL_MakeDbTuple("127.0.0.1", "root", "xxx", "amx");
   
    new szQuery[ 512 ];
    formatex( szQuery, charsmax( szQuery ),\
        "CREATE TABLE IF NOT EXISTS player_stats ( steamid varchar( 35 ), nickname varchar( 32 ), kills int( 10 ), deaths int( 10 ), headshots int( 10 ), hits int( 10 ) );"
        );
   
    SQL_ThreadQuery( g_hSQLTuple, "QueryHandler", szQuery );
}

public QueryHandler( iFailState, Handle:hQuery, szError[ ], iError, szData[ ], iDataSize, Float:fQueueTime )
{
    if( iFailState == TQUERY_CONNECT_FAILED )
    {
        set_fail_state( "SQL: Connection failed." );
    }
    else if( iFailState == TQUERY_QUERY_FAILED )
    {
        log_amx( "SQL: Query failed. Error: %s (%i)", szError, iError );
    }
}

Very nice if some kind soul could help me. :)


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

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