Page 1 of 2

Plugin MYSQL inserare date.

Posted: 26 Mar 2020, 14:25
by The Kalu
Plugin Cerut: Statistici
Descriere (adica ce face el mai exact):
Serverul impune conditii strict HLDS/REHLDS?: HLDS
Ai cautat pluginul?(daca da, precizeaza cum): Nu
Necesita mod special?: Nu

Am nevoie de un plugin care sa insereze intr-un tabel urmatoarele date:

- steamid
- steam nickname
- frags
- deaths
- money
- last seen online (doar la deconectare sa ii insereze timpul)

SQL

Code: Select all

INSERT INTO player (steamid, nickname, frags, deaths, money, last_seen_online) VALUES ();
Doar o data inserarea, daca exista deja sa nu il mai adauge.

La fraguri, morti si bani sa memoreze cati face pe runda si la sfarsit de runda sa ii adauge in campul fraguri, morti si bani, adica sa ii adune deci va rula alta interogare in db separat doar pentru bani.
Aici sa bage la fiecare sfarsit de runda!

Code: Select all

UPDATE player SET frags =, deaths = , money = , last_seen_online =  WHERE steamdid;
Inca o chestie, daca are gag/mute sa nu ii adauge nimic timp de 1 zi ca si cum ar avea un fel de cooldown.

Multumesc!

Re: Plugin MYSQL inserare date.

Posted: 26 Mar 2020, 18:19
by EnTeR_
Banuiesc ca vrei sa faci ceva pe steam only, altfel nu o sa-ti mearga cum trebuie salvarea pe steamid. Anyway, testeaza asta si spune-mi daca sunt probleme.
| Afiseaza codul
#include <   amxmodx   >
#include <   cstrike   >
#include <    sqlx     >

#pragma tabsize 0;

new SQL_TABLE [ ] = "users_stats";

new iFrags [33], iDeaths [33], iMoney [33], iLastConnected [33] [32], PlayerAuthID [33] [32], PlayerName [33] [32],

Handle: iSqlTuple, SQLHost [32], SQLUser [32], SQLPassword [32], SQLDatabase [32], cSqlHost, cSqlUser,

cSqlPassword, cSqlDatabase, MaxPlayers;

public plugin_init (  )
{
    register_event ( "DeathMsg", "EventDeathMsg", "a" );
    
    register_logevent ( "leRoundEnd", 2, "1=Round_End" );

    cSqlHost = register_cvar ( "sql_host", "host" );
    
    cSqlUser = register_cvar ( "sql_user", "user" );
    
    cSqlPassword = register_cvar ( "sql_password", "pw" );
    
    cSqlDatabase = register_cvar ( "sql_database", "db" );

    MaxPlayers = get_maxplayers (  );
}

public plugin_cfg (  ) 
{
        get_pcvar_string ( cSqlHost, SQLHost, charsmax ( SQLHost ) );
    
        get_pcvar_string ( cSqlUser, SQLUser, charsmax ( SQLUser ) );
    
        get_pcvar_string ( cSqlPassword, SQLPassword, charsmax ( SQLPassword ) );
    
        get_pcvar_string ( cSqlDatabase, SQLDatabase, charsmax ( SQLDatabase ) );

        iSqlTuple = SQL_MakeDbTuple ( SQLHost, SQLUser, SQLPassword, SQLDatabase );
    
        static Query [10048], Len;
        
        Len += formatex ( Query [Len], charsmax ( Query ), "CREATE TABLE IF NOT EXISTS `%s`", SQL_TABLE );
    
        Len += formatex ( Query [Len], charsmax ( Query ) - Len, "(`steamid` varchar(32) NOT NULL, " );
    
        Len += formatex ( Query [Len], charsmax ( Query ) - Len, "`nickname` varchar(32) NOT NULL,");

        Len += formatex ( Query [Len], charsmax ( Query ) - Len, "`frags` int(11) NOT NULL,");

        Len += formatex ( Query [Len], charsmax ( Query ) - Len, "`deaths` int(11) NOT NULL,");

        Len += formatex ( Query [Len], charsmax ( Query ) - Len, "`money` int(11) NOT NULL,");

        Len += formatex ( Query [Len], charsmax ( Query ) - Len, "`last_seen_online` varchar(32) NOT NULL,");

        Len += formatex ( Query [Len], charsmax ( Query ) - Len, "`ID` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY)" );
    
        SQL_ThreadQuery ( iSqlTuple, "CreateTableThread", Query );
}

public CreateTableThread ( FailState, Handle:Query, Error [ ], Errcode, Data [ ], DataSize, Float:Queuetime ) 
{
    if ( FailState == TQUERY_CONNECT_FAILED || FailState == TQUERY_QUERY_FAILED )
    {
        set_fail_state ( "[SQL] Query Error" );
    }
    
    if ( Errcode )
    {
        log_amx ( "[SQL] Error: %s", Error );
    }
}

