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

2006 and still counting.

[REZOLVAT] Cerere plugin Knife top

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

B1zAr3

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

Rulez un server mic de gun game - si mi-as dori daca este posibil un plugin care sa contorizeze numarul de killuri cu lama cu scris verde sub radar in stanga si utilizand comanda /knifetop sa afiseze top15 lame date si primite all time. - sper ca ma nimerit bine topicul.

Tipul de joc: CS 1.6 - Gungame mod
Ce doresti: plugin Amx 1.9.0.5271 Dev Team
Descriere: Undeva sub radar ar fi perfect daca ar aparea cu verde Lame date si imediat sub Lame primite - de asemenea comanda /knifetop sa arate sub forma de motd ( asemanator top15 normal) topul lamelor all time.

Va multumesc anticipat - mentionez ca am cautat internetul in lung si in lat si nu am gasit nimic asemanator.

Toate cele bune,
B1zAr
 
Last edited by a moderator:

dragos

leganar
Joined
Sep 8, 2020
Messages
1,030
Reaction score
697
Age
21
Nu am gasit nici eu mometan,te anunt daca am gasit pluginul!
 

B1zAr3

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

@dragos - Daca gasesti ceva - apreciez un mesaj cv :) - Multumesc
@wakEdb - Intradevar este exact ca cel pe care l-ai postat tu, doar ca nu este pentru amxx este pentru source mod :) - apreciez timpul tau.

Anybody else ?

Toate cele bune,
Adrian
 
Last edited:

wakEdb

compe/hns.laleagane.ro
Joined
Aug 3, 2019
Messages
523
Reaction score
72
Location
0°N 0°E
Va salut,

@dragos - Daca gasesti ceva - apreciez un mesaj cv :) - Multumesc
@wakEdb - Intradevar este exact ca cel pe care l-ai postat tu, doar ca nu este pentru amxx este pentru source mod :) - apreciez timpul tau.

Anybody else ?

Toate cele bune,
Adrian
Scuze sefule, am fost neatent. In postul unde am gasit eu scriptul de mai jos a postat si un anume B1zar care banuiesc ca esti tu. Acolo ai cerut ceva in plus insa pe acesta l-ai incercat/ merge?
Trebuie sa-l compilezi in plugin si sa-l adaugi pe sv. Daca ai nevoie de ajutor, reply.

#include <amxmodx>
#include <nvault>

#pragma semicolon 1

#if !defined MAX_PLAYERS
const MAX_PLAYERS = 32;
#endif

#if AMXX_VERSION_NUM < 190
#define client_disconnected(%1) client_disconnect(%1)
#endif

new const szVersion[] = "1.0.0";

new iKnifeCount[MAX_PLAYERS + 1];

new iVault;

public plugin_init() {
register_plugin("KnifeKillCount", szVersion, "NapoleoN#");

register_clcmd("say /kc", "KnifeCount");

register_event("DeathMsg", "eDeath", "a", "1>0", "1!2");

iVault = nvault_open("KnifeKillCount");
}

public plugin_end() {
nvault_close(iVault);
}

public client_disconnected(id) {
SaveData(id);
}

public client_authorized(id) {
LoadData(id);
}

public eDeath() {
new iAttacker = read_data(1);
new iClip, iAmmo, iWeapon;
iWeapon = get_user_weapon(iAttacker, iClip, iAmmo);

if(iWeapon == CSW_KNIFE && is_user_connected(iAttacker)) {
iKnifeCount[iAttacker]++;
}
}

public KnifeCount(id) {
client_print(id, print_chat, "Knife KillCount: %i", iKnifeCount[id]);
}

SaveData(id) {
new szAuth[35], szTemp[10];
get_user_authid(id, szAuth, charsmax(szAuth));

formatex(szTemp, charsmax(szTemp), "%i", iKnifeCount[id]);

nvault_set(iVault, szAuth, szTemp);
}

LoadData(id) {
new szAuth[35], szKillCount[10], szTemp[10];
get_user_authid(id, szAuth, charsmax(szAuth));

nvault_get(iVault, szAuth, szTemp, charsmax(szTemp));

parse(szTemp, szKillCount, charsmax(szKillCount));

iKnifeCount[id] = str_to_num(szKillCount);
}
 

SenorAMXX

