Raised This Month: $ Target: $400
 0% 

Simple method to hp regenerate


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Awesome_man
Senior Member
Join Date: May 2014
Location: singapore
Old 04-07-2016 , 05:56   Simple method to hp regenerate
Reply With Quote #1

How can i regenerate hp gradually i mean if my hp is less than 100 it should regenerate like +5hp per 0.5 seconds till 100 ? What is the simple and easy way to do that ?

Last edited by Awesome_man; 04-07-2016 at 05:57.
Awesome_man is offline
Kowalsky
Senior Member
Join Date: Mar 2015
Location: Poland
Old 04-07-2016 , 07:29   Re: Simple method to hp regenerate
Reply With Quote #2

Code:
#include < amxmodx > #include < fakemeta > public client_putinserver( id )           set_task( 0.5, "regen", id + 174, _, _, "b" ); public regen( id ) {           id -= 174;           if( is_user_alive( id ) )                   set_pev( id, pev_health, float( clamp( floatround( pev( id, pev_health ) ) + 5, 1, 100 ) ) ); }
__________________
I ONLY LOVE STEAM, NON-STEAM IS VERY BAD FOR YOUR HEALTH!

Last edited by Kowalsky; 04-07-2016 at 07:39.
Kowalsky is offline
Awesome_man
Senior Member
Join Date: May 2014
Location: singapore
Old 04-07-2016 , 11:29   Re: Simple method to hp regenerate
Reply With Quote #3

Quote:
Originally Posted by Kowalsky View Post
Code:
#include < amxmodx > #include < fakemeta > public client_putinserver( id )           set_task( 0.5, "regen", id + 174, _, _, "b" ); public regen( id ) {           id -= 174;           if( is_user_alive( id ) )                   set_pev( id, pev_health, float( clamp( floatround( pev( id, pev_health ) ) + 5, 1, 100 ) ) ); }
What if i don't use task then how can i do that for 0.5 second ?
Awesome_man is offline
siriusmd99
Veteran Member
Join Date: Oct 2013
Location: Republic of Moldova
Old 04-07-2016 , 12:34   Re: Simple method to hp regenerate
Reply With Quote #4

Quote:
Originally Posted by Awesome_man View Post
What if i don't use task then how can i do that for 0.5 second ?
you can use think but it's more efficient to use a task.
siriusmd99 is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 04-07-2016 , 13:03   Re: Simple method to hp regenerate
Reply With Quote #5

Quote:
Originally Posted by siriusmd99 View Post
you can use think but it's more efficient to use a task.
Not really, but Think should be used when you want a more precise timer, task can have the minimum repeat time 0.1

If you don't use a task, you could create a trigger_hurt entity, set it dmg to -value, so it will heal instead of hurting.
Also, maybe you can play with m_idrowndmg offset, so game will heal the player automatically.
__________________
HamletEagle is offline
Kowalsky
Senior Member
Join Date: Mar 2015
Location: Poland
Old 04-07-2016 , 17:06   Re: Simple method to hp regenerate
Reply With Quote #6

Quote:
Originally Posted by HamletEagle View Post
Not really, but Think should be used when you want a more precise timer, task can have the minimum repeat time 0.1

If you don't use a task, you could create a trigger_hurt entity, set it dmg to -value, so it will heal instead of hurting.
Also, maybe you can play with m_idrowndmg offset, so game will heal the player automatically.
Could you please provide an example of healing with m_idrowndmg offset? That sounds quite interesting to me, I haven't found any examples around.

E:
Quote:
Originally Posted by EFFx View Post
PHP Code:
#include <amxmodx>
#include <fun>
 
#define PLUGIN "HP Regen"
#define VERSION "1.0"
#define AUTHOR "EFFx"
 
new HpAdd
new HpMax
 
