Top Statistics System
#1

Hi, I am trying to make a dialog based top statistics system for the players who are online. This is my code for the commands:

PHP код:
CMD:toprichest(playerid,params[])
            {
                new 
string[300], Slot1 = -1Slot2 = -1Slot3 = -1Slot4 = -1Slot5 = -1;
                new 
HighestCash = -9999;
                for(new 
x=0x<MAX_PLAYERSx++)
                {
                    if(
IsPlayerConnected(x))
                    {
                        if(
GetPlayerMoney(x) >= HighestCash)
                        {
                            
HighestCash GetPlayerMoney(x);
                            
Slot1 x;
                        }
                    }
                }
                
HighestCash = -9999;
                for(new 
x=0x<MAX_PLAYERSx++)
                {
                    if(
IsPlayerConnected(x) && != Slot1)
                    {
                        if(
GetPlayerMoney(x) >= HighestCash)
                        {
                            
HighestCash GetPlayerMoney(x);
                            
Slot2 x;
                        }
                    }
                }
                
HighestCash = -9999;
                for(new 
x=0x<MAX_PLAYERSx++)
                {
                    if(
IsPlayerConnected(x) && != Slot1 && != Slot2)
                    {
                        if(
GetPlayerMoney(x) >= HighestCash)
                        {
                            
HighestCash GetPlayerMoney(x);
                            
Slot3 x;
                        }
                    }
                }
                
HighestCash = -9999;
                for(new 
x=0x<MAX_PLAYERSx++)
                {
                    if(
IsPlayerConnected(x) && != Slot1 && != Slot2 && != Slot3)
                    {
                        if(
GetPlayerMoney(x) >= HighestCash)
                        {
                            
HighestCash GetPlayerMoney(x);
                            
Slot4 x;
                        }
                    }
                }
                
HighestCash = -9999;
                for(new 
x=0x<MAX_PLAYERSx++)
                {
                    if(
IsPlayerConnected(x) && != Slot1 && != Slot2 && != Slot3 && != Slot4)
                    {
                        if(
GetPlayerMoney(x) >= HighestCash)
                        {
                            
HighestCash GetPlayerMoney(x);
                            
Slot5 x;
                        }
                    }
                }
                
format(stringsizeof(string), "Rank\tName\tMoney\n{00FF00}1\t{ffffff}%s\t{008000}$%d\n"GetName(Slot1),GetPlayerMoney(Slot1));
                if(
Slot2 != -1)
                {
                    
format(stringsizeof(string), "%s{00FF00}2\t{ffffff}%s\t{008000}$%d\n"stringGetName(Slot2),GetPlayerMoney(Slot2));
                }
                if(
Slot3 != -1)
                {
                    
format(stringsizeof(string), "%s{00FF00}3\t{ffffff}%s\t{008000}$%d\n"stringGetName(Slot3),GetPlayerMoney(Slot3));
                }
                if(
Slot4 != -1)
                {
                    
format(stringsizeof(string), "%s{00FF00}4\t{ffffff}%s\t{008000}$%d\n"stringGetName(Slot4),GetPlayerMoney(Slot4));
                }
                if(
Slot5 != -1)
                {
                    
format(stringsizeof(string), "%s{00FF00}5\t{ffffff}%s\t{008000}$%d\n"stringGetName(Slot5),GetPlayerMoney(Slot5));
                }
                
ShowPlayerDialog(playerid10001DIALOG_STYLE_TABLIST_HEADERS"Top Richest Players"string"Close""");
                return 
1;
            }
            
CMD:topskilled(playerid,params[])
            {
                new 
string[300], Slot1 = -1Slot2 = -1Slot3 = -1Slot4 = -1Slot5 = -1;
                new 
HighestScore = -9999;
                for(new 
x=0x<MAX_PLAYERSx++)
                {
                    if(
IsPlayerConnected(x))
                    {
                        if(
GetPlayerScore(x) >= HighestScore)
                        {
                            
HighestScore GetPlayerScore(x);
                            
Slot1 x;
                        }
                    }
                }
                
HighestScore = -9999;
                for(new 
x=0x<MAX_PLAYERSx++)
                {
                    if(
IsPlayerConnected(x) && != Slot1)
                    {
                        if(
GetPlayerScore(x) >= HighestScore)
                        {
                            
HighestScore GetPlayerScore(x);
                            
Slot2 x;
                        }
                    }
                }
                
HighestScore = -9999;
                for(new 
x=0x<MAX_PLAYERSx++)
                {
                    if(
IsPlayerConnected(x) && != Slot1 && != Slot2)
                    {
                        if(
GetPlayerScore(x) >= HighestScore)
                        {
                            
HighestScore GetPlayerScore(x);
                            
Slot3 x;
                        }
                    }
                }
                
HighestScore = -9999;
                for(new 
x=0x<MAX_PLAYERSx++)
                {
                    if(
IsPlayerConnected(x) && != Slot1 && != Slot2 && != Slot3)
                    {
                        if(
GetPlayerScore(x) >= HighestScore)
                        {
                            
HighestScore GetPlayerScore(x);
                            
Slot4 x;
                        }
                    }
                }
                
HighestScore = -9999;
                for(new 
x=0x<MAX_PLAYERSx++)
                {
                    if(
IsPlayerConnected(x) && != Slot1 && != Slot2 && != Slot3 && != Slot4)
                    {
                        if(
GetPlayerScore(x) >= HighestScore)
                        {
                            
HighestScore GetPlayerScore(x);
                            
Slot5 x;
                        }
                    }
                }
                
format(stringsizeof(string), "Rank\tName\tScore\n{00FF00}1\t{ffffff}%s\t{008000}%d\n"GetName(Slot1),GetPlayerScore(Slot1));
                if(
Slot2 != -1)
                {
                    
format(stringsizeof(string), "%s{00FF00}2\t{ffffff}%s\t{008000}%d\n"stringGetName(Slot2),GetPlayerScore(Slot2));
                }
                if(
Slot3 != -1)
                {
                    
format(stringsizeof(string), "%s{00FF00}3\t{ffffff}%s\t{008000}%d\n"stringGetName(Slot3),GetPlayerScore(Slot3));
                }
                if(
Slot4 != -1)
                {
                    
format(stringsizeof(string), "%s{00FF00}4\t{ffffff}%s\t{008000}%d\n"stringGetName(Slot4),GetPlayerScore(Slot4));
                }
                if(
Slot5 != -1)
                {
                    
format(stringsizeof(string), "%s{00FF00}5\t{ffffff}%s\t{008000}%d\n"stringGetName(Slot5),GetPlayerScore(Slot5));
                }
                
ShowPlayerDialog(playerid10001DIALOG_STYLE_TABLIST_HEADERS"Top Skilled Players"string"Close""");
                return 
1;
            }
            
