15.01.2018, 08:39
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:
This is the top command which calls the dialog:
and this is the ondialogresponse
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.
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;
}
PHP код:
CMD:top(playerid, params[])
{
ShowPlayerDialog(playerid, 60, DIALOG_STYLE_LIST, "Top 5 Stats", "Top Skilled\nTop Richest\n", "Select", "Exit");
return 1;
}
PHP код:
case DIALOG_TOP:
{
if(response)
{
switch(listitem)
{
case 0:
{
return cmd_topskilled(playerid);
}
case 1:
{
return cmd_toprichest(playerid);
}
}
}
}