AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Rank, possibility lag? (https://forums.alliedmods.net/showthread.php?t=325285)

spamipolito 06-15-2020 12:48

Rank, possibility lag?
 
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; 
            }
        }
    } 



Bugsy 06-15-2020 17:46

Re: Rank, possibility lag?
 
Use threaded queries: https://forums.alliedmods.net/showthread.php?t=46779

+ARUKARI- 06-15-2020 21:21

Re: Rank, possibility lag?
 
Use the AuthID as a key to narrow down the results to one.

Bugsy 06-15-2020 21:45

Re: Rank, possibility lag?
 
Oh, I didn't even look at the SQL, lol. Put as much filtering criteria as possible.

spamipolito 06-15-2020 22:41

Re: Rank, possibility lag?
 
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)
    }



+ARUKARI- 06-15-2020 22:49

Re: Rank, possibility lag?
 
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.

spamipolito 06-15-2020 23:31

Re: Rank, possibility lag?
 
Quote:

Originally Posted by +ARUKARI- (Post 2705926)
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..).

https://i.imgur.com/ft1Ypag.png

Bugsy 06-15-2020 23:44

Re: Rank, possibility lag?
 
Add a field for steam id and use that to identify players.

spamipolito 06-16-2020 15:10

Re: Rank, possibility lag?
 
Quote:

Originally Posted by Bugsy (Post 2705933)
Add a field for steam id and use that to identify players.

Don't use accounts?
UserID (Account) change to UserID = SteamID ?

Bugsy 06-16-2020 16:38

Re: Rank, possibility lag?
 
Yeah, the field name doesn't matter.


All times are GMT -4. The time now is 17:09.

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