ze.laleagane.ro
Joined
May 3, 2018
Messages
151
Reaction score
211
Age
17
Location
/var/tmp
C++:
#include <amxmodx>
#include <sqlx>

#define ARMA CSW_KNIFE
#define MAX 33
#define SAVE_DATA 10.0 // Aici modifici la cate secunde sa se introduca datele in DB , recomand 10 sec. ptr ca sa nu fie probleme



#if AMXX_VERSION_NUM < 190
    #define client_disconnected(%1) client_disconnect(%1)
#endif




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 KnifeCount[33]


public plugin_init() {
    register_plugin("knife Top", "1.0", "SenorAMXX")
 
    register_event("DeathMsg", "Event_DeathMsg", "a")

    register_clcmd("say /knifetop", "CheckData")
 
    set_task(SAVE_DATA,"Save_MySql",_,_,_,"b",0)
    set_task(1.0, "MySql_Init")
}

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 KnifeTopDB (steamid varchar(32),cutite INT(11))")

    if(!SQL_Execute(Queries))
    {
        // if there were any problems
        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[32], szTemp[512]
    get_user_authid(id, szSteamId, charsmax(szSteamId))
 
    new Data[1]
    Data[0] = id

    format(szTemp,charsmax(szTemp),"SELECT * FROM `KnifeTopDB` WHERE (`KnifeTopDB`.`steamid` = '%s')", 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) < 1)
    {
     
        new szSteamId[32]
        get_user_authid(id, szSteamId, charsmax(szSteamId))
     
        if (equal(szSteamId,"ID_PENDING"))
            return PLUGIN_HANDLED
         
        new szTemp[512]
     
        format(szTemp,charsmax(szTemp),"INSERT INTO `KnifeTopDB` ( `steamid` , `cutite`)VALUES ('%s','0');",szSteamId)
        SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp)
    }
    else
    {
        KnifeCount[id] = SQL_ReadResult(Query, 1)
    }
 
    return PLUGIN_HANDLED
}

public Save_MySql(id)
{
    new szSteamId[32], szTemp[512]
    get_user_authid(id, szSteamId, charsmax(szSteamId))
 
    format(szTemp,charsmax(szTemp),"UPDATE `KnifeTopDB` SET `cutite` = '%i' WHERE `KnifeTopDB`.`steamid` = '%s';",KnifeCount[id], szSteamId)
    SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp)
}

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

public client_putinserver(id)    Load_MySql(id)

public client_disconnected(id)    Save_MySql(id)


public Event_DeathMsg()
{
     new iKiller = read_data(1)
        new iVictim = read_data(2)
        new get_weapon = get_user_weapon(iKiller)

     if(!is_user_connected(iKiller))    return PLUGIN_HANDLED

     if(get_weapon == ARMA)    KnifeCount[iVictim] += 1
     return
}

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]
    format(szTemp,charsmax(szTemp),"SELECT COUNT(*) FROM `KnifeTopDB` WHERE `cutite` >= %d", KnifeCount[id])
    SQL_ThreadQuery(g_SqlTuple,"Sql_Rank",szTemp,Data,1)
     
    return PLUGIN_CONTINUE
}

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, KnifeCount[iUser]);
 
    return PLUGIN_HANDLED
}

O sa iti fac si partea cu motd-ul si hudul de sub radar in 1-2 ore ca sunt pe fuga :D
 
Last edited:

B1zAr3

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

@wakEdb -​

acel post l-am gasit asemanator cu ce imi doresc eu, si am postat in continuarea lui - pluginul functioneaza - insa nu este ce imi doresc eu - de asemenea la schimbarea mapei scorul se pierde - eu mi-as dori ceva permanent :)


@SenorAMXX - Iti multumesc frumos pentru timpul si energia ta pentru plugin-ul de mai sus - din pacate, primesc 3 erori la compilare. - Am atasat screenshot

compile.JPG
Apreciez efortul tau - si iti multumesc frumos.

Toate cele bune,
Adrian
 

SenorAMXX

ze.laleagane.ro
Joined
May 3, 2018
Messages
151
Reaction score
211
Age
17
Location
/var/tmp
loose identfication = cod nearanjat si nu incurca
si la faza cu ev deathmsg nu te incurca nici aia, o sa il modific in cateva minute
 

SenorAMXX

