!!Top 5 issue!! -
BlackWolf120 - 28.01.2011
hi,
i want that this board displays the top 5 players (amount of kills) currently playing on the server.
But as soon as there are more than 2 players it doesnt work. It just screws the server up and nothing works anymore. I have to restart the server after that.
There are 5 textdraws (1 for each player of the 5 top players)
Can someone tell me the error?
Why doesnt it work with more than 1 player on the server?
pawn Код:
//OnPlayerCommand
if (strcmp("/top", cmdtext, true) == 0)
{
SendClientMessage(playerid,0xAA3333AA,"{283A90}The {B0171F}Top 5 {283A90}board is displayed.");
new TotalScores[6];
new TotalPlayers[6];
new PlayerScore[2];
new PlayerID[2];
for(new i; i < MAX_PLAYERS; i++)
{
if(IsPlayerConnected(i))
{
PlayerScore[0] = kills[i]; //kills
PlayerID[0] = i;
for(new place; place < sizeof(TotalScores); place++)
{
if(PlayerScore[0] > TotalScores[place])
{
strins(TotalScores, PlayerScore, place);
strins(TotalPlayers, PlayerID, place);
place = sizeof(TotalScores);
}
}
}
}
TextDrawShowForPlayer(playerid,Top51);
new string[200];
GetPlayerName(TotalPlayers[0], string, sizeof(string));
format(string, sizeof(string), "~r~1. ~w~%s ~r~%d ~w~Kills ~y~%s", string,TotalScores[0],RankName[pRank[TotalPlayers[0]]]);
TextDrawShowForPlayer(playerid,Top52);
TextDrawSetString(Text:Top52, string);
GetPlayerName(TotalPlayers[1], string, sizeof(string));
format(string, sizeof(string), "~r~2. ~w~%s ~r~%d ~w~Kills ~y~%s", string,TotalScores[1],RankName[pRank[TotalPlayers[1]]]);
TextDrawShowForPlayer(playerid,Top53);
TextDrawSetString(Text:Top53, string);
GetPlayerName(TotalPlayers[2], string, sizeof(string));
format(string, sizeof(string), "~r~3. ~w~%s ~r~%d ~w~Kills ~y~%s", string,TotalScores[2],RankName[pRank[TotalPlayers[2]]]);
TextDrawShowForPlayer(playerid,Top54);
TextDrawSetString(Text:Top54, string);
GetPlayerName(TotalPlayers[3], string, sizeof(string));
format(string, sizeof(string), "~r~4. ~w~%s ~r~%d ~w~Kills ~y~%s", string,TotalScores[3],RankName[pRank[TotalPlayers[3]]]);
TextDrawShowForPlayer(playerid,Top55);
TextDrawSetString(Text:Top55, string);
GetPlayerName(TotalPlayers[4], string, sizeof(string));
format(string, sizeof(string), "~r~5. ~w~%s ~r~%d ~w~Kills ~y~%s", string,TotalScores[4],RankName[pRank[TotalPlayers[4]]]);
TextDrawShowForPlayer(playerid,Top56);
TextDrawSetString(Text:Top56, string);
AW: !!Top 5 issue!! -
Nero_3D - 28.01.2011
The better question is why do you use strings if you save integers ?
-> change it to normal variables
Or why Top51, Top52, ... and not an array like Top[51], Top[52] which could be used in a loop
-> you could change this but its not necessary, it only reduce the length of the td part around 75%
I just cant image why this should hang the server or why it works if one player (id 0) is connected
Re: !!Top 5 issue!! -
BlackWolf120 - 30.01.2011
hi,
thx for ur help once again.
I know that this is not the best way to script this code but im still a noob.
Now ive changed the code:
Ive involved a (switch[PlayerOnline])case function, cause i think that this code crashed the server because if there werent more than 5 players online (there are 5 textdraws) there had been some issues...
However, i have to wait till tomorrow because theres no one gonna test this with me now
regards...