AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Using health as a percent value (https://forums.alliedmods.net/showthread.php?t=208506)

XINLEI 02-14-2013 12:17

Using health as a percent value
 
Hello there.

I wanna use the health to show a percentage of the real health of a player, but everytime i want to use an
PHP Code:

set_pev(victim,pev_health,...) 

it returns zero.

How can i put a value on the health whithout returning zero and have that 0hp Bug?
Yes, i tried something like set_pev(victim,pev_health,27) and i failed miserably

Thanks in Advance.

fl0werD 02-14-2013 12:19

Re: Using health as a percent value
 
Float.

XINLEI 02-14-2013 12:40

Re: Using health as a percent value
 
Quote:

Originally Posted by fl0werD (Post 1894277)
Float.

@off:
WHY GODDAMMIT GET STUCK WITH THINGS LIKE THIS.[/rage]

@On:
Thanks.
I'm doing this on takeDamage:
PHP Code:

new percentage get_user_health(victim)*100/percentage[victim]
set_pev(victim,pev_health,float(percentage)) 

And (i think ovbious) sets the health to 99. Can't be done whitout changing the player's health.

Sylwester 02-14-2013 12:54

Re: Using health as a percent value
 
You are doing it wrong. Don't change player health. Use this:
PHP Code:

public plugin_init(){    
    
register_message(get_user_msgid("Health"), "msg_Health")
}

public 
msg_Health(msg_idmsg_destid){
    if(!
is_user_alive(id))
        return
    new 
percent 100 get_user_health(id) / MAX_HEALTH
    
if(percent <= 0)
        
percent 1
    set_msg_arg_int
(10percent)



XINLEI 02-14-2013 16:13

Re: Using health as a percent value
 
It works perfect.
is there a way to call that message twice?

Thanks again!

Sylwester 02-14-2013 17:11

Re: Using health as a percent value
 
Why do you want to send it twice?

XINLEI 02-14-2013 20:04

Re: Using health as a percent value
 
Quote:

Originally Posted by Sylwester (Post 1894483)
Why do you want to send it twice?

I change the percent value too late and gives a wrong value so i want to send it twice to put the correct health percentage.

Sylwester 02-14-2013 21:09

Re: Using health as a percent value
 
You don't change percent value. All you need to do is set MAX_HEALTH on player spawn before changing player health and my code will do the rest.

ConnorMcLeod 02-15-2013 01:37

Re: Using health as a percent value
 
If plugin that you use is well coded, you should be able to use max_health as well.

PHP Code:

public plugin_init()
{
    
register_message(get_user_msgid("Health"), "Message_Health"))
}

public 
Message_Healthid )
{
    if( 
is_user_alive(id) )
    {
        
set_msg_arg_int
        
(
            
1
            
ARG_BYTE
            (
100*get_user_health(id)) / floatroundentity_get_float(idEV_FL_max_health) )
        )
    }



Sylwester 02-15-2013 08:23

Re: Using health as a percent value
 
But in mods you usually store max health in some global array, so it's better to use it instead of a native. Also you made 2 mistakes. id in your code is message id and in some cases it will display 0 health.


All times are GMT -4. The time now is 20:35.

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