ze.laleagane.ro
Joined
May 3, 2018
Messages
151
Reaction score
211
Age
17
Location
/var/tmp
C++:
#include <amxmodx>
#include <sqlx>

#pragma semicolon 1

#define ARMA CSW_KNIFE
#define MAX 33
#define SAVE_DATA 10.0 // Aici modifici la cate secunde sa se introduca datele in DB , recomand 10 sec. ptr ca sa nu fie probleme

/* ------ [ Aici sunt setarile pentru hud, le modifici valorile daca ai nevoie ] ------*/

// Culori ( site : http://www.valmindesign.com/blog/web-design/coduri-culori/ )
#define ROSU 255
#define VERDE 215
#define ALBASTRU 0

//Aranajre pe axa xOy
#define SUS 0.03
#define JOS 0.17


// aici modifici cum vr sa scrie in hud ; De exemplu : Kill Count : 5
new const Text[] = "Kill Count :";

/* ------ [ Sfarsit setari hud ] ------*/

#if AMXX_VERSION_NUM < 190
    #define client_disconnected(%1) client_disconnect(%1)
#endif




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 KnifeCount[33];


public plugin_init() {
    register_plugin("knife Top", "1.0", "SenorAMXX");
    
    register_event("DeathMsg", "Event_DeathMsg", "a");

    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");

}


public HudMSG(Data[])
{   
    new id;
    id = Data[0];
      new ggg = KnifeCount[id];
    set_hudmessage(ROSU, VERDE, ALBASTRU, SUS, JOS, 0, 6.0, 1.0);
    show_hudmessage(id, "%s %d",Text, ggg);
}

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 KnifeTopDB (steamid varchar(32),cutite INT(11))");

    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[32], szTemp[512];
    get_user_authid(id, szSteamId, charsmax(szSteamId));
    
    new Data[1];
    Data[0] = id;

    format(szTemp,charsmax(szTemp),"SELECT * FROM `KnifeTopDB` WHERE (`KnifeTopDB`.`steamid` = '%s')", 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) < 1)
    {
        
        new szSteamId[32];
        get_user_authid(id, szSteamId, charsmax(szSteamId));
        
        if (equal(szSteamId,"ID_PENDING"))
            return PLUGIN_HANDLED;
            
        new szTemp[512];
        
        format(szTemp,charsmax(szTemp),"INSERT INTO `KnifeTopDB` ( `steamid` , `cutite`)VALUES ('%s','0');",szSteamId);
        SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp);
    }
    else
    {
        KnifeCount[id] = SQL_ReadResult(Query, 1);
    }
    
    return PLUGIN_HANDLED;
}

public Save_MySql(id)
{
    new szSteamId[32], szTemp[512];
    get_user_authid(id, szSteamId, charsmax(szSteamId));
    
    format(szTemp,charsmax(szTemp),"UPDATE `KnifeTopDB` SET `cutite` = '%i' WHERE `KnifeTopDB`.`steamid` = '%s';",KnifeCount[id], szSteamId);
    SQL_ThreadQuery(g_SqlTuple,"IgnoreHandle",szTemp);
}

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

public client_putinserver(id)    Load_MySql(id);

public client_disconnected(id)    Save_MySql(id);


public Event_DeathMsg()
{
    new iKiller = read_data(1);
       new iVictim = read_data(2);
       new get_weapon = get_user_weapon(iKiller);

    if(!is_user_connected(iKiller))    return PLUGIN_HANDLED;

    if(get_weapon == ARMA)    KnifeCount[iVictim] += 1;
    return PLUGIN_CONTINUE;
}

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];
    format(szTemp,charsmax(szTemp),"SELECT COUNT(*) FROM `KnifeTopDB` WHERE `cutite` >= %d", KnifeCount[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, KnifeCount[iUser]);
    
    return PLUGIN_HANDLED;
}


Acum merge si hudul ( ti-am facut niste modificari si niste comentarii daca ai nevoie de vreo modificare ) , cat despre motd si "cutitele primite" ma depasesc, o sa ma mai documentez pana diseara si poate ii dau edit ,pana atunci vei daca merge asa !

PS:
warning : loose identification inseamna ca nu e codul aranjat si nu incurca

Iti trebuie o baza de date ca sa functioneze corect ,pentru ca salvarea pe nvault pe langa faptul ca la +100 intrari inregistrate o ia razna, la un server restart se sterge sau se modifica random ,asa pe mysql ai garantia ca nu se pierde nimic
 