public LoadData ( id ) 
{
    static Query [10048], Data [1];
    
    Data [0] = id;
    
    formatex ( Query, charsmax ( Query ), "SELECT * FROM `%s` WHERE steamid = ^"%s^";", SQL_TABLE, PlayerAuthID [id] );
    
    SQL_ThreadQuery ( iSqlTuple, "QuerySelectData", Query, Data, 1 );
}

public QuerySelectData ( FailState, Handle: Query, Error [ ], Errcode, Data [ ], DataSize, Float: Queuetime ) 
{
    if ( FailState == TQUERY_CONNECT_FAILED || FailState == TQUERY_QUERY_FAILED )  
    {
        log_amx ( "[SQL] %s", Error );
        
        return;
    }
    else 
    {
        new id = Data [0];
        
        if ( SQL_NumRows ( Query ) < 1 ) 
        {
            new Query [256];
 
            formatex ( Query, charsmax ( Query ), "INSERT INTO `%s` (`steamid`,`nickname`,`frags`,`deaths`,`money`,`last_seen_online`) VALUES (^"%s^",^"%s^",^"0^",^"0^",^"0^",^"N/A^");", SQL_TABLE, PlayerAuthID [id], PlayerName [id] );

            SQL_ThreadQuery ( iSqlTuple, "QuerySetData", Query );

        }
        else
        {
            iFrags [id] = SQL_ReadResult ( Query, SQL_FieldNameToNum ( Query, "frags" ) );

            iDeaths [id] = SQL_ReadResult ( Query, SQL_FieldNameToNum ( Query, "deaths" ) );

            iMoney [id] = SQL_ReadResult ( Query, SQL_FieldNameToNum ( Query, "money" ) );

        }
    }
}

public SaveData ( id )
{
    new Query [256], sQuery [3000];
    
    formatex ( Query, charsmax ( Query ), "UPDATE `%s` SET ", SQL_TABLE );
    
        add ( sQuery, charsmax ( sQuery ), Query );

    formatex ( Query, charsmax ( Query ), "nickname = ^"%s^", ", PlayerName [id] );
        
        add ( sQuery, charsmax ( sQuery ), Query );

    formatex ( Query, charsmax ( Query ), "frags = ^"%i^", ", iFrags [id] );
        
        add ( sQuery, charsmax ( sQuery ), Query );

    formatex ( Query, charsmax ( Query ), "deaths = ^"%i^", ", iDeaths [id] );
        
        add ( sQuery, charsmax ( sQuery ), Query );

    formatex ( Query, charsmax ( Query ), "money = ^"%i^", ", iMoney [id] );
        
        add ( sQuery, charsmax ( sQuery ), Query );

    formatex ( Query, charsmax ( Query ), "last_seen_online = ^"%s^" WHERE steamid = ^"%s^";", iLastConnected [id], PlayerAuthID [id] );
    
        add ( sQuery, charsmax ( sQuery ), Query );
        
    SQL_ThreadQuery ( iSqlTuple, "QuerySetData", sQuery );
}


public QuerySetData ( FailState, Handle: Query, Error [ ], Errcode, Data [ ], DataSize, Float:Queuetime ) 
{
    if ( FailState == TQUERY_CONNECT_FAILED || FailState == TQUERY_QUERY_FAILED ) 
    {
        log_amx ( "[SQL] %s", Error );
        
        return;
    }
}

public client_putinserver ( id )
{
    get_user_name ( id, PlayerName [id], charsmax ( PlayerName [ ] ) );

    get_user_authid ( id, PlayerAuthID [id], charsmax ( PlayerAuthID [ ] ) );

    iFrags [id] = 0;

    iDeaths [id] = 0;

    iMoney [id] = 0;

    iLastConnected [id] = "N/A";
    
    LoadData ( id );
}


public client_disconnect ( id )
{
    iMoney [id] += cs_get_user_money ( id );

    new iTime [32];

    get_time ( "%m/%d/%Y - %H:%M:%S", iTime, charsmax ( iTime ) )
  
    copy ( iLastConnected [id], charsmax ( iLastConnected [ ] ), iTime )

    SaveData ( id );
}

public EventDeathMsg (  )
{
    new Killer = read_data ( 1 );
    
    new Victim = read_data ( 2 );
    
    if ( !is_user_alive ( Killer ) || Killer == Victim || get_user_team ( Killer ) == get_user_team ( Victim ) ) 

        return

    iFrags [Killer] ++;

    iDeaths [Victim] ++;
}

public leRoundEnd (  )
{
     for ( new i = 1; i <= MaxPlayers; i ++ )
    {
        if ( is_user_connected ( i ) )
        {
            iMoney  += cs_get_user_money ( i );

            SaveData ( i );
        }
    }
}

public plugin_end (  ) SQL_FreeHandle ( iSqlTuple );

