[Solved] How to order variables by its value? -
Miguel - 25.12.2009
For example:
pawn Код:
new Variable[MAX_PLAYERS];
public OnPlayerConnect(playerid)
{
Variable[playerid] = random(500);
return 1;
}
how to order this variable by its value (starting from
0 and ending at
500) and how to get what is the first player by the variable value?
Re: How to order variables by its value? -
Miguel - 26.12.2009
Please?
Re: How to order variables by its value? -
[HiC]TheKiller - 26.12.2009
pawn Код:
stock GetHighestValue
{
new HighestValue = 0;//Makes the highest players varibale...
for(new i=0;i<MAX_PLAYERS();i++) //Goes through the 500 players in the variable
{
if(Variable[i] > Variable[HighestValue])
{
HighestValue = i;
}
}
return HighestValue;
}
This function would return the highest value out of the 500 players. So pretty much, you could do this:
pawn Код:
if(strcmp("/Highestvalue", cmdtext) == 0)
{
new string[77];
format(string, sizeof(string), "%d has the highest value of %d", GetHighestValue, Variable[GetHighestValue]);
SendClientMessage(playerid, 0x33CCCC, string);
return 1;
}
Re: How to order variables by its value? -
Miguel - 26.12.2009
Thanks for that example, however it doesn't have what I want. I'll explain a lil bit.
I have this array:
pawn Код:
enum Info
{
bla,
bla,
bla,
points
}
new pInfo[MAX_PLAYERS][Info];
new TopFive[MAX_PLAYER_NAME*5]; // lol this has no sence but well, I'll fix it myself later.
And I'm going to use the points that are given at the events. So, I want to order the players by the amount of points they have (for tables, stats, etc), and get their positon by the amount of points, like a score system(1st, 2nd, etc).
For example:
pawn Код:
new Pos[MAX_PLAYERS]; // let's guess I make a new variable for storing the result of the thing that get the position
public OnPlayerWinEvent(playerid)
{
new string[bla]
PlayerInfo[playerid][points] ++;
format(string, sizeof(string), "You have won this event! now your at the position %d.", Pos[playerid]); //how to get his/her pos?
SendClientMessage(playerid, COLOR, string);
format(string, sizeof(string), "Top five: %s", TopFive); // I'll need something to format the TopFive with the current TopFive :)
SendClientMessage(playerid, COLOR, string);
return 1;
}
Should I post it on the topic of script request or does it has a solution?
Re: How to order variables by its value? -
[HiC]TheKiller - 26.12.2009
pawn Код:
new TopFive[MAX_PLAYER_NAME*5]; // lol this has no sence but well, I'll fix it myself later.
Is meant to be
pawn Код:
new TopFive[5][MAX_PLAYER_NAME];
For this, I'm going to make it into a variable for better use of space.
pawn Код:
stock GetHighestPoints
{
new HighestValue[5];//Makes the highest players varibale...
for(new i=0;i<MAX_PLAYERS();i++) //Goes through the 500 players in the variable
{
if(pInfo[i][points] > Variable[HighestValue[0]])
{
HighestValue[0] = i;
}
if(pInfo[i][points] > pInfo[HighestValue[1]][points] && HighestValue[0] != i)
{
HighestValue[1] = i;
}
if(pInfo[i][points] > pInfo[HighestValue[2]][points] && HighestValue[0] != i && HighestValue[1] != i)
{
HighestValue[2] = i;
}
if(pInfo[i][points] > pInfo[HighestValue[3]][points] && HighestValue[0] != i && HighestValue[1] != i && HighestValue[2] != i)
{
HighestValue[3] = i;
}
if(pInfo[i][points] > pInfo[HighestValue[4]][points] && HighestValue[0] != i && HighestValue[1] != i && HighestValue[2] != i && HighestValue[3] != i)
{
HighestValue[4] = i;
}
}
TopFive[0] = HighestValue[0];
TopFive[1] = HighestValue[1];
TopFive[2] = HighestValue[2];
TopFive[3] = HighestValue[3];
TopFive[4] = HighestValue[4];
}
This function returns the top 5 playerids, I'll show you the usage of this:
pawn Код:
new string[126], Pname[5][MAX_PLAYER_NAME];
GetPlayerName(TopFive[0], Pname[0], 24);
GetPlayerName(TopFive[1], Pname[1], 24);
GetPlayerName(TopFive[2], Pname[2], 24);
GetPlayerName(TopFive[3], Pname[3], 24);
GetPlayerName(TopFive[4], Pname[4], 24);
format(string, sizeof(string), "Top 5: 1.%s(%d), 2.%s(%d), 3.%s(%d), 4.%s(%d), 5.%s(%d)", Pname[0], TopFive[0], Pname[1], TopFive[1], Pname[2], TopFive[2], Pname[3], TopFive[3], Pname[4], TopFive[4]);
SendClientMessage(playerid, COLOR, string);
So in your case:
pawn Код:
new Pos[MAX_PLAYERS]; // let's guess I make a new variable for storing the result of the thing that get the position
public OnPlayerWinEvent(playerid)
{
GetHighestPoints
new string[126], Pname[5][MAX_PLAYER_NAME];
GetPlayerName(TopFive[0], Pname[0], 24);
GetPlayerName(TopFive[1], Pname[1], 24);
GetPlayerName(TopFive[2], Pname[2], 24);
GetPlayerName(TopFive[3], Pname[3], 24);
GetPlayerName(TopFive[4], Pname[4], 24);
format(string, sizeof(string), "Top 5: 1.%s(%d), 2.%s(%d), 3.%s(%d), 4.%s(%d), 5.%s(%d)" Pname[0], TopFive[0], Pname[1], TopFive[1], Pname[2], TopFive[2], Pname[3], TopFive[3], Pname[4], TopFive[4]);
SendClientMessage(playerid, COLOR, string);
PlayerInfo[playerid][points] ++;
format(string, sizeof(string), "You have won this event! now your at the position %d.", Pos[playerid]); //how to get his/her pos?
SendClientMessage(playerid, COLOR, string);
return 1;
}
Re: How to order variables by its value? -
Miguel - 26.12.2009
Yo, thanks.