B1zAr3

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

In primul rand permite-mi sa iti multumesc pentru timpul si efortul tau -
You The Man GIF by memecandy


Plugin-ul functioneaza,am reusit sa conectez cu Mysql - creat baza de date - inregistreaza killurile si le salveaza dupa retry si map change ( awesome stuff ! Thank you !!)
Permite-mi sa iti expun cateva aspecte pe care as vrea sa le atingem, daca e posibil evident :

1) Ruland comanda /knifetop - in schimbul top15 pe care il asteptam intr-un motd - am gasit
1617827766419.png

Eu caut ceva in directia asta - evident scos HS si Acc + modificat Top15 in Knifetop ( nu am atasat toate poza era prea mare - you get the point :)
1617827894217.png


2) Din ce am vazut in cod - Hud message-ul ar trebui sa ruleze automat - nu este nici o comanda sa il pornesti/opresti - ar trebui sa fie auto - din pacate - la mine nu functioneaza acest feature. Mentionez ca nu am modificat deloc schema de culori sau axele predefinite de tine.

3) Cum se inregistreaza in Mysql ? in momentul in care intri pe servar? sau doar atunci cand faci actually un knife kill ?

4) Let me know cum te pot ajuta sa gasim solutia si pentru cutite luate - ar fi super ! :D

Inca odata iti multumesc pentru efortul si timpul tau - i really appreciate - daca esti din Bucuresti dau niste bericica :)

Toate cele bune,
Adrian
 

B1zAr3

leganar
Joined
Apr 8, 2011
Messages
60
Reaction score
4
Age
31
Location
Bucuresti
Revin cu un edit - din pacate expirase timpul de editare a postul anterior.

Am mai cautat prin logs - just to be on the safe side - si am gasit asta :

1617831040751.png


Thanks :)
 

SenorAMXX

ze.laleagane.ro
Joined
May 3, 2018
Messages
151
Reaction score
211
Age
17
Location
/var/tmp
Okey , faza cu motd inca nu m-am prins cum ar trb schitata !
La treaba cu salvarea in mysql , se salveaz automat odata la 10 secunde si la deconectare pentru prevenirea pierderii de knife count
Also legat de eroare , apare ptr ca am uitat sa fac o verificare legata de arma folosita in timpul "killului" , se rezolva , la fel si la hud
EDIT : Legat de cutitele primite , va trb sa fac inca o variabila care trb inregistrata , o sa incerc pana plec la munca :)
 
Last edited:

SenorAMXX