Re: Plugin MYSQL inserare date.

Posted: 26 Mar 2020, 19:47
by The Kalu
EnTeR_ wrote:
26 Mar 2020, 18:19
Banuiesc ca vrei sa faci ceva pe steam only, altfel nu o sa-ti mearga cum trebuie salvarea pe steamid. Anyway, testeaza asta si spune-mi daca sunt probleme.
| Afiseaza codul
#include <   amxmodx   >
#include <   cstrike   >
#include <    sqlx     >

#pragma tabsize 0;

new SQL_TABLE [ ] = "users_stats";

new iFrags [33], iDeaths [33], iMoney [33], iLastConnected [33] [32], PlayerAuthID [33] [32], PlayerName [33] [32],

Handle: iSqlTuple, SQLHost [32], SQLUser [32], SQLPassword [32], SQLDatabase [32], cSqlHost, cSqlUser,

cSqlPassword, cSqlDatabase, MaxPlayers;

public plugin_init (  )
{
    register_event ( "DeathMsg", "EventDeathMsg", "a" );
    
    register_logevent ( "leRoundEnd", 2, "1=Round_End" );

    cSqlHost = register_cvar ( "sql_host", "host" );
    
    cSqlUser = register_cvar ( "sql_user", "user" );
    
    cSqlPassword = register_cvar ( "sql_password", "pw" );
    
    cSqlDatabase = register_cvar ( "sql_database", "db" );

    MaxPlayers = get_maxplayers (  );
}

public plugin_cfg (  ) 
{
        get_pcvar_string ( cSqlHost, SQLHost, charsmax ( SQLHost ) );
    
        get_pcvar_string ( cSqlUser, SQLUser, charsmax ( SQLUser ) );
    
        get_pcvar_string ( cSqlPassword, SQLPassword, charsmax ( SQLPassword ) );
    
        get_pcvar_string ( cSqlDatabase, SQLDatabase, charsmax ( SQLDatabase ) );

        iSqlTuple = SQL_MakeDbTuple ( SQLHost, SQLUser, SQLPassword, SQLDatabase );
    
        static Query [10048], Len;
        
        Len += formatex ( Query [Len], charsmax ( Query ), "CREATE TABLE IF NOT EXISTS `%s`", SQL_TABLE );
    
        Len += formatex ( Query [Len], charsmax ( Query ) - Len, "(`steamid` varchar(32) NOT NULL, " );
    
        Len += formatex ( Query [Len], charsmax ( Query ) - Len, "`nickname` varchar(32) NOT NULL,");

        Len += formatex ( Query [Len], charsmax ( Query ) - Len, "`frags` int(11) NOT NULL,");

        Len += formatex ( Query [Len], charsmax ( Query ) - Len, "`deaths` int(11) NOT NULL,");

        Len += formatex ( Query [Len], charsmax ( Query ) - Len, "`money` int(11) NOT NULL,");

        Len += formatex ( Query [Len], charsmax ( Query ) - Len, "`last_seen_online` varchar(32) NOT NULL,");

        Len += formatex ( Query [Len], charsmax ( Query ) - Len, "`ID` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY)" );
    
        SQL_ThreadQuery ( iSqlTuple, "CreateTableThread", Query );
}

public CreateTableThread ( FailState, Handle:Query, Error [ ], Errcode, Data [ ], DataSize, Float:Queuetime ) 
{
    if ( FailState == TQUERY_CONNECT_FAILED || FailState == TQUERY_QUERY_FAILED )
    {
        set_fail_state ( "[SQL] Query Error" );
    }
    
    if ( Errcode )
    {
        log_amx ( "[SQL] Error: %s", Error );
    }
}

public LoadData ( id ) 
{
    static Query [10048], Data [1];
    
    Data [0] = id;
    
    formatex ( Query, charsmax ( Query ), "SELECT * FROM `%s` WHERE steamid = ^"%s^";", SQL_TABLE, PlayerAuthID [id] );
    
    SQL_ThreadQuery ( iSqlTuple, "QuerySelectData", Query, Data, 1 );
}

public QuerySelectData ( FailState, Handle: Query, Error [ ], Errcode, Data [ ], DataSize, Float: Queuetime ) 
{
    if ( FailState == TQUERY_CONNECT_FAILED || FailState == TQUERY_QUERY_FAILED )  
    {
        log_amx ( "[SQL] %s", Error );
        
        return;
    }
    else 
    {
        new id = Data [0];
        
        if ( SQL_NumRows ( Query ) < 1 ) 
        {
            new Query [256];
 
            formatex ( Query, charsmax ( Query ), "INSERT INTO `%s` (`steamid`,`nickname`,`frags`,`deaths`,`money`,`last_seen_online`) VALUES (^"%s^",^"%s^",^"0^",^"0^",^"0^",^"N/A^");", SQL_TABLE, PlayerAuthID [id], PlayerName [id] );

            SQL_ThreadQuery ( iSqlTuple, "QuerySetData", Query );

        }
        else
        {
            iFrags [id] = SQL_ReadResult ( Query, SQL_FieldNameToNum ( Query, "frags" ) );

            iDeaths [id] = SQL_ReadResult ( Query, SQL_FieldNameToNum ( Query, "deaths" ) );

            iMoney [id] = SQL_ReadResult ( Query, SQL_FieldNameToNum ( Query, "money" ) );

        }
    }
}

