09.08.2014, 00:47
Like the title says, any ideas?
new KillCount[MAX_PLAYERS];
KillCount[playerid] = 0;
KillCount[killerid]++;
GetTopFive(team)
{
new TopFive[5];
for(new i = 0; i < 5; i++)
{
for(new a = 0; a < MAX_PLAYERS; a++)
{
if(GetPlayerTeam(a) == team)
{
for(new b = 0; b < MAX_PLAYERS; b++)
{
if(KillCount[a] > KillCount[b] && GetPlayerTeam(b) == team)
{
if(i == 0 && TopFive[0] < KillCount[a])
{
TopFive[0] = a;
}
else if(TopFive[i] < KillCount[a] && TopFive[i - 1] > KillCount[a])
{
TopFive[i] = a;
}
}
}
}
}
}
return TopFive;
}
new variable[5];
variable = GetTopFive(team);
Hey, just stopped in for a peek, been out of the loop for a while and this is not the most efficient way to do this. I just wrote it up quick and believe it should work. *crosses fingers*
Top of script: pawn Код:
pawn Код:
pawn Код:
pawn Код:
pawn Код:
|
new Top[5],string[256];
Top = GetTopFive(Team1);
format(string, sizeof(string), "Top 1 | Name: %s | Kills: %d | Deaths: %d", pName(Top[0]), KillsCount(Top[0]), deaths[0]));
SendClientMessage(playerid, -1, string);
format(string, sizeof(string), "Top 2 | Name: %s | Kills: %d | Deaths: %d", pName(Top[1]), KillsCount(Top[1]), deaths[1]));
SendClientMessage(playerid, -1, string);
// and continue doing that until I get to Top[4]...
Check if player is connected or not inside the loop and then return the values accordingly. Or you can just look if the player is connected or not with the returned values.
|
GetTopFive(team)
{
new num[MAX_PLAYERS], numid[MAX_PLAYERS] = {-1, -1, -1, -1, -1}, sum[5];
for(new a = 0; a < MAX_PLAYERS; a++) for(new b = 0; b < MAX_PLAYERS; b++) {
if(num[a] <= KillCount[b]) {
for(new c = 0; c < 5; c++) if(b == numid[c]) goto one;
if(IsPlayerConnected(b) == 0 || GetPlayerTeam(b) != team) goto one;
num[a] = KillCount[b]; numid[a] = b;
one:
}
}
for(new i = 0; i < 5; i++) sum[i] = numid[i];
return sum;
}
//And for your message, something like this:
new Top[5], string[128];
Top = GetTopFive(Team1);
for(new i = 0; i < 5; i++) {
if(Top[i] == -1) break; //Top will be -1 if player is not connected
format(string, sizeof(string), "Top %d | Name: %s | Kills: %d | Deaths: %d", i + 1, pName(Top[i]), KillCount[i], deaths[i]);
SendClientMessage(playerid, -1, string);
}