ze.laleagane.ro
Joined
May 3, 2018
Messages
151
Reaction score
211
Age
17
Location
/var/tmp
Ok , incearca asta , e un mic update la plugin , mici fixuri si optimizari la cod, also am adaugat ca datele ptr db sa fie adaugate din amxx.cfg , ca sa fie mai usor , sa nu stai sa recompilezi plg de fiecare data :D
PS : Nu imi iese treaba cu MOTD-ul , ma depaseste .. , i need to research more :(
C++:
#include <amxmodx>
#include <sqlx>
#include <hamsandwich>

#pragma semicolon 1


/* -------- [DB NAME] -------- */
new const DataBaseMainName[] = "NumeBazaDeDate"; // aici pui ce nume vrei la baza de date ! Exemplu "KnifeKillsDB"



#define ARMA CSW_KNIFE
#define MAX 33
#define SAVE_DATA 10.0 // Aici modifici la cate secunde sa se introduca datele in DB , recomand 10 sec. ptr ca sa nu fie probleme

/* ------ [ Aici sunt setarile pentru hud, le modifici valorile daca ai nevoie ] ------*/

// Culori ( site : http://www.valmindesign.com/blog/web-design/coduri-culori/ )
#define ROSU 255
#define VERDE 215
#define ALBASTRU 0

//Aranajre pe axa xOy
#define XO 0.03  // stanga dreapta
#define YO 0.17  // sus jos


// aici modifici cum vr sa scrie in hud ; De exemplu : Kill Count : 5 
new const Text[]    = "Cutite date :";
new const Text2[]   = "Cutite Primite pe cocoasa :";

/* ------ [ Sfarsit setari hud ] ------*/

#if AMXX_VERSION_NUM < 190
    #define client_disconnected(%1) client_disconnect(%1)
#endif

enum
{
    DB_IP,
    DB_USER,
    DB_PASS,
    DB_NAME,
    MAX_VARS
};

new VAR[MAX_VARS];

new Handle:g_SqlTuple;
new g_Error[512];

new CutiteDate[33];
new CutitePrimite[33];

new SyncHudMessage;


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

    VAR[DB_IP]      = register_cvar("database_ip"   ," ");
    VAR[DB_USER]    = register_cvar("database_user" ," ");
    VAR[DB_PASS]    = register_cvar("database_pass" ," ");
    VAR[DB_NAME]    = register_cvar("database_name" ," ");


    register_event("DeathMsg", "Event_DeathMsg", "a");
    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_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()
{
    new IP[128],USER[64],PASS[64],NAME[64];
    get_cvar_string(VAR[DB_IP], IP, charsmax(IP));
    get_cvar_string(VAR[DB_USER], USER, charsmax(USER));
    get_cvar_string(VAR[DB_PASS], PASS, charsmax(PASS));
    get_cvar_string(VAR[DB_NAME], NAME, charsmax(NAME));


    g_SqlTuple = SQL_MakeDbTuple(IP,USER,PASS,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(32),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[32], szTemp[512];
    get_user_authid(id, szSteamId, charsmax(szSteamId));
    
    new Data[1];
    Data[0] = id;

    format(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) < 2) 
    {
        
        new szSteamId[32];
        get_user_authid(id, szSteamId, charsmax(szSteamId));
        
        if (equal(szSteamId,"ID_PENDING"))
            return PLUGIN_HANDLED;
            
        new szTemp[512];
        
        format(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[32], szTemp[512];
    get_user_authid(id, szSteamId, charsmax(szSteamId));
    
    format(szTemp,charsmax(szTemp),"UPDATE `%s` SET `cutite_date` = '%i' AND `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_putinserver(id)    Load_MySql(id);

public client_disconnected(id)    Save_MySql(id);



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

    if(!is_user_alive(killer) || is_user_hltv(killer) || is_user_bot(killer) && killer_weapon != ARMA) return;
    else
    {
        ++CutiteDate[killer];
    }
    if(victim == killer)
    {
        if(!is_user_alive(victim) || is_user_hltv(victim) || is_user_bot(victim) && victim_weapon != ARMA) return;
        else
        {
            ++CutitePrimite[killer];
        }
    }
}

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];
    format(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;
}

In amxx.cfg pui astea :
C++:
database_ip "ip baza de date"
database_user "username baza de date"
database_pass "parola  baza de date"
database_name "nume baza de date"
Nu sunt din Bucuresti :D, dar daca vrei sa imi sustii munca , da o bere aici ;) bere
 
Last edited:

B1zAr3

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

3rd times a charm :) a compilat fara galagie tura asta - am put toate informatiile cum mi-ai specificat tu - but for some reason nu se conecteaza la mysql.
Am sters si baza de date veche - la fel :(

Am adaugat ip, username tot - still no love.... - I get this -
1617905712458.png

Sper sa reusesti sa iti iei niste bere rece din astia :D stiu ca nu e cine stie ce :) but its money in, not out - as they say
Futurama Buy GIF


Toate cele bune,
Adrian
 

SenorAMXX

ze.laleagane.ro
Joined
May 3, 2018
Messages
151
Reaction score
211
Age
17
Location
/var/tmp
Apreciez orice fel de sustinere <3 ; Mie imi ruleaza fara probleme, tie vad ca nu iti citeste string-urile, try this :
C++:
#include <amxmodx>
#include <sqlx>
#include <hamsandwich>

#pragma semicolon 1


/* -------- [DB NAME] -------- */
new const DataBaseMainName[] = "NumeBazaDeDate"; // aici pui ce nume vrei la baza de date ! Exemplu "KnifeKillsDB"



#define ARMA CSW_KNIFE
#define MAX 33
#define SAVE_DATA 10.0 // Aici modifici la cate secunde sa se introduca datele in DB , recomand 10 sec. ptr ca sa nu fie probleme

/* ------ [ Aici sunt setarile pentru hud, le modifici valorile daca ai nevoie ] ------*/

// Culori ( site : http://www.valmindesign.com/blog/web-design/coduri-culori/ )
#define ROSU 255
#define VERDE 215
#define ALBASTRU 0

//Aranajre pe axa xOy
#define XO 0.03  // stanga dreapta
#define YO 0.17  // sus jos


// aici modifici cum vr sa scrie in hud ; De exemplu : Kill Count : 5
new const Text[]    = "Cutite date :";
new const Text2[]   = "Cutite Primite pe cocoasa :";

/* ------ [ Sfarsit setari hud ] ------*/

#if AMXX_VERSION_NUM < 190
    #define client_disconnected(%1) client_disconnect(%1)
#endif

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[33];
new CutitePrimite[33];

new SyncHudMessage;


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


    register_event("DeathMsg", "Event_DeathMsg", "a");
    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_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(32),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[32], szTemp[512];
    get_user_authid(id, szSteamId, charsmax(szSteamId));
   
    new Data[1];
    Data[0] = id;

    format(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) < 2)
    {
       
        new szSteamId[32];
        get_user_authid(id, szSteamId, charsmax(szSteamId));
       
        if (equal(szSteamId,"ID_PENDING"))
            return PLUGIN_HANDLED;
           
        new szTemp[512];
       
        format(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[32], szTemp[512];
    get_user_authid(id, szSteamId, charsmax(szSteamId));
   
    format(szTemp,charsmax(szTemp),"UPDATE `%s` SET `cutite_date` = '%i' AND `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_putinserver(id)    Load_MySql(id);

public client_disconnected(id)    Save_MySql(id);



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

    if(!is_user_alive(killer) || is_user_hltv(killer) || is_user_bot(killer) && killer_weapon != ARMA) return;
    else
    {
        ++CutiteDate[killer];
    }
    if(victim == killer) // La partea asta nu mi-a venit prin cap altceva decat sa verific daca victima e criminalul , working ? i think so xd
    {
        if(!is_user_alive(victim) || is_user_hltv(victim) || is_user_bot(victim) && victim_weapon != ARMA) return;
        else
        {
            ++CutitePrimite[killer];
        }
    }
}

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];
    format(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;
}

EDIT : Folosesti baza de date pe acelasi host / ip sau e remote ? Pentru ca asta ar fi putut provoca eroarea , altceva nu :j
 
Last edited:

B1zAr3

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

Mysql e pe host remote - alt ip decat cel al servarului :D
Intradevar ruleaza pluginul dar pare ca inregistreaza kill-uri random pe arme, cateodata succesiv - de asemenea la map change - s-a dus :(
Cutitele primite nu se inregistreaza deloc by the way.

Uite cum arata tabla din sql -
1617910184226.png


Hai sa il mai optimizam putin in sensul refresh rate-ului ( momentan e real time - pune-l te rog sa se updateze atunci cand mori, ca imi interfereaza cu celelalte plugin-uri de mesaje hud. Inclusiv cu cel de gungame - nu iti mai arata nimic altceva :)

Error in logs :
1617910341432.png


Pune la loc comanda /knifetop please - chiar daca arata mesaj text momentan - poate e editabil later on :) fingers crossed

Later edit : Versiunea anterioara avea niste cvaruri de nume db, username, bla bla - in loc de alea - pune daca poti x si y pentru hud mesage sa il incadrez bine :)
 
