O noua aventura incepe. LaLeagane - It's all about gaming!

2006 and still counting.

REZOLVATA Cerere plugin Knife top

Status
Subiectul a fost blocat si nu sunt permise comentarii ulterioare.

dozaa

Moderator
Joined
May 3, 2018
Messages
287
Reaction score
241
Age
17
Location
/var/tmp
Partea cu debug.log am facut o sa vezi daca afiseaza bine , si datele tot din mysql le preia
 
Last edited:

dozaa

Moderator
Joined
May 3, 2018
Messages
287
Reaction score
241
Age
17
Location
/var/tmp
Macrourile , aka #define , nu le pot face cvare , vor exista probleme, legat de hud sper ca l-am rezolvat , doar i-am dat copy paste din scriptul lui napolitana ala :)
Also sper ca nu mai sunt probleme deloc cu preluarea datelor ! De asemenea scriptul a fost optimizat , au fost modificate metodele de formatare a datelor daca pot spune asa
C++:
#include <amxmodx>
#include <amxmisc>
#include <sqlx>
#include <hamsandwich>

#pragma semicolon 1

new const DataBaseMainName[] = "NumeBazaDeDate";


#define MAX 33
#define SAVE_DATA 10.0

#define ROSU 255
#define VERDE 215
#define ALBASTRU 0
#define XO 0.03
#define YO 0.17


new const Text[]    = "Cutite date :";
new const Text2[]   = "Cutite Primite pe cocoasa :";


new DB_IP[]       = "ip la baza de date";
new DB_USER[]     = "username la baza de date";
new DB_PASS[]     = "parola baza de date";
new DB_NAME[]     = "nume baza de date (cea care apare in hostpanel) , nu pui ce nume vr aici";

new Handle:g_SqlTuple;
new g_Error[512];

new CutiteDate[MAX_PLAYERS + 1];
new CutitePrimite[MAX_PLAYERS + 1];

new SyncHudMessage;

public plugin_init() {
    register_plugin("knife Top", "1.4", "SenorAMXX");

    register_event( "DeathMsg" , "Event_DeathMsg" , "a" , "3=knife" );
    register_clcmd("say /knifetop", "CheckData");

    set_task(1.0,"HudMSG",_,_,_, "b");
    set_task(SAVE_DATA,"Save_MySql",_,_,_,"b",0);
    set_task(1.0, "MySql_Init");

    SyncHudMessage = CreateHudSyncObj();

}

public Event_DeathMsg()
{
    new killer = read_data(1);
    new victim = read_data(2);

    if( !is_user_hltv(killer) && !is_user_bot(killer) )
    {
        ++CutitePrimite[killer];
        ++CutiteDate[victim];
    }
}

public DisplayHud(id)
{
    if(!is_user_alive(id) || is_user_hltv(id) || is_user_bot(id)) return;

    new txtData[ 256 ];

    formatex(txtData, sizeof(txtData) - 1,"%s %d^n%s %d",Text,CutiteDate[id],Text2,CutitePrimite[id]);
    set_hudmessage(ROSU, VERDE, ALBASTRU, XO, YO, 0, 0.0, 20.0, 0.0, 0.0, -1);
    ShowSyncHudMsg(id, SyncHudMessage, txtData);
}



public MySql_Init()
{
    g_SqlTuple = SQL_MakeDbTuple(DB_IP,DB_USER,DB_PASS,DB_NAME);
  
    new ErrorCode,Handle:SqlConnection = SQL_Connect(g_SqlTuple,ErrorCode,g_Error,charsmax(g_Error));
    if(SqlConnection == Empty_Handle)
        set_fail_state(g_Error);
      
    new Handle:Queries;
    Queries = SQL_PrepareQuery(SqlConnection,"CREATE TABLE IF NOT EXISTS %s (steamid varchar(33),cutite_date INT(11),cutite_primite INT(11))",DataBaseMainName);

    if(!SQL_Execute(Queries))
    {
        SQL_QueryError(Queries,g_Error,charsmax(g_Error));
        set_fail_state(g_Error);
    }
    
    SQL_FreeHandle(Queries);
  
    SQL_FreeHandle(SqlConnection);
}

public plugin_end()     SQL_FreeHandle(g_SqlTuple);

public Load_MySql(id)
{
    new szSteamId[33], szTemp[512];
    get_user_authid(id, szSteamId, charsmax(szSteamId));
    
    new Data[1];
    Data[0] = id;

    formatex(szTemp,charsmax(szTemp),"SELECT * FROM `%s` WHERE (`%s`.`steamid` = '%s')",DataBaseMainName, DataBaseMainName, szSteamId);
    SQL_ThreadQuery(g_SqlTuple,"add_user",szTemp,Data,1);
}

