Raised This Month: $12 Target: $400
 3% 

Rank, possibility lag?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
spamipolito
Junior Member
Join Date: Jun 2018
Old 06-15-2020 , 12:48   Rank, possibility lag?
Reply With Quote #1

Hi guys. I wanted to know if this way of obtaining rank can cause server lag. Sorry for my english :c

PHP Code:
public clcmd__Rank(id)
{                    
    static 
iData[1
     
    
formatex(g_szQuerycharsmaxg_szQuery ), "SELECT * FROM %s ORDER BY `Level` DESC, `KILLS` DESC"szTableData

    
iData[0] = id 
    mysql_query
(g_Connection"rankMe"g_szQueryiData1


public 
rankMe(failstateerror[], errnumdata[], sizeFloat:queuetime) {  
    if(
failstate == TQUERY_CONNECT_FAILED || failstate == TQUERY_QUERY_FAILED) {  
        
log_to_file"SQL_LOG_TQ.txt""Error en la consulta al MySQL [%i]: %s"errnumerror );
        return 
    } 
    else { 
        static 
idid data[0]

        if(
mysql_num_results())
        { 
            static 
CountCharacter[33]

            
Count 0
             
            WPN_MAXTOP 
mysql_num_results()
             
            for(new 
0;Count;i++)
                
mysql_next_row()
             
            while(
mysql_more_results())
            { 
                if(
Count WPN_MAXTOP)
                {             
                    
mysql_read_result(mysql_fieldnametonum("Character"), Character32)
                    
                    if (
equal(Characterg_playername[id]))
                    {
                        
colorChat(id_"!g[%s]!y Rank position:!g %d / %d"COMMUNITYCount+1WPN_MAXTOP)
                        
mysql_next_row()
                        break;
                    }
                    
                    
Count++ 
                         
                    
mysql_next_row() 

                } 
                else 
                    break; 
            }
        }
    } 


Last edited by spamipolito; 06-15-2020 at 12:48.
spamipolito is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 06-15-2020 , 17:46   Re: Rank, possibility lag?
Reply With Quote #2

Use threaded queries: https://forums.alliedmods.net/showthread.php?t=46779
__________________
Bugsy is offline
+ARUKARI-
AlliedModders Donor
Join Date: Jul 2004
Location: Japan
Old 06-15-2020 , 21:21   Re: Rank, possibility lag?
Reply With Quote #3

Use the AuthID as a key to narrow down the results to one.
__________________
GitHub
SteamWishlist

六四天安門事件
+ARUKARI- is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 06-15-2020 , 21:45   Re: Rank, possibility lag?
Reply With Quote #4

Oh, I didn't even look at the SQL, lol. Put as much filtering criteria as possible.
__________________
Bugsy is offline
spamipolito
Junior Member
Join Date: Jun 2018
Old 06-15-2020 , 22:41   Re: Rank, possibility lag?
Reply With Quote #5

Solution:

PHP Code:
public clcmd__Rank(const id)

    static 
iData[1];
    
formatex(g_szQuerycharsmaxg_szQuery ), "select * from ( select T.*,(@rownum := @rownum + 1) as posicion from ( select * from %s group by PJ_ID order by Level DESC, KILLS DESC ) as T JOIN (SELECT @rownum := 0) r ) as w where PJ_ID = ^"%d^""szTableDatag_CharacterID[id]);

    
iData[0] = id;
    
mysql_query(g_Connection"show__Rank"g_szQueryiData1);
}

public 
show__Rank(failstateerror[], errnumdata[], sizeFloat:queuetime)  
{  
    if(
failstate == TQUERY_CONNECT_FAILED || failstate == TQUERY_QUERY_FAILED)  
    {  
        
log_to_file"SQL_LOG_TQ.txt""Error en la consulta al MySQL [%i]: %s"errnumerror );
        return;
    }
    else
    {
        new 
id data[0]

        
g__RankPosition[id] = mysql_read_result(mysql_fieldnametonum("posicion"))    

        
colorChat(id_"!g[%s]!y Rank position #%i / #%d"COMMUNITYg__RankPosition[id], g__GlobalTotalCharacters)
    }


Last edited by spamipolito; 06-15-2020 at 22:42.
spamipolito is offline
+ARUKARI-
AlliedModders Donor
Join Date: Jul 2004
Location: Japan
Old 06-15-2020 , 22:49   Re: Rank, possibility lag?
Reply With Quote #6

Show us the table layout.
The id changes when the player is connected timing.
Use the SteamID that you can get with get_user_authid.
__________________
GitHub
SteamWishlist

六四天安門事件
+ARUKARI- is offline
spamipolito
Junior Member
Join Date: Jun 2018
Old 06-15-2020 , 23:31   Re: Rank, possibility lag?
Reply With Quote #7

Quote:
Originally Posted by +ARUKARI- View Post
Show us the table layout.
The id changes when the player is connected timing.
Use the SteamID that you can get with get_user_authid.
I use account system with multiple characters. Example: Account "Covid19" Characters: ("William", "Robert", "Analisa Melchoto", etc..).


Last edited by spamipolito; 06-15-2020 at 23:32.
spamipolito is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 06-15-2020 , 23:44   Re: Rank, possibility lag?
Reply With Quote #8

Add a field for steam id and use that to identify players.
__________________
Bugsy is offline
spamipolito
Junior Member
Join Date: Jun 2018
Old 06-16-2020 , 15:10   Re: Rank, possibility lag?
Reply With Quote #9

Quote:
Originally Posted by Bugsy View Post
Add a field for steam id and use that to identify players.
Don't use accounts?
UserID (Account) change to UserID = SteamID ?
spamipolito is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 06-16-2020 , 16:38   Re: Rank, possibility lag?
Reply With Quote #10

Yeah, the field name doesn't matter.
__________________
Bugsy 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 20:25.


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