Last edited:

SenorAMXX

ze.laleagane.ro
Joined
May 3, 2018
Messages
151
Reaction score
211
Age
17
Location
/var/tmp
Pentru xyz si culori ai astea :
C++:
#define ROSU 255
#define VERDE 215
#define ALBASTRU 0

//Aranajre pe axa xOy
#define XO 0.03  // stanga dreapta
#define YO 0.17  // sus jos

Mie imi functioneaza pluginul, probabil rulezi alt build de amxx, am incercat sa fac cu functii deprecate , poate ajuta ..
C++:
#include <amxmodx>
#include <sqlx>
#include <hamsandwich>

#pragma semicolon 1


/* -------- [DB NAME] -------- */
new const DataBaseMainName[] = "NumeBazaDeDate"; // aici pui ce nume vrei la baza de date ! Exemplu "KnifeKillsDB"


#define MAX 33
#define SAVE_DATA 10.0 // Aici modifici la cate secunde sa se introduca datele in DB , recomand 10 sec. ptr ca sa nu fie probleme

/* ------ [ Aici sunt setarile pentru hud, le modifici valorile daca ai nevoie ] ------*/

// Culori ( site : http://www.valmindesign.com/blog/web-design/coduri-culori/ )
#define ROSU 255
#define VERDE 215
#define ALBASTRU 0