public add_user(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
    if(FailState == TQUERY_CONNECT_FAILED)    log_amx("Load - Could not connect to SQL database.  [%d] %s", Errcode, Error);
    else if(FailState == TQUERY_QUERY_FAILED)    log_amx("Load Query failed. [%d] %s", Errcode, Error);

    new id;
    id = Data[0];
    
    if(SQL_NumResults(Query) < 3) // Daca nu a gasit cele 3 rezultate : STEAMID , CUTITE_DATE, CUTITE_PRIMIT register new id ?
    {
        
        new szSteamId[33];
        get_user_authid(id, szSteamId, charsmax(szSteamId));
        
        if (equal(szSteamId,"ID_PENDING"))
            return PLUGIN_HANDLED;
            
        new szTemp[512];
        
        formatex(szTemp,charsmax(szTemp),"INSERT INTO `%s` ( `steamid` , `cutite_date` , `cutite_primite` )VALUES ('%s','0', '0');",DataBaseMainName,szSteamId);
        SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp);
    }
    else
    {
        CutiteDate[id] = SQL_ReadResult(Query, 1);
        CutitePrimite[id] = SQL_ReadResult(Query, 2);
    }
    
    return PLUGIN_HANDLED;
}

public Save_MySql(id)
{
    new szSteamId[33], szTemp[512];
    get_user_authid(id, szSteamId, charsmax(szSteamId));
    
    formatex(szTemp,charsmax(szTemp),"UPDATE `%s` SET `cutite_date` = '%i' , `cutite_primite` = `%i` WHERE `%s`.`steamid` = '%s';",DataBaseMainName, CutiteDate[id], CutitePrimite[id], DataBaseMainName, szSteamId);
    SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp);
}

public IgnoreHandle(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
    SQL_FreeHandle(Query);
    
    return PLUGIN_HANDLED;
}

public client_disconnected(id)    Save_MySql(id);
public client_putinserver(id)
{
    set_task(20.0, "DisplayHud", id, _, _, "b");
    Load_MySql(id);
}



public CheckData(id)
{
    for(new i; i < MAX; i++)
    {
        if(is_user_connected(i))
           Save_MySql(i);
    }
        
    new Data[1];
    Data[0] = id;
    
    new szTemp[512];
    formatex(szTemp,charsmax(szTemp),"SELECT COUNT(*) FROM `%s` WHERE `cutite_date` >= %d",DataBaseMainName, CutiteDate[id]);
    SQL_ThreadQuery(g_SqlTuple,"Sql_Rank",szTemp,Data,1);
        
    return PLUGIN_HANDLED;
}

public Sql_Rank(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
    if(FailState == TQUERY_CONNECT_FAILED)    log_amx("Load - Could not connect to SQL database.  [%d] %s", Errcode, Error);
    else if(FailState == TQUERY_QUERY_FAILED)    log_amx("Load Query failed. [%d] %s", Errcode, Error);
 
    new count = 0;
    count = SQL_ReadResult(Query,0);
    if(count == 0)    count = 1;
    
    new iUser;
    iUser = Data[0];

    client_print(iUser, print_chat, "[KNIFE] You're rank is %i with %i knife kills", count, CutiteDate[iUser]);
    
    return PLUGIN_HANDLED;
}
Mai am de facut niste verificari in client_putinserver , dar ar trb sa fie okey acm :D
 

B1zAr3

leganar
Joined
Apr 8, 2011
Messages
60
Reaction score
4
Age
31
Location
Bucuresti
Salut,

Compileaza corect - vad pluginul in lista - dar din pacate avem eroarea asta :

L 04/10/2021 - 12:52:23: HudSyncObject -1 is invalid
L 04/10/2021 - 12:52:23: [AMXX] Displaying debug trace (plugin "Topknife.amxx", version "1.4")
L 04/10/2021 - 12:52:23: [AMXX] Run time error 10: native error (native "ShowSyncHudMsg")
L 04/10/2021 - 12:52:23: [AMXX] [0] Topknife.sma: DisplayHud (line 72)


Toate cele bune,
Adrian
 

dozaa

Moderator
Joined
May 3, 2018
Messages
287
Reaction score
241
Age
17
Location
/var/tmp
Deci , hudul era bun cum l-am facut prima oara , mai scoate din hudurile inutile de pe server . Pentru ca se formateaza 4 informatii : Text de la kill count , text de la knifed count , valoarea de la kill count respectiv valoarea de la knifed count !