public SaveData ( id )
{
    new Query [256], sQuery [3000];
    
    formatex ( Query, charsmax ( Query ), "UPDATE `%s` SET ", SQL_TABLE );
    
        add ( sQuery, charsmax ( sQuery ), Query );

    formatex ( Query, charsmax ( Query ), "nickname = ^"%s^", ", PlayerName [id] );
        
        add ( sQuery, charsmax ( sQuery ), Query );

    formatex ( Query, charsmax ( Query ), "frags = ^"%i^", ", iFrags [id] );
        
        add ( sQuery, charsmax ( sQuery ), Query );

    formatex ( Query, charsmax ( Query ), "deaths = ^"%i^", ", iDeaths [id] );
        
        add ( sQuery, charsmax ( sQuery ), Query );

    formatex ( Query, charsmax ( Query ), "money = ^"%i^", ", iMoney [id] );
        
        add ( sQuery, charsmax ( sQuery ), Query );

    formatex ( Query, charsmax ( Query ), "last_seen_online = ^"%s^" WHERE steamid = ^"%s^";", iLastConnected [id], PlayerAuthID [id] );
    
        add ( sQuery, charsmax ( sQuery ), Query );
        
    SQL_ThreadQuery ( iSqlTuple, "QuerySetData", sQuery );
}


public QuerySetData ( FailState, Handle: Query, Error [ ], Errcode, Data [ ], DataSize, Float:Queuetime ) 
{
    if ( FailState == TQUERY_CONNECT_FAILED || FailState == TQUERY_QUERY_FAILED ) 
    {
        log_amx ( "[SQL] %s", Error );
        
        return;
    }
}

public client_putinserver ( id )
{
    get_user_name ( id, PlayerName [id], charsmax ( PlayerName [ ] ) );

    get_user_authid ( id, PlayerAuthID [id], charsmax ( PlayerAuthID [ ] ) );

    iFrags [id] = 0;

    iDeaths [id] = 0;

    iMoney [id] = 0;

    iLastConnected [id] = "N/A";
    
    LoadData ( id );
}


public client_disconnect ( id )
{
    iMoney [id] += cs_get_user_money ( id );

    new iTime [32];

    get_time ( "%m/%d/%Y - %H:%M:%S", iTime, charsmax ( iTime ) )
  
    copy ( iLastConnected [id], charsmax ( iLastConnected [ ] ), iTime )

    SaveData ( id );
}

public EventDeathMsg (  )
{
    new Killer = read_data ( 1 );
    
    new Victim = read_data ( 2 );
    
    if ( !is_user_alive ( Killer ) || Killer == Victim || get_user_team ( Killer ) == get_user_team ( Victim ) ) 

        return

    iFrags [Killer] ++;

    iDeaths [Victim] ++;
}

public leRoundEnd (  )
{
     for ( new i = 1; i <= MaxPlayers; i ++ )
    {
        if ( is_user_connected ( i ) )
        {
            iMoney  += cs_get_user_money ( i );

            SaveData ( i );
        }
    }
}

public plugin_end (  ) SQL_FreeHandle ( iSqlTuple );


Multumesc de raspuns si solutie, totusi observ ca compilerul de la freakz nu mai exista.Cu ce il pot compila?

Re: Plugin MYSQL inserare date.

Posted: 26 Mar 2020, 20:28
by EnTeR_
The Kalu wrote:
26 Mar 2020, 19:47
EnTeR_ wrote:
26 Mar 2020, 18:19
Banuiesc ca vrei sa faci ceva pe steam only, altfel nu o sa-ti mearga cum trebuie salvarea pe steamid. Anyway, testeaza asta si spune-mi daca sunt probleme.
| Afiseaza codul
#include <   amxmodx   >
#include <   cstrike   >
#include <    sqlx     >

#pragma tabsize 0;

new SQL_TABLE [ ] = "users_stats";

new iFrags [33], iDeaths [33], iMoney [33], iLastConnected [33] [32], PlayerAuthID [33] [32], PlayerName [33] [32],

Handle: iSqlTuple, SQLHost [32], SQLUser [32], SQLPassword [32], SQLDatabase [32], cSqlHost, cSqlUser,

cSqlPassword, cSqlDatabase, MaxPlayers;

