Quote:
Originally Posted by Vaggelis
Keep in mind this code will return only one client, i also suppose max health is 100HP, so i putted 101 in min.
PHP Code:
new client = HasLowestHealth()
PHP Code:
HasLowestHealth()
{
new min = 101
new client, health
for(new i = 1; i <= MaxClients; i++)
{
if(IsClientInGame(i) && IsPlayerAlive(i))
{
health = GetClientHealth(i)
if(health < min)
{
min = health
client = i
}
}
}
return client
}
|
Quote:
Originally Posted by Shane1390
Bool function on new syntax, since you need to iterate through every client, I guess the earlier return point could help a bit(?)
Code:
public bool playerHasLowestHealth(int client)
{
if (!IsValidClient(client)) {
return false;
}
int clientHp = GetClientHealth(client);
for (int i = 1; i <= MAXPLAYERS; i++) {
if (!IsValidClient(i) || !IsPlayerAlive(i)) {
continue;
} else if (GetClientHealth(i) < clientHp) {
return false;
}
}
return true;
}
stock bool IsValidClient(int client, bool nobots = false)
{
if (client <= 0 || client > MaxClients || !IsClientConnected(client) || (nobots && IsFakeClient(client)) || !IsClientInGame(client)) {
return false;
}
return true;
}
|
Alright, much obliged. I would able to code further and my stuff with your help.
__________________