Raised This Month: $12 Target: $400
 3% 

Solved How to get the lowest health of the player?


Post New Thread Closed Thread   
 
Thread Tools Display Modes
Author Message
Edison1318
Senior Member
Join Date: Nov 2015
Location: Peaceful place of the in
Old 09-18-2018 , 07:59   How to get the lowest health of the player?
#1

Well, let's just say i'm not advanced coder but I'm understood some coding experiences. I want to find player which has a lowest health. Drop comments to help me out.

ty.
__________________
EdisonGar

Last edited by Edison1318; 09-18-2018 at 14:05. Reason: Mistaken.
Edison1318 is offline
Send a message via Skype™ to Edison1318
eyal282
Veteran Member
Join Date: Aug 2011
Old 09-18-2018 , 08:45   Re: How to get the lowest health of the player?
#2

It's always 1 as the lowest health a player can have being alone very and 0 the lowest possible which kills the player
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334
eyal282 is offline
Cruze
Veteran Member
Join Date: May 2017
Old 09-18-2018 , 09:03   Re: How to get the lowest health of the player?
#3

Quote:
Originally Posted by eyal282 View Post
0 the lowest possible which kills the player
and for csgo, it freezes the player
__________________
Taking paid private requests! Contact me
Cruze is offline
Edison1318
Senior Member
Join Date: Nov 2015
Location: Peaceful place of the in
Old 09-18-2018 , 09:12   Re: How to get the lowest health of the player?
#4

I mean which player has a lowest health like for example:

Player 1: has 100%
Player 2: has 45%
Player 3: has 76%
Player 4: has 48%

Player 3 has a lowest health so i want to put like
if(playerhasalowesthealth(client))
{
(Do something)
}
Hope you what i mean.
__________________
EdisonGar

Last edited by Edison1318; 09-18-2018 at 09:12.
Edison1318 is offline
Send a message via Skype™ to Edison1318
Vaggelis
Senior Member
Join Date: May 2017
Old 09-18-2018 , 09:30   Re: How to get the lowest health of the player?
#5

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

Vaggelis is offline
Shane1390
Member
Join Date: Apr 2018
Old 09-18-2018 , 09:49   Re: How to get the lowest health of the player?
#6

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;
}

Last edited by Shane1390; 09-18-2018 at 09:50. Reason: bracket went funny
Shane1390 is offline
Edison1318
Senior Member
Join Date: Nov 2015
Location: Peaceful place of the in
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
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 09-18-2018 , 12:41   Re: How to get the lowest health of the player?
#8

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(?)
so you check if client > 0 && client <= MaxClients in a for that starts with 1 and ends at MaxClients?
also isclientconnected it's useless when you check if the client is in game.

PHP Code:
public int HasLowestHealth()
{
    
int client = -1min = -1;
    
    for (
int i 1<= MaxClientsi++)
    {
        if (
IsClientInGame(i))
        {
            if (
IsPlayerAlive(i))
            {
                
int health GetClientHealth(i);
                
                if (
min == -1)
                {
                    
min health;
                    
client i;
                }
                else
                {
                    if (
health min)
                    {
                        
min health;
                        
client i;
                    }
                }
            }
        }
    }

    return 
client;


Last edited by Ilusion9; 09-19-2018 at 08:05.
Ilusion9 is offline
Vaggelis
Senior Member
Join Date: May 2017
Old 09-18-2018 , 13:21   Re: How to get the lowest health of the player?
#9

Quote:
Originally Posted by Ilusion9 View Post
so you check if client > 0 && client <= MaxClients in a for that starts with 1 and ends at MaxClients?
also isclientconnected it's useless when you check if the client is in game.

PHP Code:
public int HasLowestHealth()
{
    
size 0;
    
int client = -1min = -1;
    
    for (
int i 1<= MaxClientsi++)
    {
        if (
IsClientInGame(i))
        {
            if (
IsPlayerAlive(i))
            {
                
int health GetClientHealth(i);
                
                if (
min == -1)
                {
                    
min health;
                    
client i;
                }
                else
                {
                    if (
health min)
                    {
                        
min health;
                        
client i;
                    }
                }
            }
        }
    }

    return 
client;

Whats the point posting that code? Edison1318 got what he wanted
Vaggelis is offline
Edison1318
Senior Member
Join Date: Nov 2015
Location: Peaceful place of the in
Old 09-18-2018 , 14:09   Re: How to get the lowest health of the player?
#10

Quote:
Originally Posted by Vaggelis View Post
Whats the point posting that code? Edison1318 got what he wanted
It's okay. Since I got the code, i'm alright with trying people's code just to test in my game as well.
__________________
EdisonGar

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


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 21:38.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode