Raised This Month: $ Target: $400
 0% 

Using health as a percent value


Post New Thread Reply   
 
Thread Tools Display Modes
XINLEI
me too
Join Date: Jun 2011
Location: Colombian Coffee storage
Old 02-15-2013 , 10:01   Re: Using health as a percent value
Reply With Quote #11

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

PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <hamsandwich>
#include <zp50_core>

#define PLUGIN "Health percent"
#define VERSION "0.002"
#define AUTHOR "makiza"

new g_RealHealth[33]

public 
plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_message(get_user_msgid("Health"), "msg_Health")
    
RegisterHam(Ham_Spawn"player""fwHamPlayerSpawnPost"1)
}

public 
client_putinserver(id)
{
    
g_RealHealth[id] = 1
}

public 
fwHamPlayerSpawnPost(id
{
    if (
is_user_alive(id)) 
    {
        
g_RealHealth[id] = get_user_health(id)*100
    
}
}

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

public 
zp_fw_core_infect_post(id,attacker)
{
    
//if i do it directly i will have the zombie health plus any multiplier
    //example: first zombie earns a value over 100%, being nemesis earns a value over 9000%
    
set_task(1.0,"max_health_checker",id
}

public 
zp_fw_core_cure_post(id,attacker)
{
    
set_task(1.0,"max_health_checker",id)
}

public 
max_health_checker(id)
{
    
g_RealHealth[id] = get_user_health(id)


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

try this:
PHP Code:
#include <amxmodx>
#include <hamsandwich>

#define PLUGIN "Health percent"
#define VERSION "0.002"
#define AUTHOR "makiza"

new g_MaxHealth[33]

public 
plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_message(get_user_msgid("Health"), "msg_Health")
    
RegisterHam(Ham_Spawn"player""fwHamPlayerSpawnPre")
}

public 
fwHamPlayerSpawnPre(id
{
    
g_MaxHealth[id] = 1
}

public 
msg_Health(msg_idmsg_destid)
{
    if(!
is_user_alive(id))
        return
        
    new 
health get_user_health(id)
    if(
g_MaxHealth[id] < health)
        
g_MaxHealth[id] = health
        
    
new percent = (100 health g_MaxHealth[id] - 1) / g_MaxHealth[id]

    
set_msg_arg_int(1ARG_BYTEpercent)

__________________
Impossible is Nothing
Sylwester is offline
Xalus
Veteran Member
Join Date: Dec 2009
Location: Belgium
Old 02-15-2013 , 12:36   Re: Using health as a percent value
Reply With Quote #13

As far I remember, with calculating percents
You need to calculate with floats and return the result in a integer.
__________________
Retired.
Xalus is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 02-15-2013 , 12:47   Re: Using health as a percent value
Reply With Quote #14

You are wrong. My solution works fine.
__________________
Impossible is Nothing
Sylwester is offline
Xalus
Veteran Member
Join Date: Dec 2009
Location: Belgium
Old 02-15-2013 , 12:52   Re: Using health as a percent value
Reply With Quote #15

If I calculated percents with interger it only resulted 0 or 100 in the past for me.

But anyway; if it works, it works ;)
__________________
Retired.

Last edited by Xalus; 02-15-2013 at 12:52.
Xalus is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 02-15-2013 , 14:09   Re: Using health as a percent value
Reply With Quote #16

Quote:
Originally Posted by Xalus View Post
If I calculated percents with interger it only resulted 0 or 100 in the past for me.
That's probably because you calculated it in a wrong order (you did division first and then multiplied it by 100).
__________________
Impossible is Nothing
Sylwester is offline
XINLEI
me too
Join Date: Jun 2011
Location: Colombian Coffee storage
Old 02-15-2013 , 16:04   Re: Using health as a percent value
Reply With Quote #17

Quote:
Originally Posted by Sylwester View Post
try this:
PHP Code:
#include <amxmodx>
#include <hamsandwich>

#define PLUGIN "Health percent"
#define VERSION "0.002"
#define AUTHOR "makiza"

new g_MaxHealth[33]

public 
plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_message(get_user_msgid("Health"), "msg_Health")
    
RegisterHam(Ham_Spawn"player""fwHamPlayerSpawnPre")
}

public 
fwHamPlayerSpawnPre(id
{
    
g_MaxHealth[id] = 1
}

public 
msg_Health(msg_idmsg_destid)
{
    if(!
is_user_alive(id))
        return
        
    new 
health get_user_health(id)
    if(
g_MaxHealth[id] < health)
        
g_MaxHealth[id] = health
        
    
new percent = (100 health g_MaxHealth[id] - 1) / g_MaxHealth[id]

    
set_msg_arg_int(1ARG_BYTEpercent)

It works awesome, shame that it locks the health to 100, and if a player manages to earn more health he will not notice it. Is it really a bad idea/method to use my previous code?
XINLEI is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 02-15-2013 , 16:12   Re: Using health as a percent value
Reply With Quote #18

What mod is it to play with ?
How do you gain health and how is max health limited (if limited) ?
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
XINLEI
me too
Join Date: Jun 2011
Location: Colombian Coffee storage
Old 02-15-2013 , 16:15   Re: Using health as a percent value
Reply With Quote #19

Zombie plague.

You gan gain more health for example in a infecting spree or a silly extra item to give 500hp. and the health is not limited (or maxed) at all, but starts with the player's zombie class upon infection.

This is why i asked to send a message_health twice.

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

You are trying to make it really complicated. Why don't you just inform player that his max health changed with hud message or chat message?
PHP Code:
    if(g_MaxHealth[id] < health)
    {
        
g_MaxHealth[id] = health
        
//max health increased, inform player that his max health now equals g_MaxHealth[id] ...
    

__________________
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