This site is a testing version, but all data is shared with the live forum.


Raised This Month: $ Target: $400
 0% 

rank sqlite


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
yagami
Senior Member
Join Date: Jan 2021
Old 09-23-2023 , 23:24   rank sqlite
Reply With Quote #1

This was supposed to show a rank, but I'm lost inside the for, does anyone know what the next step is?

PHP Code:
public OnTop15Command(id)
{
    new 
top[TOP_PLAYERS_LENGTH][TopPlayersEnum];

    new 
total SQLQuery_GetTopPlayers(topsizeof top);

    for (new 
0totali++)
    {
        
/*
            Available variables:

            top[i][tpClanName]
            top[i][tpClanTag]
            top[i][tpName]
            top[i][tpAuthid]
            top[i][tpIP]
            top[i][tpXP]
            top[i][tpKills]
            top[i][tpDeaths]
            top[i][tpCaptures]
            top[i][tpDefenses]
            top[i][tpPosition]
        */

        
console_print(id"%dº | %s | %d/%d"top[i][tpPosition], top[i][tpName], top[i][tpKills], top[i][tpDeaths]);
    }

    
log("OnTop15Command(id: %d) total: %d"idtotal);
}


public 
OnTopClansCommand(id)
{
    new 
top[TOP_CLANS_LENGTH][TopClansEnum];

    new 
total SQLQuery_GetTopClans(topsizeof top);

    for (new 
0totali++)
    {
        
/*
            Available variables:

            top[i][tcName]
            top[i][tcTag]
            top[i][tcMembersCount]
            top[i][tcTotalXP]
            top[i][tcTotalKills]
            top[i][tcTotalDeaths]
            top[i][tcTotalCaptures]
            top[i][tcTotalDefenses]
            top[i][tcPosition]
        */

        
console_print(id"%dº | TAG: %s | CLAN: %s | XP: %d | MEMBROS: %d"top[i][tcPosition], top[i][tcName], top[i][tcTag], top[i][tcTotalXP], top[i][tcMembersCount]);
    }

    
log("OnTopClansCommand(id: %d) total: %d"idtotal);

yagami is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 09-24-2023 , 15:20   Re: rank sqlite
Reply With Quote #2

show how you declared the enum with tcName, tcTag .. etc
lexzor is offline
yagami
Senior Member
Join Date: Jan 2021
Old 09-24-2023 , 22:41   Re: rank sqlite
Reply With Quote #3

Quote:
Originally Posted by lexzor View Post
show how you declared the enum with tcName, tcTag .. etc
My mistake for not sending everything

PHP Code:
#include <amxmodx>
#include <hamsandwich>
#include <regex>
#include <sqlx>
#include <jctf>


#define SQLITE_DATABASE_NAME "clan_management"
#define TOP_PLAYERS_LENGTH 15
#define TOP_CLANS_LENGTH 10


enum _:PlayerEnum
{
    
bool:pIsAuthorized,
    
bool:pIsConnected,
    
bool:pIsAuthenticated,
    
bool:pIsWaitingLoginAttemptResponse,
    
bool:pRegisterPlayerIfNotFound,
    
bool:pShowRegisterOption,

    
pName[MAX_NAME_LENGTH],
    
pAuthid[MAX_AUTHID_LENGTH],
    
pIP[MAX_IP_LENGTH],
    
pLogin[128],
    
pPassword[128],
    
pJoinedClanAtDate[12],
    
pInviteCode[MAX_INVITE_CODE_LENGTH],

    
pTemporaryClanName[MAX_CLAN_NAME_LENGTH],
    
pTemporaryClanTag[MAX_CLAN_TAG_LENGTH],

    
pClanId,
    
pClanPrivilegies,
    
pID,
    
pXP,
    
pKills,
    
pDeaths,
    
pCaptures,
    
pDefenses,

}

public 
Player[MAX_PLAYERS 1][PlayerEnum];

enum _:TopPlayersEnum
{
    
tpClanName[MAX_CLAN_NAME_LENGTH],
    
tpClanTag[MAX_CLAN_TAG_LENGTH],

    
tpName[MAX_NAME_LENGTH],
    
tpAuthid[MAX_AUTHID_LENGTH],
    
tpIP[MAX_IP_LENGTH],
    
    
tpXP,
    
tpKills,
    
tpDeaths,
    
tpCaptures,
    
tpDefenses,
    
tpPosition
}


enum _:TopClansEnum
{
    
tcName[MAX_CLAN_NAME_LENGTH],
    
tcTag[MAX_CLAN_TAG_LENGTH],

    
tcMembersCount,
    
tcTotalXP,
    
tcTotalKills,
    
tcTotalDeaths,
    
tcTotalCaptures,
    
tcTotalDefenses,
    
tcPosition
}

public 
jctf_flag(iEventidiFlagTeambool:bAssist)
{
    new 
top[TOP_PLAYERS_LENGTH][TopPlayersEnum]

    switch(
iEvent)
    {
        case 
FLAG_CAPTURED:
        {
            if(!
bAssist)
            {
                
top[id][pCaptures]++
            }
            
log("OnTop15Rank(id: %d) total: %d"idtop[id][pCaptures]);
        }
        case 
FLAG_STOLEN:
        {
            if(!
bAssist)
            {
                
top[id][tpDefenses]++
            }
            
log("OnTop15Rank(id: %d) total: %d"idtop[id][pCaptures]);
        }
    }
    
savePlayerData(id)
}

public 
OnTop15Command(id)
{
    new 
top[TOP_PLAYERS_LENGTH][TopPlayersEnum];

    new 
total SQLQuery_GetTopPlayers(topsizeof top);

    for (new 
0totali++)
    {
        
/*
            Variáveis disponíveis:

            top[i][tpClanName]
            top[i][tpClanTag]
            top[i][tpName]
            top[i][tpAuthid]
            top[i][tpIP]
            top[i][tpXP]
            top[i][tpKills]
            top[i][tpDeaths]
            top[i][tpCaptures]
            top[i][tpDefenses]
            top[i][tpPosition]
        */

        
console_print(id"%dº | %s | %d/%d"top[i][tpPosition], top[i][tpName], top[i][tpKills], top[i][tpDeaths]);
    }

    
log("OnTop15Command(id: %d) total: %d"idtotal);
}


public 
OnTopClansCommand(id)
{
    new 
top[TOP_CLANS_LENGTH][TopClansEnum];

    new 
total SQLQuery_GetTopClans(topsizeof top);

    for (new 
0totali++)
    {
        
/*
            Variáveis disponíveis:

            top[i][tcName]
            top[i][tcTag]
            top[i][tcMembersCount]
            top[i][tcTotalXP]
            top[i][tcTotalKills]
            top[i][tcTotalDeaths]
            top[i][tcTotalCaptures]
            top[i][tcTotalDefenses]
            top[i][tcPosition]
        */

        
console_print(id"%dº | TAG: %s | CLAN: %s | XP: %d | MEMBROS: %d"top[i][tcPosition], top[i][tcName], top[i][tcTag], top[i][tcTotalXP], top[i][tcMembersCount]);
    }

    
log("OnTopClansCommand(id: %d) total: %d"idtotal);
}

public 
client_putinserver(id)
{
    
Player[id][pIsConnected] = bool:is_user_connected(id);

    
loadPlayerData(id);
}


public 
client_authorized(id)
{
    
Player[id][pIsAuthorized] = true;

    
loadPlayerData(id);
}


public 
client_disconnected(id)
{
    
Player[id][pIsConnected] = false;
    
    
savePlayerData(id);

    
ArrayDestroy(Player[id][pNotifications]);
}

loadPlayerData(id)
{
    if (!
Player[id][pIsConnected] || !Player[id][pIsAuthorized])
    {
        
log("loadPlayerData(id: %d) => Não conectado ou autorizado. connected: %d, auth: %d"idPlayer[id][pIsConnected], Player[id][pIsAuthorized]);
        return;
    }

    
get_user_name(idPlayer[id][pName], charsmax(Player[][pName]));
    
get_user_authid(idPlayer[id][pAuthid], charsmax(Player[][pAuthid]));
    
get_user_ip(idPlayer[id][pIP], charsmax(Player[][pIP]));

    if (!
validateCredentials(id))
    {
        if (
Player[id][pIsWaitingLoginAttemptResponse])
        {
            
client_print_color(idprint_team_red"%s^3 Não foi possível carregar seus dados. Erro ao validar credenciais."CHAT_TAG);

            
Player[id][pIsWaitingLoginAttemptResponse] = false;
        }

        
log("loadPlayerData(id: %d) => Erro ao validar credenciais. Tipo: %d"idcvarAuthenticationType);

        return;
    }

    
log("loadPlayerData(id: %d) => Consultando player"id);

    
SQLQuery_FetchPlayer(id);
}


savePlayerData(id)
{
    if (!
Player[id][pIsAuthenticated])
    {
        
log("savePlayerData(id: %d) => Salvamento nao autorizado"id);
        return;
    }

    
SQLQuery_SavePlayer(id);
}

SQLQuery_SavePlayer(id)
{
    
formatex(Querycharsmax(Query),
        
"UPDATE players_stats SET \
            xp = %d, \
            kills = %d, \
            deaths = %d, \
            captures = %d, \
            defenses = %d \
        WHERE \
            player_id = %d; \
        UPDATE players SET \
            last_seen = CURRENT_TIMESTAMP \
        WHERE \
            id = %d"
,
        
Player[id][pXP],
        
Player[id][pKills],
        
Player[id][pDeaths],
        
Player[id][pCaptures],
        
Player[id][pDefenses],
        
Player[id][pID],
        
Player[id][pID]
    );

    
log("SQLQuery_SavePlayer(id: %d) => %s"idQuery);

    
SQL_ThreadQuery(DatabaseHandle"@SQLCallback_Ignore"Query);
}

SQLQuery_GetTopPlayers(top[][TopPlayersEnum], length)
{
    new 
Handle:query SQL_PrepareQuery(DatabaseConnectionHandle,
        
"SELECT \
            c.name, \
            c.tag, \
            p.name, \
            p.authid, \
            p.ip, \
            s.xp, \
            s.kills, \
            s.deaths, \
            s.captures, \
            s.defenses \
        FROM players p \
        INNER JOIN players_stats s \
            ON s.player_id = p.id \
        LEFT JOIN clans_members cm \
            ON cm.player_id = p.id AND cm.status = 1 \
        LEFT JOIN clans c \
            ON c.id = cm.clan_id AND c.status = 1 \
        ORDER BY \
            s.kills DESC, \
            s.deaths ASC \
        LIMIT %d"
,
        
length
    
);

    new 
0;

    if (!
SQL_Execute(query))
    {
        new 
error[128];

        
SQL_QueryError(queryerrorcharsmax(error));

        
log("SQLQuery_GetTopPlayers() erro na query: %s"error);
        return 
0;
    }

    while (
SQL_MoreResults(query))
    {
        
SQL_ReadResult(query0top[i][tpClanName], charsmax(top[][tpClanName]));
        
SQL_ReadResult(query1top[i][tpClanTag], charsmax(top[][tpClanTag]));
        
SQL_ReadResult(query2top[i][tpName], charsmax(top[][tpName]));
        
SQL_ReadResult(query3top[i][tpAuthid], charsmax(top[][tpAuthid]));
        
SQL_ReadResult(query4top[i][tpIP], charsmax(top[][tpIP]));
        
        
top[i][tpXP] = SQL_ReadResult(query5);
        
top[i][tpKills] = SQL_ReadResult(query6);
        
top[i][tpDeaths] = SQL_ReadResult(query7);
        
top[i][tpCaptures] = SQL_ReadResult(query8);
        
top[i][tpDefenses] = SQL_ReadResult(query9);
        
        
top[i][tpPosition] = ++i;

        
SQL_NextRow(query);
    }

    return 
i;
}


SQLQuery_GetTopClans(top[][TopClansEnum], length)
{
    new 
Handle:query SQL_PrepareQuery(DatabaseConnectionHandle,
        
"SELECT \
            c.name, \
            c.tag, \
            SUM(s.xp), \
            SUM(s.kills), \
            SUM(s.deaths), \
            SUM(s.captures), \
            SUM(s.defenses), \
            COUNT(cm.player_id) \
        FROM clans c \
        INNER JOIN clans_members cm \
            ON cm.clan_id = c.id AND cm.status = 1 \
        INNER JOIN players_stats s \
            ON s.player_id = cm.player_id \
        GROUP BY \
            c.id \
        ORDER BY \
            SUM(s.xp) DESC, \
            SUM(s.kills) DESC, \
            SUM(s.deaths) ASC \
        LIMIT %d"
,
        
length
    
);

    new 
0;

    if (!
SQL_Execute(query))
    {
        new 
error[128];

        
SQL_QueryError(queryerrorcharsmax(error));

        
log("SQLQuery_GetTopClans() erro na query: %s"error);
        return 
0;
    }

    while (
SQL_MoreResults(query))
    {
        
SQL_ReadResult(query0top[i][tcName], charsmax(top[][tcName]));
        
SQL_ReadResult(query1top[i][tcTag], charsmax(top[][tcTag]));
        
        
top[i][tcTotalXP] = SQL_ReadResult(query2);
        
top[i][tcTotalKills] = SQL_ReadResult(query3);
        
top[i][tcTotalDeaths] = SQL_ReadResult(query4);
        
top[i][tcTotalCaptures] = SQL_ReadResult(query5);
        
top[i][tcTotalDefenses] = SQL_ReadResult(query6);
        
top[i][tcMembersCount] = SQL_ReadResult(query7);
        
        
top[i][tcPosition] = ++i;

        
SQL_NextRow(query);
    }

    return 
i;

yagami is offline
yagami
Senior Member
Join Date: Jan 2021
Old 09-24-2023 , 23:18   Re: rank sqlite
Reply With Quote #4

Quote:
Originally Posted by yagami View Post
My mistake for not sending everything

PHP Code:
#include <amxmodx>
#include <hamsandwich>
#include <regex>
#include <sqlx>
#include <jctf>


#define SQLITE_DATABASE_NAME "clan_management"
#define TOP_PLAYERS_LENGTH 15
#define TOP_CLANS_LENGTH 10


enum _:PlayerEnum
{
    
bool:pIsAuthorized,
    
bool:pIsConnected,
    
bool:pIsAuthenticated,
    
bool:pIsWaitingLoginAttemptResponse,
    
bool:pRegisterPlayerIfNotFound,
    
bool:pShowRegisterOption,

    
pName[MAX_NAME_LENGTH],
    
pAuthid[MAX_AUTHID_LENGTH],
    
pIP[MAX_IP_LENGTH],
    
pLogin[128],
    
pPassword[128],
    
pJoinedClanAtDate[12],
    
pInviteCode[MAX_INVITE_CODE_LENGTH],

    
pTemporaryClanName[MAX_CLAN_NAME_LENGTH],
    
pTemporaryClanTag[MAX_CLAN_TAG_LENGTH],

    
pClanId,
    
pClanPrivilegies,
    
pID,
    
pXP,
    
pKills,
    
pDeaths,
    
pCaptures,
    
pDefenses,

}

public 
Player[MAX_PLAYERS 1][PlayerEnum];

enum _:TopPlayersEnum
{
    
tpClanName[MAX_CLAN_NAME_LENGTH],
    
tpClanTag[MAX_CLAN_TAG_LENGTH],

    
tpName[MAX_NAME_LENGTH],
    
tpAuthid[MAX_AUTHID_LENGTH],
    
tpIP[MAX_IP_LENGTH],
    
    
tpXP,
    
tpKills,
    
tpDeaths,
    
tpCaptures,
    
tpDefenses,
    
tpPosition
}


enum _:TopClansEnum
{
    
tcName[MAX_CLAN_NAME_LENGTH],
    
tcTag[MAX_CLAN_TAG_LENGTH],

    
tcMembersCount,
    
tcTotalXP,
    
tcTotalKills,
    
tcTotalDeaths,
    
tcTotalCaptures,
    
tcTotalDefenses,
    
tcPosition
}

public 
jctf_flag(iEventidiFlagTeambool:bAssist)
{
    new 
top[TOP_PLAYERS_LENGTH][TopPlayersEnum]

    switch(
iEvent)
    {
        case 
FLAG_CAPTURED:
        {
            if(!
bAssist)
            {
                
top[id][pCaptures]++
            }
            
log("OnTop15Rank(id: %d) total: %d"idtop[id][pCaptures]);
        }
        case 
FLAG_STOLEN:
        {
            if(!
bAssist)
            {
                
top[id][tpDefenses]++
            }
            
log("OnTop15Rank(id: %d) total: %d"idtop[id][pCaptures]);
        }
    }
    
savePlayerData(id)
}

public 
OnTop15Command(id)
{
    new 
top[TOP_PLAYERS_LENGTH][TopPlayersEnum];

    new 
total SQLQuery_GetTopPlayers(topsizeof top);

    for (new 
0totali++)
    {
        
/*
            Variáveis disponíveis:

            top[i][tpClanName]
            top[i][tpClanTag]
            top[i][tpName]
            top[i][tpAuthid]
            top[i][tpIP]
            top[i][tpXP]
            top[i][tpKills]
            top[i][tpDeaths]
            top[i][tpCaptures]
            top[i][tpDefenses]
            top[i][tpPosition]
        */

        
console_print(id"%dº | %s | %d/%d"top[i][tpPosition], top[i][tpName], top[i][tpKills], top[i][tpDeaths]);
    }

    
log("OnTop15Command(id: %d) total: %d"idtotal);
}


public 
OnTopClansCommand(id)
{
    new 
top[TOP_CLANS_LENGTH][TopClansEnum];

    new 
total SQLQuery_GetTopClans(topsizeof top);

    for (new 
0totali++)
    {
        
/*
            Variáveis disponíveis:

            top[i][tcName]
            top[i][tcTag]
            top[i][tcMembersCount]
            top[i][tcTotalXP]
            top[i][tcTotalKills]
            top[i][tcTotalDeaths]
            top[i][tcTotalCaptures]
            top[i][tcTotalDefenses]
            top[i][tcPosition]
        */

        
console_print(id"%dº | TAG: %s | CLAN: %s | XP: %d | MEMBROS: %d"top[i][tcPosition], top[i][tcName], top[i][tcTag], top[i][tcTotalXP], top[i][tcMembersCount]);
    }

    
log("OnTopClansCommand(id: %d) total: %d"idtotal);
}

public 
client_putinserver(id)
{
    
Player[id][pIsConnected] = bool:is_user_connected(id);

    
loadPlayerData(id);
}


public 
client_authorized(id)
{
    
Player[id][pIsAuthorized] = true;

    
loadPlayerData(id);
}


public 
client_disconnected(id)
{
    
Player[id][pIsConnected] = false;
    
    
savePlayerData(id);

    
ArrayDestroy(Player[id][pNotifications]);
}

loadPlayerData(id)
{
    if (!
Player[id][pIsConnected] || !Player[id][pIsAuthorized])
    {
        
log("loadPlayerData(id: %d) => Não conectado ou autorizado. connected: %d, auth: %d"idPlayer[id][pIsConnected], Player[id][pIsAuthorized]);
        return;
    }

    
get_user_name(idPlayer[id][pName], charsmax(Player[][pName]));
    
get_user_authid(idPlayer[id][pAuthid], charsmax(Player[][pAuthid]));
    
get_user_ip(idPlayer[id][pIP], charsmax(Player[][pIP]));

    if (!
validateCredentials(id))
    {
        if (
Player[id][pIsWaitingLoginAttemptResponse])
        {
            
client_print_color(idprint_team_red"%s^3 Não foi possível carregar seus dados. Erro ao validar credenciais."CHAT_TAG);

            
Player[id][pIsWaitingLoginAttemptResponse] = false;
        }

        
log("loadPlayerData(id: %d) => Erro ao validar credenciais. Tipo: %d"idcvarAuthenticationType);

        return;
    }

    
log("loadPlayerData(id: %d) => Consultando player"id);

    
SQLQuery_FetchPlayer(id);
}


savePlayerData(id)
{
    if (!
Player[id][pIsAuthenticated])
    {
        
log("savePlayerData(id: %d) => Salvamento nao autorizado"id);
        return;
    }

    
SQLQuery_SavePlayer(id);
}

SQLQuery_SavePlayer(id)
{
    
formatex(Querycharsmax(Query),
        
"UPDATE players_stats SET \
            xp = %d, \
            kills = %d, \
            deaths = %d, \
            captures = %d, \
            defenses = %d \
        WHERE \
            player_id = %d; \
        UPDATE players SET \
            last_seen = CURRENT_TIMESTAMP \
        WHERE \
            id = %d"
,
        
Player[id][pXP],
        
Player[id][pKills],
        
Player[id][pDeaths],
        
Player[id][pCaptures],
        
Player[id][pDefenses],
        
Player[id][pID],
        
Player[id][pID]
    );

    
log("SQLQuery_SavePlayer(id: %d) => %s"idQuery);

    
SQL_ThreadQuery(DatabaseHandle"@SQLCallback_Ignore"Query);
}

SQLQuery_GetTopPlayers(top[][TopPlayersEnum], length)
{
    new 
Handle:query SQL_PrepareQuery(DatabaseConnectionHandle,
        
"SELECT \
            c.name, \
            c.tag, \
            p.name, \
            p.authid, \
            p.ip, \
            s.xp, \
            s.kills, \
            s.deaths, \
            s.captures, \
            s.defenses \
        FROM players p \
        INNER JOIN players_stats s \
            ON s.player_id = p.id \
        LEFT JOIN clans_members cm \
            ON cm.player_id = p.id AND cm.status = 1 \
        LEFT JOIN clans c \
            ON c.id = cm.clan_id AND c.status = 1 \
        ORDER BY \
            s.kills DESC, \
            s.deaths ASC \
        LIMIT %d"
,
        
length
    
);

    new 
0;

    if (!
SQL_Execute(query))
    {
        new 
error[128];

        
SQL_QueryError(queryerrorcharsmax(error));

        
log("SQLQuery_GetTopPlayers() erro na query: %s"error);
        return 
0;
    }

    while (
SQL_MoreResults(query))
    {
        
SQL_ReadResult(query0top[i][tpClanName], charsmax(top[][tpClanName]));
        
SQL_ReadResult(query1top[i][tpClanTag], charsmax(top[][tpClanTag]));
        
SQL_ReadResult(query2top[i][tpName], charsmax(top[][tpName]));
        
SQL_ReadResult(query3top[i][tpAuthid], charsmax(top[][tpAuthid]));
        
SQL_ReadResult(query4top[i][tpIP], charsmax(top[][tpIP]));
        
        
top[i][tpXP] = SQL_ReadResult(query5);
        
top[i][tpKills] = SQL_ReadResult(query6);
        
top[i][tpDeaths] = SQL_ReadResult(query7);
        
top[i][tpCaptures] = SQL_ReadResult(query8);
        
top[i][tpDefenses] = SQL_ReadResult(query9);
        
        
top[i][tpPosition] = ++i;

        
SQL_NextRow(query);
    }

    return 
i;
}


SQLQuery_GetTopClans(top[][TopClansEnum], length)
{
    new 
Handle:query SQL_PrepareQuery(DatabaseConnectionHandle,
        
"SELECT \
            c.name, \
            c.tag, \
            SUM(s.xp), \
            SUM(s.kills), \
            SUM(s.deaths), \
            SUM(s.captures), \
            SUM(s.defenses), \
            COUNT(cm.player_id) \
        FROM clans c \
        INNER JOIN clans_members cm \
            ON cm.clan_id = c.id AND cm.status = 1 \
        INNER JOIN players_stats s \
            ON s.player_id = cm.player_id \
        GROUP BY \
            c.id \
        ORDER BY \
            SUM(s.xp) DESC, \
            SUM(s.kills) DESC, \
            SUM(s.deaths) ASC \
        LIMIT %d"
,
        
length
    
);

    new 
0;

    if (!
SQL_Execute(query))
    {
        new 
error[128];

        
SQL_QueryError(queryerrorcharsmax(error));

        
log("SQLQuery_GetTopClans() erro na query: %s"error);
        return 
0;
    }

    while (
SQL_MoreResults(query))
    {
        
SQL_ReadResult(query0top[i][tcName], charsmax(top[][tcName]));
        
SQL_ReadResult(query1top[i][tcTag], charsmax(top[][tcTag]));
        
        
top[i][tcTotalXP] = SQL_ReadResult(query2);
        
top[i][tcTotalKills] = SQL_ReadResult(query3);
        
top[i][tcTotalDeaths] = SQL_ReadResult(query4);
        
top[i][tcTotalCaptures] = SQL_ReadResult(query5);
        
top[i][tcTotalDefenses] = SQL_ReadResult(query6);
        
top[i][tcMembersCount] = SQL_ReadResult(query7);
        
        
top[i][tcPosition] = ++i;

        
SQL_NextRow(query);
    }

    return 
i;


I wanted to gank the best clans based on XP, and also which clan has the most kills, the most flags captured,

as well as the best playewr of each clan

Last edited by yagami; 09-24-2023 at 23:18.
yagami is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 09-25-2023 , 06:38   Re: rank sqlite
Reply With Quote #5

Code:
/**     TopPlayersEnum should be defined only with stats enum     here it's a bad logic, you are putting in the same enum players info (name id authid) with his top stats     to not create another enum, i changed a little their position in enum     you can take a look in the loop from OnTop15Command function to understand why this is a must  */ enum _:TopPlayersEnum {     tpAuthid[MAX_AUTHID_LENGTH],     tpIP[MAX_IP_LENGTH],     tpName[MAX_NAME_LENGTH],         tpClanName[MAX_CLAN_NAME_LENGTH],     tpClanTag[MAX_CLAN_TAG_LENGTH],     tpXP,     tpKills,     tpDeaths,     tpCaptures,     tpDefenses,     tpPosition } static const STATS_NAME[][] = {     "",     "",     "",     "Clan name",     "Clan tag",     "Experience",     "Kills",     "Deaths",     "Captures",     "Defenses",     "Position", } public OnTop15Command(id) {     new top[TOP_PLAYERS_LENGTH][TopPlayersEnum], szOutput[512], iLen;     SQLQuery_GetTopPlayers(top, sizeof top); // here you don't need the total variable because you already know the top max size is TOP_PLAYERS_LENGTH     for(new iTopPlayer; iTopPlayer < sizeof top; iTopPlayer++) // for every player from top we are reading his stats     {         iLen = formatex(szOutput[iLen], charsmax(szOutput), "Stats for %s:^n%s: %s^n%s: %s",         top[iTopPlayer][tpName], STATS_NAME[tpClanName], top[iTopPlayer][tpClanName], STATS_NAME[tpClanTag], top[iTopPlayer][tpClanTag])         for (new iStat = tpXP, iLen; i < TopPlayersEnum; iStat++)         {             iLen = formatex(szOutput[iLen], charsmax(szOutput), "^n%s - %i", STATS_NAME[iStat], top[iTopPlayer][iStat])         }         server_print("%s", szOutput)             iLen = 0     } }

Last edited by lexzor; 09-25-2023 at 06:39.
lexzor is offline
yagami
Senior Member
Join Date: Jan 2021
Old 09-25-2023 , 17:10   Re: rank sqlite
Reply With Quote #6

Quote:
Originally Posted by lexzor View Post
Code:
/**     TopPlayersEnum should be defined only with stats enum     here it's a bad logic, you are putting in the same enum players info (name id authid) with his top stats     to not create another enum, i changed a little their position in enum     you can take a look in the loop from OnTop15Command function to understand why this is a must  */ enum _:TopPlayersEnum {     tpAuthid[MAX_AUTHID_LENGTH],     tpIP[MAX_IP_LENGTH],     tpName[MAX_NAME_LENGTH],         tpClanName[MAX_CLAN_NAME_LENGTH],     tpClanTag[MAX_CLAN_TAG_LENGTH],     tpXP,     tpKills,     tpDeaths,     tpCaptures,     tpDefenses,     tpPosition } static const STATS_NAME[][] = {     "",     "",     "",     "Clan name",     "Clan tag",     "Experience",     "Kills",     "Deaths",     "Captures",     "Defenses",     "Position", } public OnTop15Command(id) {     new top[TOP_PLAYERS_LENGTH][TopPlayersEnum], szOutput[512], iLen;     SQLQuery_GetTopPlayers(top, sizeof top); // here you don't need the total variable because you already know the top max size is TOP_PLAYERS_LENGTH     for(new iTopPlayer; iTopPlayer < sizeof top; iTopPlayer++) // for every player from top we are reading his stats     {         iLen = formatex(szOutput[iLen], charsmax(szOutput), "Stats for %s:^n%s: %s^n%s: %s",         top[iTopPlayer][tpName], STATS_NAME[tpClanName], top[iTopPlayer][tpClanName], STATS_NAME[tpClanTag], top[iTopPlayer][tpClanTag])         for (new iStat = tpXP, iLen; i < TopPlayersEnum; iStat++)         {             iLen = formatex(szOutput[iLen], charsmax(szOutput), "^n%s - %i", STATS_NAME[iStat], top[iTopPlayer][iStat])         }         server_print("%s", szOutput)             iLen = 0     } }

In fact, I think I was wrong to put it all together There would be two rankings, the first and a ranking with the best clans, so the XP was made for that to classify the best, but now I don't know how to give this XP or calculate it because there are kills, deaths, flags
yagami is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 09-25-2023 , 17:52   Re: rank sqlite
Reply With Quote #7

you can use

Code:
    "Kills",     "Deaths",     "Captures",     "Defenses",     "Position",

only for user statistics,

you can set a hardcoded number of experience to give to player after some events

anyways, the reason why i posted it was only to show you how to parse in a loop an array if it is declared using an enum

Last edited by lexzor; 09-25-2023 at 17:52.
lexzor is offline
yagami
Senior Member
Join Date: Jan 2021
Old 09-27-2023 , 09:43   Re: rank sqlite
Reply With Quote #8

Quote:
Originally Posted by lexzor View Post
Code:
/**     TopPlayersEnum should be defined only with stats enum     here it's a bad logic, you are putting in the same enum players info (name id authid) with his top stats     to not create another enum, i changed a little their position in enum     you can take a look in the loop from OnTop15Command function to understand why this is a must  */ enum _:TopPlayersEnum {     tpAuthid[MAX_AUTHID_LENGTH],     tpIP[MAX_IP_LENGTH],     tpName[MAX_NAME_LENGTH],         tpClanName[MAX_CLAN_NAME_LENGTH],     tpClanTag[MAX_CLAN_TAG_LENGTH],     tpXP,     tpKills,     tpDeaths,     tpCaptures,     tpDefenses,     tpPosition } static const STATS_NAME[][] = {     "",     "",     "",     "Clan name",     "Clan tag",     "Experience",     "Kills",     "Deaths",     "Captures",     "Defenses",     "Position", } public OnTop15Command(id) {     new top[TOP_PLAYERS_LENGTH][TopPlayersEnum], szOutput[512], iLen;     SQLQuery_GetTopPlayers(top, sizeof top); // here you don't need the total variable because you already know the top max size is TOP_PLAYERS_LENGTH     for(new iTopPlayer; iTopPlayer < sizeof top; iTopPlayer++) // for every player from top we are reading his stats     {         iLen = formatex(szOutput[iLen], charsmax(szOutput), "Stats for %s:^n%s: %s^n%s: %s",         top[iTopPlayer][tpName], STATS_NAME[tpClanName], top[iTopPlayer][tpClanName], STATS_NAME[tpClanTag], top[iTopPlayer][tpClanTag])         for (new iStat = tpXP, iLen; i < TopPlayersEnum; iStat++)         {             iLen = formatex(szOutput[iLen], charsmax(szOutput), "^n%s - %i", STATS_NAME[iStat], top[iTopPlayer][iStat])         }         server_print("%s", szOutput)             iLen = 0     } }


What would it be like to do this rank in modt within looop?
yagami is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 09-27-2023 , 10:57   Re: rank sqlite
Reply With Quote #9

the way i show you, format motd string in loop then use it in motd
lexzor is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 23:57.


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