//Aranajre pe axa xOy
#define XO 0.03  // stanga dreapta
#define YO 0.17  // sus jos


// aici modifici cum vr sa scrie in hud ; De exemplu : Kill Count : 5 
new const Text[]    = "Cutite date :";
new const Text2[]   = "Cutite Primite pe cocoasa :";

/* ------ [ Sfarsit setari hud ] ------*/

#if AMXX_VERSION_NUM < 190
    #define client_disconnected(%1) client_disconnect(%1)
#endif

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[33];
new CutitePrimite[33];

new SyncHudMessage;

/* ---------- [ Cvare ] ---------- */
new cvar;

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

    register_event("ResetHUD", "event_ResetHud", "be");
    RegisterHam(Ham_Spawn, "player", "Ham_PlayerSpawnedPost", 1);

    cvar = register_cvar("knife_kill", "1"); // nu modifica

    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_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 client_death(killer,victim,wpnindex) 
{
    static name_killer[33], name_victim[33];
    new iKill = get_pcvar_num(cvar);
    get_user_name(killer, name_killer, charsmax(name_killer));
    get_user_name(victim, name_victim, charsmax(name_victim));

    if(wpnindex != CSW_KNIFE || !is_user_connected(killer) || !is_user_connected(victim)) return;

    if(wpnindex == CSW_KNIFE)
    {
    CutiteDate[killer] += iKill;
    }

    if(victim == killer && wpnindex == CSW_KNIFE)
    {
    CutitePrimite[killer] += iKill;
    }
    else if(victim == killer && wpnindex != CSW_KNIFE) return;

    Save_MySql(killer);
    log_to_file("debug.txt", "%s l-a omorat pe %s cu cutitul si are acum are %d killuri si %d lame primite", name_killer, name_victim, CutiteDate[killer], CutitePrimite[killer]);

}


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(32),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[32], szTemp[512];
    get_user_authid(id, szSteamId, charsmax(szSteamId));
    
    new Data[1];
    Data[0] = id;

    format(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) < 2) 
    {
        
        new szSteamId[32];
        get_user_authid(id, szSteamId, charsmax(szSteamId));
        
        if (equal(szSteamId,"ID_PENDING"))
            return PLUGIN_HANDLED;
            
        new szTemp[512];
        
        format(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[32], szTemp[512];
    get_user_authid(id, szSteamId, charsmax(szSteamId));
    
    format(szTemp,charsmax(szTemp),"UPDATE `%s` SET `cutite_date` = '%i' AND `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_putinserver(id)    Load_MySql(id);

public client_disconnected(id)    Save_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];
    format(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;
}

Legat de hud :
C++:
Functia de setare hud : set_hudmessage(a,a,a,b,b,c,d,e,f,g,h);
Unde :
a = culori
b = coordonate hud xOy
c = efecte
d = durata efect
e = cat sta textul pe ecran
f = cat dureaza pana sa apara textul ! Gen fade-in
g = cat dureaza pana dispare efectul ! Gen fade-out
IMPORTANT ! h = canal text
Pe CS sunt permise doar 4 canale de text ; respectiv 4 mesaje hud
In functia din plg nostru avem :
C++:
set_hudmessage(ROSU, VERDE, ALBASTRU, XO, YO, 0, 0.5, 15.0, 2.0, 2.0, -1);
Unde canalul de text este -1 ! Adica pluginul detecteaza singur un slot liber si il foloseste, cat despre rata de refresh il pot face gen sa apara hudul cand faci un kill , dar o sa se buguiasca cred
 
Last edited:

B1zAr3

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

Incepe sa prinda forma :) cateva aspecte totusi :

1) Inregistreaza doar killurile, nu si pe cele primite

2) Dupa retry mi-a salvat o singura data datele - dar de cele mai multe ori pierde datele la disconect sau retry

3) MySql inregistreaza doar steamid-urile nu si kills/received

4) Daca poti cum ai pus cvarul ala "cvar = register_cvar("knife_kill", "1"); // " - pune te rog axele acolo sa le pot modifica din modmenu - momentan trebuie sa recompilez la fiecare schimbare :D de altfel nu e chiar sub radar :) motivul cerintei -
1618012160825.png


