Raised This Month: $ Target: $400
 0% 

HP regenerator


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ArthHa
Member
Join Date: Apr 2014
Old 11-03-2014 , 10:49   HP regenerator
Reply With Quote #1

Hello, i need a little help with HP regenerator.

I want to:
player can have max 140 HP
regenerator max can add 40 HP

Something like this: if player health is 100, regenerator will increase it till 140
but if player health is 20, regenerator will increase it only till 60

im using this code

Code:
#include <amxmodx>
#include <cstrike>
#include <fun>
#include <fakemeta>

new max_hp, hp_time, hp_give

public plugin_init()  
{
    register_plugin("VIP REGENERATOR", "1.0", "AMXMODX")
    
    max_hp = register_cvar("HR_maxhp", "140")
    hp_time = register_cvar("HR_hptime", "2")
    hp_give = register_cvar("HR_hpgive", "2")
    register_clcmd("say /reg", "generate_hp")
}

public generate_hp(id)
{
    new health = get_user_health(id)
    
    if(health >= get_pcvar_num(max_hp))
    {
        remove_task(id)
        return PLUGIN_CONTINUE
    }
    
    new hptogive = clamp(health + get_pcvar_num(hp_give), 0, get_pcvar_num(max_hp))    
    set_user_health(id, hptogive)
    
    return PLUGIN_CONTINUE
}
__________________


ArthHa is offline
Send a message via Skype™ to ArthHa
RateX
Veteran Member
Join Date: Jun 2012
Location: 0o. SEA .o0
Old 11-03-2014 , 11:25   Re: HP regenerator
Reply With Quote #2

try:
PHP Code:
#include <amxmodx>
#include <fun>

#define TASK_REGEN    328479239

new max_hphp_timehp_giveregen_hp[33]

public 
plugin_init()  
{
    
register_plugin("VIP REGENERATOR""1.0""AMXMODX")
    
    
max_hp register_cvar("HR_maxhp""140")
    
hp_time register_cvar("HR_hptime""2.0")
    
hp_give register_cvar("HR_hpgive""2")
    
register_clcmd("say /reg""generate_hp")
}

public 
generate_hp(id)
{
    if(!
task_exists(id TASK_REGEN))
    {
        
set_task(get_pcvar_float(hp_time), "regen"id TASK_REGEN__"b")
        
regen_hp[id] = 0
    
}
}

public 
regen(taskid)
{
    new 
id taskid TASK_REGEN
    
    
if(!is_user_alive(id) || regen_hp[id] == 40)
    {
        
remove_task(taskid)
        return
    }
    
    new 
health get_user_health(id)
    new 
maxhp get_pcvar_num(max_hp)
    new 
hpgive get_pcvar_num(hp_give)
    
    if((
health hpgive) >= maxhp)
    {
        
set_user_health(idmaxhp)
        
remove_task(taskid)
    }
    else 
    {
        
set_user_health(idhealth hpgive)
        
regen_hp[id] += hpgive
    
}

RateX is offline
ArthHa
Member
Join Date: Apr 2014
Old 11-03-2014 , 12:26   Re: HP regenerator
Reply With Quote #3

Quote:
Originally Posted by RateX View Post
try:
PHP Code:
#include <amxmodx>
#include <fun>

#define TASK_REGEN    328479239

new max_hphp_timehp_giveregen_hp[33]

public 
plugin_init()  
{
    
register_plugin("VIP REGENERATOR""1.0""AMXMODX")
    
    
max_hp register_cvar("HR_maxhp""140")
    
hp_time register_cvar("HR_hptime""2.0")
    
hp_give register_cvar("HR_hpgive""2")
    
register_clcmd("say /reg""generate_hp")
}

public 
generate_hp(id)
{
    if(!
task_exists(id TASK_REGEN))
    {
        
set_task(get_pcvar_float(hp_time), "regen"id TASK_REGEN__"b")
        
regen_hp[id] = 0
    
}
}

public 
regen(taskid)
{
    new 
id taskid TASK_REGEN
    
    
if(!is_user_alive(id) || regen_hp[id] == 40)
    {
        
remove_task(taskid)
        return
    }
    
    new 
health get_user_health(id)
    new 
maxhp get_pcvar_num(max_hp)
    new 
hpgive get_pcvar_num(hp_give)
    
    if((
health hpgive) >= maxhp)
    {
        
set_user_health(idmaxhp)
        
remove_task(taskid)
    }
    else 
    {
        
set_user_health(idhealth hpgive)
        
regen_hp[id] += hpgive
    
}


Thanks.
__________________


ArthHa is offline
Send a message via Skype™ to ArthHa
zmd94
Veteran Member
Join Date: Nov 2013
Location: Malaysia (9w2zow).
Old 11-03-2014 , 12:02   Re: HP regenerator
Reply With Quote #4

This is the other version.
PHP Code:
#include <amxmodx>
#include <fun>

public plugin_init()  
{
    
register_plugin("Health Regenerator""1.0""AUTHOR")
    
    
register_clcmd("say /reg""iRegenerate")
    
register_clcmd("say_team /reg""iRegenerate")
}

public 
iRegenerate(id)
{
    if(
is_user_alive(id))
    {
        new 
iHealth get_user_health(id)
        
        if(
iHealth >= 100 || iHealth >= 20)
        {
            
set_user_health(idiHealth 40)
        }   
    }


Last edited by zmd94; 11-03-2014 at 12:04.
zmd94 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 17:31.


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