AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Simple method to hp regenerate (https://forums.alliedmods.net/showthread.php?t=281264)

Awesome_man 04-07-2016 05:56

Simple method to hp regenerate
 
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 ?

Kowalsky 04-07-2016 07:29

Re: Simple method to hp regenerate
 
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 ) ) ); }

NiHiLaNTh 04-07-2016 07:48

Re: Simple method to hp regenerate
 
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)

gabuch2 04-07-2016 08:28

Re: Simple method to hp regenerate
 
Quote:

Originally Posted by NiHiLaNTh (Post 2408752)
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.

Kowalsky 04-07-2016 08:50

Re: Simple method to hp regenerate
 
Quote:

Originally Posted by NiHiLaNTh (Post 2408752)
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?

NiHiLaNTh 04-07-2016 09:11

Re: Simple method to hp regenerate
 
yes, it will. So if you have max health > 100, than you need to overwrite the pev_max_health field value.

Spoiler


Quote:

HamSandwich doesn't support every mod.
In theory this function should work on all mods (or at least on most of them)

Awesome_man 04-07-2016 11:29

Re: Simple method to hp regenerate
 
Quote:

Originally Posted by Kowalsky (Post 2408749)
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 ?

siriusmd99 04-07-2016 12:34

Re: Simple method to hp regenerate
 
Quote:

Originally Posted by Awesome_man (Post 2408805)
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.

HamletEagle 04-07-2016 13:03

Re: Simple method to hp regenerate
 
Quote:

Originally Posted by siriusmd99 (Post 2408823)
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.

EFFx 04-07-2016 17:05

Re: Simple method to hp regenerate
 
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




All times are GMT -4. The time now is 09:18.

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