C++:
#include <amxmodx>
#include <amxmisc>
#include <sqlx>
#include <hamsandwich>

#pragma semicolon 1

new const DataBaseMainName[] = "NumeBazaDeDate";


#define MAX 33
#define SAVE_DATA 10.0
#define FRQ 20.0

#define ROSU 255
#define VERDE 215
#define ALBASTRU 0
#define XO 0.03
#define YO 0.17


new const Text[]    = "Cutite date :";
new const Text2[]   = "Cutite Primite pe cocoasa :";


new DB_IP[]       = "ip la baza de date";
new DB_USER[]     = "username la baza de date";
new DB_PASS[]     = "parola baza de date";
new DB_NAME[]     = "nume baza de date (cea care apare in hostpanel) , nu pui ce nume vr aici";

new Handle:g_SqlTuple;
new g_Error[512];

new CutiteDate[MAX_PLAYERS + 1];
new CutitePrimite[MAX_PLAYERS + 1];

new SyncHudMessage;

public plugin_init() {
    register_plugin("knife Top", "1.4", "SenorAMXX");

    register_event( "DeathMsg" , "Event_DeathMsg" , "a" , "3=knife" );
    register_event("ResetHUD", "event_ResetHud", "be");
    RegisterHam(Ham_Spawn, "player", "Ham_PlayerSpawnedPost", 1);
   
    register_clcmd("say /knifetop", "CheckData");

    set_task(1.0,"HudMSG",_,_,_, "b");
    set_task(SAVE_DATA,"Save_MySql",_,_,_,"b",0);
    set_task(1.0, "MySql_Init");

    SyncHudMessage = CreateHudSyncObj();

}

public Event_DeathMsg()
{
    new killer = read_data(1);
    new victim = read_data(2);

    if( !is_user_hltv(killer) && !is_user_bot(killer) )
    {
        ++CutitePrimite[killer];
        ++CutiteDate[victim];
    }
}

public event_ResetHud(id) HudMSG(id);

public Ham_PlayerSpawnedPost(id)
{
    if(is_user_connected(id))
        set_task(1.0, "HudMSG", id, _, _, "b");
}

public HudMSG(id)
{
    if(!is_user_alive(id) || is_user_hltv(id) || is_user_bot(id)) return;
    new txtData[ 256 ];
    formatex(txtData, sizeof( txtData ) - 1,"%s %d^n%s %d",Text,CutiteDate[id],Text2,CutitePrimite[id]);

    set_hudmessage(ROSU, VERDE, ALBASTRU, XO, YO, 0, 0.5, 15.0, 2.0, 2.0, -1);
    ShowSyncHudMsg(id, SyncHudMessage, txtData);

}



public MySql_Init()
{
    g_SqlTuple = SQL_MakeDbTuple(DB_IP,DB_USER,DB_PASS,DB_NAME);
  
    new ErrorCode,Handle:SqlConnection = SQL_Connect(g_SqlTuple,ErrorCode,g_Error,charsmax(g_Error));
    if(SqlConnection == Empty_Handle)
        set_fail_state(g_Error);
      
    new Handle:Queries;
    Queries = SQL_PrepareQuery(SqlConnection,"CREATE TABLE IF NOT EXISTS %s (steamid varchar(33),cutite_date INT(11),cutite_primite INT(11))",DataBaseMainName);

    if(!SQL_Execute(Queries))
    {
        SQL_QueryError(Queries,g_Error,charsmax(g_Error));
        set_fail_state(g_Error);
    }
   
    SQL_FreeHandle(Queries);
  
    SQL_FreeHandle(SqlConnection);
}

public plugin_end()     SQL_FreeHandle(g_SqlTuple);

public Load_MySql(id)
{
    new szSteamId[33], szTemp[512];
    get_user_authid(id, szSteamId, charsmax(szSteamId));
   
    new Data[1];
    Data[0] = id;

    formatex(szTemp,charsmax(szTemp),"SELECT * FROM `%s` WHERE (`%s`.`steamid` = '%s')",DataBaseMainName, DataBaseMainName, szSteamId);
    SQL_ThreadQuery(g_SqlTuple,"add_user",szTemp,Data,1);
}

