Top3 help -
NeamPojma - 10.03.2016
Hello im trying to create top 3 players and teleport them somewhere after each round..
How i could find who have most pRoundkills, i tried for(int i = 0; i <MAX_PLAYERS; i++)...
But i cant use playerid in for so how i could compare players?Or i must use something other?
Re: Top3 help -
amirm3hdi - 10.03.2016
This is how you get the top player with the most kills:
Код:
GetTopPlayerByKills()
{
new top_player = -1;
new top_kills = 0;
for (new i = 0; i < MAX_PLAYERS; i++)
{
if (pRoundkills[i] > top_kills)
{
top_player = i;
top_kills = pRoundkills[i];
}
}
return top_player;
}
Now you need to get top 3 players,
Make a function yourself like the top one and don't count the top player,
Repeat it 3 times.
Re: Top3 help -
NeamPojma - 10.03.2016
I created this:
pawn Код:
GetTopPlayer1()
{
for (new i = 0; i < MAX_PLAYERS; i++)
{
if (PlayerInfo[i][pRoundkills] > top_kills)
{
top_player = i;
top_kills = PlayerInfo[i][pRoundkills];
}
}
new string[64];
new first[MAX_PLAYER_NAME];
GetPlayerName(top_player,first,sizeof(first));
format(string, sizeof(string), "%s Is 1st!.", first);
SendClientMessageToAll(COLOR_WHITE,string);
TogglePlayerControllable(top_player,false);
SetPlayerPos(top_player,1444.5739,-972.7752,59.6679);
SetPlayerFacingAngle(top_player,179.5416);
return top_player;
}
GetTopPlayer2()
{
for (new i = 0; i < MAX_PLAYERS; i++)
{
if (PlayerInfo[i][pRoundkills] > PlayerInfo[i][pRoundkills] && PlayerInfo[i][pRoundkills] < top_player)
{
top_player2 = i;
}
}
new string[64],second[MAX_PLAYER_NAME];
GetPlayerName(top_player2,second,sizeof(second));
format(string, sizeof(string), "%s Is 2nd!.", second);
SendClientMessageToAll(COLOR_WHITE,string);
TogglePlayerControllable(top_player2,false);
SetPlayerPos(top_player2,1441.0249,-973.0031,58.4679);
SetPlayerFacingAngle(top_player2,179.5416);
return top_player2;
}
But it dont work good when there is mutliple players,can you suggest me what to fix?
Re: Top3 help -
NeamPojma - 11.03.2016
Bump
Re: Top3 help -
BroZeus - 11.03.2016
Try this, read comments :
PHP код:
new top3[3] = {-1, ...};//this initilizes the array with all index value set as -1, so the array has -1's in it
top_kills = -1;
new onlinePlayerNumber = 0;
//first getting number of online players
//because if players are less than 3 then get the top 2 or top 1 only.
for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++)if(IsPlayerConnected(i))onlinePlayerNumber++;
//Getting top 3 and store in top[3] array
for(new num = 0; num < (onlinePlayerNumber > 3 ? 3 : onlinePlayerNumber); num++)
{
for (new i = 0, j = GetPlayerPoolSize(); i <= j; i++)
{
// here we check if player is already not on list :
if(top[0] != i && top[1] != i && IsPlayerConnected(i))
{
if (PlayerInfo[i][pRoundkills] > top_kills)
{
top[num] = i;
top_kills = PlayerInfo[i][pRoundkills];
}
}
}
top_kills = -1;
}
// task done now just send top 3 message
for(new i = 0; i < 3; i++)
{
//make sure to put this if conditon :
if(top[i] != -1)SendClientMessage(top[i], 0x00cc00FF, "HEY! You are on top 3 list!!");
}
Re: Top3 help -
Sew_Sumi - 11.03.2016
^^ That seems legit, another thing to look at is
https://sampwiki.blast.hk/wiki/Advanced_Structures
The wiki topic simply shows some bits, but also shows to have the whole thing in one function, rather than having several.
There was a tutorial way back somewhere which did this entirely, making a top5-10 list. I have no idea where it's ended up.