View Single Post
Edison1318
Senior Member
Join Date: Nov 2015
Location: Peaceful place of the internet
Old 09-18-2018 , 10:04   Re: How to get the lowest health of the player?
#7

Quote:
Originally Posted by Vaggelis View Post
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 clienthealth
    
    
for(new 1<= MaxClientsi++)
    {
        if(
IsClientInGame(i) && IsPlayerAlive(i))
        {
            
health GetClientHealth(i)
            
            if(
health min)
            {
                
min health
                client 
i
            
}
        }
    }
    
    return 
client

Quote:
Originally Posted by Shane1390 View Post
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.
__________________
EdisonGar

Last edited by Edison1318; 09-18-2018 at 14:08.
Edison1318 is offline
Send a message via Skype™ to Edison1318