public add_user(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
    if(FailState == TQUERY_CONNECT_FAILED)    log_amx("Load - Could not connect to SQL database.  [%d] %s", Errcode, Error);
    else if(FailState == TQUERY_QUERY_FAILED)    log_amx("Load Query failed. [%d] %s", Errcode, Error);

    new id;
    id = Data[0];
   
    if(SQL_NumResults(Query) < 3) // Daca nu a gasit cele 3 rezultate : STEAMID , CUTITE_DATE, CUTITE_PRIMIT register new id ?
    {
       
        new szSteamId[33];
        get_user_authid(id, szSteamId, charsmax(szSteamId));
       
        if (equal(szSteamId,"ID_PENDING"))
            return PLUGIN_HANDLED;
           
        new szTemp[512];
       
        formatex(szTemp,charsmax(szTemp),"INSERT INTO `%s` ( `steamid` , `cutite_date` , `cutite_primite` )VALUES ('%s','0', '0');",DataBaseMainName,szSteamId);
        SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp);
    }
    else
    {
        CutiteDate[id] = SQL_ReadResult(Query, 1);
        CutitePrimite[id] = SQL_ReadResult(Query, 2);
    }
   
    return PLUGIN_HANDLED;
}

public Save_MySql(id)
{
    new szSteamId[33], szTemp[512];
    get_user_authid(id, szSteamId, charsmax(szSteamId));
   
    formatex(szTemp,charsmax(szTemp),"UPDATE `%s` SET `cutite_date` = '%i' , `cutite_primite` = `%i` WHERE `%s`.`steamid` = '%s';",DataBaseMainName, CutiteDate[id], CutitePrimite[id], DataBaseMainName, szSteamId);
    SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp);
}

public IgnoreHandle(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
    SQL_FreeHandle(Query);
   
    return PLUGIN_HANDLED;
}

public client_disconnected(id)    Save_MySql(id);
public client_putinserver(id)
{
    Load_MySql(id);
}



public CheckData(id)
{
    for(new i; i < MAX; i++)
    {
        if(is_user_connected(i))
           Save_MySql(i);
    }
       
    new Data[1];
    Data[0] = id;
   
    new szTemp[512];
    formatex(szTemp,charsmax(szTemp),"SELECT COUNT(*) FROM `%s` WHERE `cutite_date` >= %d",DataBaseMainName, CutiteDate[id]);
    SQL_ThreadQuery(g_SqlTuple,"Sql_Rank",szTemp,Data,1);
       
    return PLUGIN_HANDLED;
}

public Sql_Rank(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
{
    if(FailState == TQUERY_CONNECT_FAILED)    log_amx("Load - Could not connect to SQL database.  [%d] %s", Errcode, Error);
    else if(FailState == TQUERY_QUERY_FAILED)    log_amx("Load Query failed. [%d] %s", Errcode, Error);
 
    new count = 0;
    count = SQL_ReadResult(Query,0);
    if(count == 0)    count = 1;
   
    new iUser;
    iUser = Data[0];

    client_print(iUser, print_chat, "[KNIFE] You're rank is %i with %i knife kills", count, CutiteDate[iUser]);
   
    return PLUGIN_HANDLED;
}
 
Last edited:

B1zAr3

leganar
Joined
Apr 8, 2011
Messages
60
Reaction score
4
Age
31
Location
Bucuresti
A inceput sa inregistreze si la primite - dar total aiurea.
De exemplu cand mi-am luat o lama - s-a pus la killuri - si cand am murit normal din pistol s-a pus la received - de asemenea atunci cand faci kill normal se pune la knife kills.

Tot nu scrie in MySql...

This is in the logs :D

L 04/10/2021 - 15:48:55: [AMXX] Displaying debug trace (plugin "Topknife.amxx", version "1.4")
L 04/10/2021 - 15:48:55: [AMXX] Run time error 10: native error (native "SQL_FreeHandle")
L 04/10/2021 - 15:48:55: [AMXX] [0] Topknife.sma: Plugin_end (line 99)
 
Last edited:

dozaa

Moderator
Joined
May 3, 2018
Messages
287
Reaction score
241
Age
17
Location
/var/tmp
E imposibil sa nu iti scrie , mie imi merge perfect , am testat pe sv de zm
 

B1zAr3

leganar
Joined
Apr 8, 2011
Messages
60
Reaction score
4
Age
31
Location
Bucuresti
Problema rezolvata!
Pluginul ramane privat :) - Multumesc frumos !

Toate cele bune,
 
Status
Subiectul a fost blocat si nu sunt permise comentarii ulterioare.
shape1
shape2
shape3
shape4
shape5
shape6
Top