public plugin_init() 
{
 
register_plugin(PLUGINVERSIONAUTHOR)
 
 
HpAdd register_cvar("hp_add","5")
 
HpMax register_cvar("hp_max","100")
}
public 
client_putinserver(idset_task(1.0,"hp_add")
public 
hp_add(id)
{
 
remove_task(id);
 if(!
is_user_alive(id))
 return 
PLUGIN_HANDLED;
 
set_user_health(idget_user_health(id) + get_pcvar_num(HpAdd))
 if( 
get_user_health(id) > get_pcvar_num(HpMax)) 
 {
  
set_user_health(idget_pcvar_num(HpMax))
 }
 
set_task(1.0"hp_add"id)
 return 
PLUGIN_HANDLED

Goddamn it looks so inefficient. Setting task every second, so many unnecessary native calls, variables are not cached. No offense, but I wouldn't recommend using this.
__________________
I ONLY LOVE STEAM, NON-STEAM IS VERY BAD FOR YOUR HEALTH!

Last edited by Kowalsky; 04-07-2016 at 17:10.
Kowalsky is offline
Awesome_man
Senior Member
Join Date: May 2014
Location: singapore
Old 04-08-2016 , 02:42   Re: Simple method to hp regenerate
Reply With Quote #7

Quote:
Originally Posted by Kowalsky View Post
Code:
#include < amxmodx > #include < fakemeta > public client_putinserver( id )           set_task( 0.5, "regen", id + 174, _, _, "b" ); public regen( id ) {           id -= 174;           if( is_user_alive( id ) )                   set_pev( id, pev_health, float( clamp( floatround( pev( id, pev_health ) ) + 5, 1, 100 ) ) ); }
It should work fine i want to regenerate hp if player ducking at rate of 5hp per 0.5 seconds till 100 ?

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>

public client_putinserver(id)
{

set_task0.5"regen"id 174__"b" );
}

public 
regen(id)
{
    
id -= 174;
    if(
is_user_alive(id) && !is_user_bot(id))
{
   
      if(
pev(idpev_flags) & FL_DUCKING)
{

     
set_pevidpev_healthfloatclampfloatroundpevidpev_health ) ) + 51100 ) ) );
}
}


Last edited by Awesome_man; 04-08-2016 at 02:44.
Awesome_man is offline
NiHiLaNTh
Way Past Expiration
Join Date: May 2009
Location: Latvia
Old 04-07-2016 , 07:48   Re: Simple method to hp regenerate
Reply With Quote #8

Code:
set_pev( id, pev_health, float( clamp( floatround( pev( id, pev_health ) ) + 5, 1, 100 ) ) );
-->
Code:
ExecuteHamB(Ham_TakeHealth, id, 5.0, DMG_GENERIC)
__________________

NiHiLaNTh is offline
Send a message via Skype™ to NiHiLaNTh
gabuch2
AlliedModders Donor
Join Date: Mar 2011
Location: Chile
Old 04-07-2016 , 08:28   Re: Simple method to hp regenerate
Reply With Quote #9

Quote:
Originally Posted by NiHiLaNTh View Post
Code:
set_pev( id, pev_health, float( clamp( floatround( pev( id, pev_health ) ) + 5, 1, 100 ) ) );
-->
Code:
ExecuteHamB(Ham_TakeHealth, id, 5.0, DMG_GENERIC)
HamSandwich doesn't support every mod.
__________________

Last edited by gabuch2; 04-07-2016 at 08:29.
gabuch2 is offline
Kowalsky
Senior Member
Join Date: Mar 2015
Location: Poland
Old 04-07-2016 , 08:50   Re: Simple method to hp regenerate
Reply With Quote #10

Quote:
Originally Posted by NiHiLaNTh View Post
Code:
set_pev( id, pev_health, float( clamp( floatround( pev( id, pev_health ) ) + 5, 1, 100 ) ) );
-->
Code:
ExecuteHamB(Ham_TakeHealth, id, 5.0, DMG_GENERIC)

Nice, didn't know you could do so with HAM. Will take in account in my future codes.

Does pev_max_health affect the max healing value if using HAM?
__________________
I ONLY LOVE STEAM, NON-STEAM IS VERY BAD FOR YOUR HEALTH!

Last edited by Kowalsky; 04-07-2016 at 08:51.
Kowalsky 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 09:18.


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