CMD:topkillers(playerid,params[])
            {
                new 
string[300], Slot1 = -1Slot2 = -1Slot3 = -1Slot4 = -1Slot5 = -1;
                new 
HighestKill = -9999;
                for(new 
x=0x<MAX_PLAYERSx++)
                {
                    if(
IsPlayerConnected(x))
                    {
                        if(
PInfo[x][Kills] >= HighestKill)
                        {
                            
HighestKill PInfo[x][Kills];
                            
Slot1 x;
                        }
                    }
                }
                
HighestKill = -9999;
                for(new 
x=0x<MAX_PLAYERSx++)
                {
                    if(
IsPlayerConnected(x) && != Slot1)
                    {
                        if(
PInfo[x][Kills] >= HighestKill)
                        {
                            
HighestKill PInfo[x][Kills];
                            
Slot2 x;
                        }
                    }
                }
                
HighestKill = -9999;
                for(new 
x=0x<MAX_PLAYERSx++)
                {
                    if(
IsPlayerConnected(x) && != Slot1 && != Slot2)
                    {
                        if(
PInfo[x][Kills] >= HighestKill)
                        {
                            
HighestKill PInfo[x][Kills];
                            
Slot3 x;
                        }
                    }
                }
                
HighestKill = -9999;
                for(new 
x=0x<MAX_PLAYERSx++)
                {
                    if(
IsPlayerConnected(x) && != Slot1 && != Slot2 && != Slot3)
                    {
                        if(
PInfo[x][Kills] >= HighestKill)
                        {
                            
HighestKill PInfo[x][Kills];
                            
Slot4 x;
                        }
                    }
                }
                
HighestKill = -9999;
                for(new 
x=0x<MAX_PLAYERSx++)
                {
                    if(
IsPlayerConnected(x) && != Slot1 && != Slot2 && != Slot3 && != Slot4)
                    {
                        if(
PInfo[x][Kills] >= HighestKill)
                        {
                            
HighestKill PInfo[x][Kills];
                            
Slot5 x;
                        }
                    }
                }
                
format(stringsizeof(string), "Rank\tName\tKills\n{00FF00}1\t{ffffff}%s\t{008000}%d\n"GetName(Slot1),HighestKill(Slot1));
                if(
Slot2 != -1)
                {
                    
format(stringsizeof(string), "%s{00FF00}2\t{ffffff}%s\t{008000}%d\n"stringGetName(Slot2),HighestKill(Slot2));
                }
                if(
Slot3 != -1)
                {
                    
format(stringsizeof(string), "%s{00FF00}3\t{ffffff}%s\t{008000}%d\n"stringGetName(Slot3),HighestKill(Slot3));
                }
                if(
Slot4 != -1)
                {
                    
format(stringsizeof(string), "%s{00FF00}4\t{ffffff}%s\t{008000}%d\n"stringGetName(Slot4),HighestKill(Slot4));
                }
                if(
Slot5 != -1)
                {
                    
format(stringsizeof(string), "%s{00FF00}5\t{ffffff}%s\t{008000}%d\n"stringGetName(Slot5),HighestKill(Slot5));
                }
                
ShowPlayerDialog(playerid10001DIALOG_STYLE_TABLIST_HEADERS"Top Serial Killers"string"Close""");
                return 
1;
            } 
This is the top command which calls the dialog:

PHP код:
CMD:top(playeridparams[])
            {
                
ShowPlayerDialog(playerid60DIALOG_STYLE_LIST"Top 5 Stats""Top Skilled\nTop Richest\n""Select""Exit");
                return 
1;
            } 
and this is the ondialogresponse

PHP код:
case DIALOG_TOP:
        {
            if(
response)
            {
                switch(
listitem)
                {
                    case 
0:
                    {
                        return 
cmd_topskilled(playerid);
                    }
                    case 
1:
                    {
                        return 
cmd_toprichest(playerid);
                    }
                }
            }
        } 
The top system is based on top 5 statistics ingame thus whenever there are 5 players or more connected and someone uses the /top command, it crashes the server. I dont understand what's wrong. Any help appreciated.
Reply
#2

Anyone?
Reply
#3

Nothing wrong with code,
Try to set timer before you Show the player your dialog to let the server check the players, if it doesn't works, Post your server_log.
Reply
#4

Please post your server log. Use crash detect or something.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)