public plugin_init (  )
{
    register_event ( "DeathMsg", "EventDeathMsg", "a" );
    
    register_logevent ( "leRoundEnd", 2, "1=Round_End" );

    cSqlHost = register_cvar ( "sql_host", "host" );
    
    cSqlUser = register_cvar ( "sql_user", "user" );
    
    cSqlPassword = register_cvar ( "sql_password", "pw" );
    
    cSqlDatabase = register_cvar ( "sql_database", "db" );

    MaxPlayers = get_maxplayers (  );
}

public plugin_cfg (  ) 
{
        get_pcvar_string ( cSqlHost, SQLHost, charsmax ( SQLHost ) );
    
        get_pcvar_string ( cSqlUser, SQLUser, charsmax ( SQLUser ) );
    
        get_pcvar_string ( cSqlPassword, SQLPassword, charsmax ( SQLPassword ) );
    
        get_pcvar_string ( cSqlDatabase, SQLDatabase, charsmax ( SQLDatabase ) );

        iSqlTuple = SQL_MakeDbTuple ( SQLHost, SQLUser, SQLPassword, SQLDatabase );
    
        static Query [10048], Len;
        
        Len += formatex ( Query [Len], charsmax ( Query ), "CREATE TABLE IF NOT EXISTS `%s`", SQL_TABLE );
    
        Len += formatex ( Query [Len], charsmax ( Query ) - Len, "(`steamid` varchar(32) NOT NULL, " );
    
        Len += formatex ( Query [Len], charsmax ( Query ) - Len, "`nickname` varchar(32) NOT NULL,");

        Len += formatex ( Query [Len], charsmax ( Query ) - Len, "`frags` int(11) NOT NULL,");

        Len += formatex ( Query [Len], charsmax ( Query ) - Len, "`deaths` int(11) NOT NULL,");

        Len += formatex ( Query [Len], charsmax ( Query ) - Len, "`money` int(11) NOT NULL,");

        Len += formatex ( Query [Len], charsmax ( Query ) - Len, "`last_seen_online` varchar(32) NOT NULL,");

        Len += formatex ( Query [Len], charsmax ( Query ) - Len, "`ID` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY)" );
    
        SQL_ThreadQuery ( iSqlTuple, "CreateTableThread", Query );
}

public CreateTableThread ( FailState, Handle:Query, Error [ ], Errcode, Data [ ], DataSize, Float:Queuetime ) 
{
    if ( FailState == TQUERY_CONNECT_FAILED || FailState == TQUERY_QUERY_FAILED )
    {
        set_fail_state ( "[SQL] Query Error" );
    }
    
    if ( Errcode )
    {
        log_amx ( "[SQL] Error: %s", Error );
    }
}

public LoadData ( id ) 
{
    static Query [10048], Data [1];
    
    Data [0] = id;
    
    formatex ( Query, charsmax ( Query ), "SELECT * FROM `%s` WHERE steamid = ^"%s^";", SQL_TABLE, PlayerAuthID [id] );
    
    SQL_ThreadQuery ( iSqlTuple, "QuerySelectData", Query, Data, 1 );
}

public QuerySelectData ( FailState, Handle: Query, Error [ ], Errcode, Data [ ], DataSize, Float: Queuetime ) 
{
    if ( FailState == TQUERY_CONNECT_FAILED || FailState == TQUERY_QUERY_FAILED )  
    {
        log_amx ( "[SQL] %s", Error );
        
        return;
    }
    else 
    {
        new id = Data [0];
        
        if ( SQL_NumRows ( Query ) < 1 ) 
        {
            new Query [256];
 
            formatex ( Query, charsmax ( Query ), "INSERT INTO `%s` (`steamid`,`nickname`,`frags`,`deaths`,`money`,`last_seen_online`) VALUES (^"%s^",^"%s^",^"0^",^"0^",^"0^",^"N/A^");", SQL_TABLE, PlayerAuthID [id], PlayerName [id] );

            SQL_ThreadQuery ( iSqlTuple, "QuerySetData", Query );

        }
        else
        {
            iFrags [id] = SQL_ReadResult ( Query, SQL_FieldNameToNum ( Query, "frags" ) );

            iDeaths [id] = SQL_ReadResult ( Query, SQL_FieldNameToNum ( Query, "deaths" ) );

            iMoney [id] = SQL_ReadResult ( Query, SQL_FieldNameToNum ( Query, "money" ) );

        }
    }
}

