Raised This Month: $ Target: $400
 0% 

Using health as a percent value


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
XINLEI
me too
Join Date: Jun 2011
Location: Colombian Coffee storage
Old 02-14-2013 , 12:17   Using health as a percent value
Reply With Quote #1

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.
XINLEI is offline
fl0werD
Senior Member
Join Date: May 2011
Old 02-14-2013 , 12:19   Re: Using health as a percent value
Reply With Quote #2

Float.
fl0werD is offline
Send a message via ICQ to fl0werD
XINLEI
me too
Join Date: Jun 2011
Location: Colombian Coffee storage
Old 02-14-2013 , 12:40   Re: Using health as a percent value
Reply With Quote #3

Quote:
Originally Posted by fl0werD View Post
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.
XINLEI is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 02-14-2013 , 12:54   Re: Using health as a percent value
Reply With Quote #4

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)

__________________
Impossible is Nothing

Last edited by Sylwester; 02-14-2013 at 12:57.
Sylwester is offline
XINLEI
me too
Join Date: Jun 2011
Location: Colombian Coffee storage
Old 02-14-2013 , 16:13   Re: Using health as a percent value
Reply With Quote #5

It works perfect.
is there a way to call that message twice?

Thanks again!

Last edited by XINLEI; 02-14-2013 at 20:07.
XINLEI is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 02-14-2013 , 17:11   Re: Using health as a percent value
Reply With Quote #6

Why do you want to send it twice?
__________________
Impossible is Nothing
Sylwester is offline
XINLEI
me too
Join Date: Jun 2011
Location: Colombian Coffee storage
Old 02-14-2013 , 20:04   Re: Using health as a percent value
Reply With Quote #7

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

Last edited by XINLEI; 02-14-2013 at 20:07.
XINLEI is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 02-14-2013 , 21:09   Re: Using health as a percent value
Reply With Quote #8

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.
__________________
Impossible is Nothing
Sylwester is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 02-15-2013 , 01:37   Re: Using health as a percent value
Reply With Quote #9

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

__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 02-15-2013 , 08:23   Re: Using health as a percent value
Reply With Quote #10

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.
__________________
Impossible is Nothing
Sylwester is offline
Reply



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 20:35.


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