5) Faza cu intervalul de schimbare a killului in hud - ruland gungame dupa cateva secunde e singurul lucru care apare in hud - numai vezi cine e primul loc, doar atunci cand mori si te spawneaza ai cateva secunde in care le vezi si dupa dispar toate. Am si un plugin de schimbare roundtime hud in real time si ala e afectat - asa arata ora normal cateva secunde cand esti in viata
1618012687868.png
( Am observat o chestie - atunci cand este pe 0 - 0 toate mesaje sunt ok si apar - dupa primul kill - incepe problema.
Cred ca daca reusesti sa il faci sa inregistreze pe tabela doar atunci cand mori poate scapam de problema... asa el numai incearca sa updateze hud textul all the time interferand cu celelalte pluginuri.


Later edit : Am observat ca s-a creat in logs un fisier cu lamele primite date dar are numele de debug.txt- cred ca de acolo isi ia datele pentru rank knife nu ? credeam ca le ia din mysql


Toate cele bune,
Adrian
 
Last edited:

B1zAr3

leganar
Joined
Apr 8, 2011
Messages
60
Reaction score
4
Age
31
Location
Bucuresti
De curiozitate am retestat pluginul de la Napoleon - din primele posturi - si aparent ala nu interfereaza si se updateaza atunci cand mori :) poate reusesti sa il descrifezi si sa imprumuti ideea :D

Uite codul :

C++:
#include <amxmodx>
#include <nvault>

#pragma semicolon 1

#if !defined MAX_PLAYERS
    const MAX_PLAYERS = 32;
#endif

#if AMXX_VERSION_NUM < 183
    #define client_disconnected(%1) client_disconnect(%1)
#endif

new const szVersion[] = "1.0.0";

new iKnifeCount[MAX_PLAYERS + 1];

new iVault;

public plugin_init() {
      register_plugin("KnifeKillCount", szVersion, "NapoleoN#");

      register_clcmd("say /kc", "KnifeCount");

      register_event("DeathMsg", "eDeath", "a", "1>0", "1!2");

      iVault = nvault_open("KnifeKillCount");
}

public plugin_end() {
    nvault_close(iVault);
}

public client_authorized(id) {
    LoadData(id);
}

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

public client_disconnected(id)
{
    SaveData(id);
    // Remove task on disconnect? Sounds pointless lol.
}

public eDeath() {
    new iAttacker = read_data(1);
    new iClip, iAmmo, iWeapon;
    iWeapon = get_user_weapon(iAttacker, iClip, iAmmo);

    if(iWeapon == CSW_KNIFE && is_user_connected(iAttacker)) {
        iKnifeCount[iAttacker]++;
    }
}

public KnifeCount(id) {
    client_print(id, print_chat, "Knife KillCount: %i", iKnifeCount[id]);
}

public DisplayHud(id)
{
    if(is_user_connected(id))
    {
        set_hudmessage(200, 100, 0, -1.0, 0.35, 0, 0.0, 20.0, 0.0, 0.0, -1);
        show_hudmessage(id, "Knife KillCount: %i", iKnifeCount[id]);
    }
}

SaveData(id) {
    new szAuth[35], szTemp[10];
    get_user_authid(id, szAuth, charsmax(szAuth));

    formatex(szTemp, charsmax(szTemp), "%i", iKnifeCount[id]);

    nvault_set(iVault, szAuth, szTemp);
}

LoadData(id) {
    new szAuth[35], szKillCount[10], szTemp[10];
    get_user_authid(id, szAuth, charsmax(szAuth));

    nvault_get(iVault, szAuth, szTemp, charsmax(szTemp));

    parse(szTemp, szKillCount, charsmax(szKillCount));

    iKnifeCount[id] = str_to_num(szKillCount);
}
 

SenorAMXX

ze.laleagane.ro
Joined
May 3, 2018
Messages
151
Reaction score
211
Age
17
Location
/var/tmp
Salvarea in nVault duce la pagube . . . O sa incerc sa iti transfor integrele in stringuri ca sa poata fi adaugate mai usor , revin cu reply
 
Status
Subiectul a fost blocat si nu sunt permise comentarii ulterioare.
shape1
shape2
shape3
shape4
shape5
shape6
Top