public SaveData ( id )
{
    new Query [256], sQuery [3000];
    
    formatex ( Query, charsmax ( Query ), "UPDATE `%s` SET ", SQL_TABLE );
    
        add ( sQuery, charsmax ( sQuery ), Query );

    formatex ( Query, charsmax ( Query ), "nickname = ^"%s^", ", PlayerName [id] );
        
        add ( sQuery, charsmax ( sQuery ), Query );

    formatex ( Query, charsmax ( Query ), "frags = ^"%i^", ", iFrags [id] );
        
        add ( sQuery, charsmax ( sQuery ), Query );

    formatex ( Query, charsmax ( Query ), "deaths = ^"%i^", ", iDeaths [id] );
        
        add ( sQuery, charsmax ( sQuery ), Query );

    formatex ( Query, charsmax ( Query ), "money = ^"%i^", ", iMoney [id] );
        
        add ( sQuery, charsmax ( sQuery ), Query );

    formatex ( Query, charsmax ( Query ), "last_seen_online = ^"%s^" WHERE steamid = ^"%s^";", iLastConnected [id], PlayerAuthID [id] );
    
        add ( sQuery, charsmax ( sQuery ), Query );
        
    SQL_ThreadQuery ( iSqlTuple, "QuerySetData", sQuery );
}


public QuerySetData ( FailState, Handle: Query, Error [ ], Errcode, Data [ ], DataSize, Float:Queuetime ) 
{
    if ( FailState == TQUERY_CONNECT_FAILED || FailState == TQUERY_QUERY_FAILED ) 
    {
        log_amx ( "[SQL] %s", Error );
        
        return;
    }
}

public client_putinserver ( id )
{
    get_user_name ( id, PlayerName [id], charsmax ( PlayerName [ ] ) );

    get_user_authid ( id, PlayerAuthID [id], charsmax ( PlayerAuthID [ ] ) );

    iFrags [id] = 0;

    iDeaths [id] = 0;

    iMoney [id] = 0;

    iLastConnected [id] = "N/A";
    
    LoadData ( id );
}


public client_disconnect ( id )
{
    iMoney [id] += cs_get_user_money ( id );

    new iTime [32];

    get_time ( "%m/%d/%Y - %H:%M:%S", iTime, charsmax ( iTime ) )
  
    copy ( iLastConnected [id], charsmax ( iLastConnected [ ] ), iTime )

    SaveData ( id );
}

public EventDeathMsg (  )
{
    new Killer = read_data ( 1 );
    
    new Victim = read_data ( 2 );
    
    if ( !is_user_alive ( Killer ) || Killer == Victim || get_user_team ( Killer ) == get_user_team ( Victim ) ) 

        return

    iFrags [Killer] ++;

    iDeaths [Victim] ++;
}

public leRoundEnd (  )
{
     for ( new i = 1; i <= MaxPlayers; i ++ )
    {
        if ( is_user_connected ( i ) )
        {
            iMoney  += cs_get_user_money ( i );

            SaveData ( i );
        }
    }
}

public plugin_end (  ) SQL_FreeHandle ( iSqlTuple );


Multumesc de raspuns si solutie, totusi observ ca compilerul de la freakz nu mai exista.Cu ce il pot compila?


Compilezi local. Daca nu ai compiler, este unul in acest addons default: addon-uri/addon-default-amxx-1-8-2-3-t187339.html. Descarci versiunea pentru windows si ai acolo tot ce iti trebuie.

Re: Plugin MYSQL inserare date.

Posted: 26 Mar 2020, 20:58
by DevilBoy.eXe
EnTeR_ wrote:
26 Mar 2020, 20:28
The Kalu wrote:
26 Mar 2020, 19:47
EnTeR_ wrote:
26 Mar 2020, 18:19
Banuiesc ca vrei sa faci ceva pe steam only, altfel nu o sa-ti mearga cum trebuie salvarea pe steamid. Anyway, testeaza asta si spune-mi daca sunt probleme.
| Afiseaza codul
#include <   amxmodx   >
#include <   cstrike   >
#include <    sqlx     >

#pragma tabsize 0;

new SQL_TABLE [ ] = "users_stats";

new iFrags [33], iDeaths [33], iMoney [33], iLastConnected [33] [32], PlayerAuthID [33] [32], PlayerName [33] [32],

Handle: iSqlTuple, SQLHost [32], SQLUser [32], SQLPassword [32], SQLDatabase [32], cSqlHost, cSqlUser,

cSqlPassword, cSqlDatabase, MaxPlayers;

public plugin_init (  )
{
    register_event ( "DeathMsg", "EventDeathMsg", "a" );
    
    register_logevent ( "leRoundEnd", 2, "1=Round_End" );

    cSqlHost = register_cvar ( "sql_host", "host" );
    
    cSqlUser = register_cvar ( "sql_user", "user" );
    
    cSqlPassword = register_cvar ( "sql_password", "pw" );
    
    cSqlDatabase = register_cvar ( "sql_database", "db" );

    MaxPlayers = get_maxplayers (  );
}

