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 = -1, Slot2 = -1, Slot3 = -1, Slot4 = -1, Slot5 = -1;
new HighestCash = -9999;
for(new x=0; x<MAX_PLAYERS; x++)
{
if(IsPlayerConnected(x))
{
if(GetPlayerMoney(x) >= HighestCash)
{
HighestCash = GetPlayerMoney(x);
Slot1 = x;
}
}
}
HighestCash = -9999;
for(new x=0; x<MAX_PLAYERS; x++)
{
if(IsPlayerConnected(x) && x != Slot1)
{
if(GetPlayerMoney(x) >= HighestCash)
{
HighestCash = GetPlayerMoney(x);
Slot2 = x;
}
}
}
HighestCash = -9999;
for(new x=0; x<MAX_PLAYERS; x++)
{
if(IsPlayerConnected(x) && x != Slot1 && x != Slot2)
{
if(GetPlayerMoney(x) >= HighestCash)
{
HighestCash = GetPlayerMoney(x);
Slot3 = x;
}
}
}
HighestCash = -9999;
for(new x=0; x<MAX_PLAYERS; x++)
{
if(IsPlayerConnected(x) && x != Slot1 && x != Slot2 && x != Slot3)
{
if(GetPlayerMoney(x) >= HighestCash)
{
HighestCash = GetPlayerMoney(x);
Slot4 = x;
}
}
}
HighestCash = -9999;
for(new x=0; x<MAX_PLAYERS; x++)
{
if(IsPlayerConnected(x) && x != Slot1 && x != Slot2 && x != Slot3 && x != Slot4)
{
if(GetPlayerMoney(x) >= HighestCash)
{
HighestCash = GetPlayerMoney(x);
Slot5 = x;
}
}
}
format(string, sizeof(string), "Rank\tName\tMoney\n{00FF00}1\t{ffffff}%s\t{008000}$%d\n", GetName(Slot1),GetPlayerMoney(Slot1));
if(Slot2 != -1)
{
format(string, sizeof(string), "%s{00FF00}2\t{ffffff}%s\t{008000}$%d\n", string, GetName(Slot2),GetPlayerMoney(Slot2));
}
if(Slot3 != -1)
{
format(string, sizeof(string), "%s{00FF00}3\t{ffffff}%s\t{008000}$%d\n", string, GetName(Slot3),GetPlayerMoney(Slot3));
}
if(Slot4 != -1)
{
format(string, sizeof(string), "%s{00FF00}4\t{ffffff}%s\t{008000}$%d\n", string, GetName(Slot4),GetPlayerMoney(Slot4));
}
if(Slot5 != -1)
{
format(string, sizeof(string), "%s{00FF00}5\t{ffffff}%s\t{008000}$%d\n", string, GetName(Slot5),GetPlayerMoney(Slot5));
}
ShowPlayerDialog(playerid, 10001, DIALOG_STYLE_TABLIST_HEADERS, "Top Richest Players", string, "Close", "");
return 1;
}
CMD:topskilled(playerid,params[])
{
new string[300], Slot1 = -1, Slot2 = -1, Slot3 = -1, Slot4 = -1, Slot5 = -1;
new HighestScore = -9999;
for(new x=0; x<MAX_PLAYERS; x++)
{
if(IsPlayerConnected(x))
{
if(GetPlayerScore(x) >= HighestScore)
{
HighestScore = GetPlayerScore(x);
Slot1 = x;
}
}
}
HighestScore = -9999;
for(new x=0; x<MAX_PLAYERS; x++)
{
if(IsPlayerConnected(x) && x != Slot1)
{
if(GetPlayerScore(x) >= HighestScore)
{
HighestScore = GetPlayerScore(x);
Slot2 = x;
}
}
}
HighestScore = -9999;
for(new x=0; x<MAX_PLAYERS; x++)
{
if(IsPlayerConnected(x) && x != Slot1 && x != Slot2)
{
if(GetPlayerScore(x) >= HighestScore)
{
HighestScore = GetPlayerScore(x);
Slot3 = x;
}
}
}
HighestScore = -9999;
for(new x=0; x<MAX_PLAYERS; x++)
{
if(IsPlayerConnected(x) && x != Slot1 && x != Slot2 && x != Slot3)
{
if(GetPlayerScore(x) >= HighestScore)
{
HighestScore = GetPlayerScore(x);
Slot4 = x;
}
}
}
HighestScore = -9999;
for(new x=0; x<MAX_PLAYERS; x++)
{
if(IsPlayerConnected(x) && x != Slot1 && x != Slot2 && x != Slot3 && x != Slot4)
{
if(GetPlayerScore(x) >= HighestScore)
{
HighestScore = GetPlayerScore(x);
Slot5 = x;
}
}
}
format(string, sizeof(string), "Rank\tName\tScore\n{00FF00}1\t{ffffff}%s\t{008000}%d\n", GetName(Slot1),GetPlayerScore(Slot1));
if(Slot2 != -1)
{
format(string, sizeof(string), "%s{00FF00}2\t{ffffff}%s\t{008000}%d\n", string, GetName(Slot2),GetPlayerScore(Slot2));
}
if(Slot3 != -1)
{
format(string, sizeof(string), "%s{00FF00}3\t{ffffff}%s\t{008000}%d\n", string, GetName(Slot3),GetPlayerScore(Slot3));
}
if(Slot4 != -1)
{
format(string, sizeof(string), "%s{00FF00}4\t{ffffff}%s\t{008000}%d\n", string, GetName(Slot4),GetPlayerScore(Slot4));
}
if(Slot5 != -1)
{
format(string, sizeof(string), "%s{00FF00}5\t{ffffff}%s\t{008000}%d\n", string, GetName(Slot5),GetPlayerScore(Slot5));
}
ShowPlayerDialog(playerid, 10001, DIALOG_STYLE_TABLIST_HEADERS, "Top Skilled Players", string, "Close", "");
return 1;
}
CMD:topkillers(playerid,params[])
{
new string[300], Slot1 = -1, Slot2 = -1, Slot3 = -1, Slot4 = -1, Slot5 = -1;
new HighestKill = -9999;
for(new x=0; x<MAX_PLAYERS; x++)
{
if(IsPlayerConnected(x))
{
if(PInfo[x][Kills] >= HighestKill)
{
HighestKill = PInfo[x][Kills];
Slot1 = x;
}
}
}
HighestKill = -9999;
for(new x=0; x<MAX_PLAYERS; x++)
{
if(IsPlayerConnected(x) && x != Slot1)
{
if(PInfo[x][Kills] >= HighestKill)
{
HighestKill = PInfo[x][Kills];
Slot2 = x;
}
}
}
HighestKill = -9999;
for(new x=0; x<MAX_PLAYERS; x++)
{
if(IsPlayerConnected(x) && x != Slot1 && x != Slot2)
{
if(PInfo[x][Kills] >= HighestKill)
{
HighestKill = PInfo[x][Kills];
Slot3 = x;
}
}
}
HighestKill = -9999;
for(new x=0; x<MAX_PLAYERS; x++)
{
if(IsPlayerConnected(x) && x != Slot1 && x != Slot2 && x != Slot3)
{
if(PInfo[x][Kills] >= HighestKill)
{
HighestKill = PInfo[x][Kills];
Slot4 = x;
}
}
}
HighestKill = -9999;
for(new x=0; x<MAX_PLAYERS; x++)
{
if(IsPlayerConnected(x) && x != Slot1 && x != Slot2 && x != Slot3 && x != Slot4)
{
if(PInfo[x][Kills] >= HighestKill)
{
HighestKill = PInfo[x][Kills];
Slot5 = x;
}
}
}
format(string, sizeof(string), "Rank\tName\tKills\n{00FF00}1\t{ffffff}%s\t{008000}%d\n", GetName(Slot1),HighestKill(Slot1));
if(Slot2 != -1)
{
format(string, sizeof(string), "%s{00FF00}2\t{ffffff}%s\t{008000}%d\n", string, GetName(Slot2),HighestKill(Slot2));
}
if(Slot3 != -1)
{
format(string, sizeof(string), "%s{00FF00}3\t{ffffff}%s\t{008000}%d\n", string, GetName(Slot3),HighestKill(Slot3));
}
if(Slot4 != -1)
{
format(string, sizeof(string), "%s{00FF00}4\t{ffffff}%s\t{008000}%d\n", string, GetName(Slot4),HighestKill(Slot4));
}
if(Slot5 != -1)
{
format(string, sizeof(string), "%s{00FF00}5\t{ffffff}%s\t{008000}%d\n", string, GetName(Slot5),HighestKill(Slot5));
}
ShowPlayerDialog(playerid, 10001, DIALOG_STYLE_TABLIST_HEADERS, "Top Serial Killers", string, "Close", "");
return 1;
}
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.
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.
Please post your server log. Use crash detect or something.