26.12.2009, 06:59
GetHigestValueInVariable
GetHigestValueInVariable - A long name, Yes but it's better in explaining it. It finds the highest value in a variable such as pawn Код:
Kills[playerid]
GetHigestValueInVariable(VarName, Length)
VariableName - The variable that you want to find the highest value of
Length - The size of the variable
pawn Код:
GetHigestValueInVariable(VarName[], XLength)
{
new HighestNumber;
for(new i=0;i<XLength;i++)
{
if(VarName[i] > VarName[HighestNumber])
{
HighestNumber = i;
}
}
return HighestNumber;
}
pawn Код:
new Kills[MAX_PLAYERS];
public OnPlayerDeath(playerid, killerid, reason)
{
Kills[killerid] ++;
return 1;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
if(strcmp("/MostKills", cmdtext) == 0)
{
new String[135];
new Pname[24];
GetPlayerName(GetHigestValueInVariable(Kills, 500), Pname, 24);
format(String, sizeof(String), "%s(%d) has the highest kills with %d kills!", Pname, GetHigestValueInVariable(Kills, 500), Kills[GetHigestValueInVariable(Kills, 500)]);
SendClientMessage(playerid, 0x33CCCC, String);
return 1;
}
return 0;
}