public plugin_cfg (  ) 
{
        get_pcvar_string ( cSqlHost, SQLHost, charsmax ( SQLHost ) );
    
        get_pcvar_string ( cSqlUser, SQLUser, charsmax ( SQLUser ) );
    
        get_pcvar_string ( cSqlPassword, SQLPassword, charsmax ( SQLPassword ) );
    
        get_pcvar_string ( cSqlDatabase, SQLDatabase, charsmax ( SQLDatabase ) );

        iSqlTuple = SQL_MakeDbTuple ( SQLHost, SQLUser, SQLPassword, SQLDatabase );
    
        static Query [10048], Len;
        
        Len += formatex ( Query [Len], charsmax ( Query ), "CREATE TABLE IF NOT EXISTS `%s`", SQL_TABLE );
    
        Len += formatex ( Query [Len], charsmax ( Query ) - Len, "(`steamid` varchar(32) NOT NULL, " );
    
        Len += formatex ( Query [Len], charsmax ( Query ) - Len, "`nickname` varchar(32) NOT NULL,");

        Len += formatex ( Query [Len], charsmax ( Query ) - Len, "`frags` int(11) NOT NULL,");

        Len += formatex ( Query [Len], charsmax ( Query ) - Len, "`deaths` int(11) NOT NULL,");

        Len += formatex ( Query [Len], charsmax ( Query ) - Len, "`money` int(11) NOT NULL,");

        Len += formatex ( Query [Len], charsmax ( Query ) - Len, "`last_seen_online` varchar(32) NOT NULL,");

        Len += formatex ( Query [Len], charsmax ( Query ) - Len, "`ID` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY)" );
    
        SQL_ThreadQuery ( iSqlTuple, "CreateTableThread", Query );
}

public CreateTableThread ( FailState, Handle:Query, Error [ ], Errcode, Data [ ], DataSize, Float:Queuetime ) 
{
    if ( FailState == TQUERY_CONNECT_FAILED || FailState == TQUERY_QUERY_FAILED )
    {
        set_fail_state ( "[SQL] Query Error" );
    }
    
    if ( Errcode )
    {
        log_amx ( "[SQL] Error: %s", Error );
    }
}

public LoadData ( id ) 
{
    static Query [10048], Data [1];
    
    Data [0] = id;
    
    formatex ( Query, charsmax ( Query ), "SELECT * FROM `%s` WHERE steamid = ^"%s^";", SQL_TABLE, PlayerAuthID [id] );
    
    SQL_ThreadQuery ( iSqlTuple, "QuerySelectData", Query, Data, 1 );
}

public QuerySelectData ( FailState, Handle: Query, Error [ ], Errcode, Data [ ], DataSize, Float: Queuetime ) 
{
    if ( FailState == TQUERY_CONNECT_FAILED || FailState == TQUERY_QUERY_FAILED )  
    {
        log_amx ( "[SQL] %s", Error );
        
        return;
    }
    else 
    {
        new id = Data [0];
        
        if ( SQL_NumRows ( Query ) < 1 ) 
        {
            new Query [256];
 
            formatex ( Query, charsmax ( Query ), "INSERT INTO `%s` (`steamid`,`nickname`,`frags`,`deaths`,`money`,`last_seen_online`) VALUES (^"%s^",^"%s^",^"0^",^"0^",^"0^",^"N/A^");", SQL_TABLE, PlayerAuthID [id], PlayerName [id] );

            SQL_ThreadQuery ( iSqlTuple, "QuerySetData", Query );

        }
        else
        {
            iFrags [id] = SQL_ReadResult ( Query, SQL_FieldNameToNum ( Query, "frags" ) );

            iDeaths [id] = SQL_ReadResult ( Query, SQL_FieldNameToNum ( Query, "deaths" ) );

            iMoney [id] = SQL_ReadResult ( Query, SQL_FieldNameToNum ( Query, "money" ) );

        }
    }
}

public SaveData ( id )
{
    new Query [256], sQuery [3000];
    
    formatex ( Query, charsmax ( Query ), "UPDATE `%s` SET ", SQL_TABLE );
    
        add ( sQuery, charsmax ( sQuery ), Query );

    formatex ( Query, charsmax ( Query ), "nickname = ^"%s^", ", PlayerName [id] );
        
        add ( sQuery, charsmax ( sQuery ), Query );

    formatex ( Query, charsmax ( Query ), "frags = ^"%i^", ", iFrags [id] );
        
        add ( sQuery, charsmax ( sQuery ), Query );

    formatex ( Query, charsmax ( Query ), "deaths = ^"%i^", ", iDeaths [id] );
        
        add ( sQuery, charsmax ( sQuery ), Query );

    formatex ( Query, charsmax ( Query ), "money = ^"%i^", ", iMoney [id] );
        
        add ( sQuery, charsmax ( sQuery ), Query );

    formatex ( Query, charsmax ( Query ), "last_seen_online = ^"%s^" WHERE steamid = ^"%s^";", iLastConnected [id], PlayerAuthID [id] );
    
        add ( sQuery, charsmax ( sQuery ), Query );
        
    SQL_ThreadQuery ( iSqlTuple, "QuerySetData", sQuery );
}


public QuerySetData ( FailState, Handle: Query, Error [ ], Errcode, Data [ ], DataSize, Float:Queuetime ) 
{
    if ( FailState == TQUERY_CONNECT_FAILED || FailState == TQUERY_QUERY_FAILED ) 
    {
        log_amx ( "[SQL] %s", Error );
        
        return;
    }
}

public client_putinserver ( id )
{
    get_user_name ( id, PlayerName [id], charsmax ( PlayerName [ ] ) );

    get_user_authid ( id, PlayerAuthID [id], charsmax ( PlayerAuthID [ ] ) );

    iFrags [id] = 0;

    iDeaths [id] = 0;

    iMoney [id] = 0;

    iLastConnected [id] = "N/A";
    
    LoadData ( id );
}


public client_disconnect ( id )
{
    iMoney [id] += cs_get_user_money ( id );

    new iTime [32];

    get_time ( "%m/%d/%Y - %H:%M:%S", iTime, charsmax ( iTime ) )
  
    copy ( iLastConnected [id], charsmax ( iLastConnected [ ] ), iTime )

    SaveData ( id );
}

public EventDeathMsg (  )
{
    new Killer = read_data ( 1 );
    
    new Victim = read_data ( 2 );
    
    if ( !is_user_alive ( Killer ) || Killer == Victim || get_user_team ( Killer ) == get_user_team ( Victim ) ) 

        return

    iFrags [Killer] ++;

    iDeaths [Victim] ++;
}

public leRoundEnd (  )
{
     for ( new i = 1; i <= MaxPlayers; i ++ )
    {
        if ( is_user_connected ( i ) )
        {
            iMoney  += cs_get_user_money ( i );

            SaveData ( i );
        }
    }
}

public plugin_end (  ) SQL_FreeHandle ( iSqlTuple );


Multumesc de raspuns si solutie, totusi observ ca compilerul de la freakz nu mai exista.Cu ce il pot compila?


Compilezi local. Daca nu ai compiler, este unul in acest addons default: addon-uri/addon-default-amxx-1-8-2-3-t187339.html. Descarci versiunea pentru windows si ai acolo tot ce iti trebuie.


Sau asta topic365704.html, contine doar compilerul

Re: Plugin MYSQL inserare date.

Posted: 26 Mar 2020, 22:47
by The Kalu

Code: Select all

C:\Users\steel\Desktop\1.10 - build 5390\sql_table.sma(216) : error 023: array assignment must be simple assignment

Code: Select all

public leRoundEnd (  )
{
     for ( new i = 1; i <= MaxPlayers; i ++ )
    {
        if ( is_user_connected ( i ) )
        {
            iMoney  += cs_get_user_money ( i );

            SaveData ( i );
        }
    }
}

rezolvat, cred.Am adaugat id jucator

Code: Select all

public leRoundEnd ( id )
{

     for ( new i = 1; i <= MaxPlayers; i ++ )
    {
        if ( is_user_connected ( i ) )
        {
            iMoney[id]  += cs_get_user_money ( i );

            SaveData ( i );
        }
    }
}

Re: Plugin MYSQL inserare date.

Posted: 26 Mar 2020, 22:49
by zLowCS
Pentru loose indentation , foloseste
#pragma tabelsize 0

Re: Plugin MYSQL inserare date.

Posted: 26 Mar 2020, 23:01
by EnTeR_
E de la forum, inlocuieste iMoney += cs_get_user_money ( i ); cu iMoney [ i ] += cs_get_user_money ( i );

Re: Plugin MYSQL inserare date.

Posted: 26 Mar 2020, 23:02
by The Kalu
EnTeR_ wrote:
26 Mar 2020, 23:01
E de la forum, inlocuieste iMoney += cs_get_user_money ( i ); cu iMoney [ i ] += cs_get_user_money ( i );
Eu pusesem id, trebuie i in loop.Solved :*

Re: Plugin MYSQL inserare date.

Posted: 26 Mar 2020, 23:02
by The Kalu
zLowCS wrote:
26 Mar 2020, 22:49
Pentru loose indentation , foloseste
#pragma tabelsize 0
Nup, am curatat un pic prin cod.

Re: Plugin MYSQL inserare date.

Posted: 27 Mar 2020, 02:10
by The Kalu
Functioneaza perfect, multumesc.Am facut update si la amx mod x 1.8.3, nu stiu cat de sigur este!

Lipseste asta.

Code: Select all

Inca o chestie, daca are gag/mute sa nu ii adauge nimic timp de 1 zi ca si cum ar avea un fel de cooldown.
Image

Re: Plugin MYSQL inserare date.

Posted: 27 Mar 2020, 20:24
by levin
pentru faza cu gag trb făcut cu nativ pentru plg extern pe care l postezi tu