Raised This Month: $ Target: $400
 0% 

Simple method to hp regenerate


Post New Thread Reply   
 
Thread Tools Display Modes
Kowalsky
Senior Member
Join Date: Mar 2015
Location: Poland
Old 04-07-2016 , 17:06   Re: Simple method to hp regenerate
Reply With Quote #11

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
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 04-07-2016 , 18:43   Re: Simple method to hp regenerate
Reply With Quote #12

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


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.

No problem:

PHP Code:
#include <amxmodx>
#include <hamsandwich>
#include <cstrike>
#include <fun>

#define PLUGIN "HP Regen"
#define VERSION "1.0"
#define AUTHOR "EFFx"

enum(+= 1000)
{
 
TASK_REGEN
}

new const 
ON_OFF[][] =
{
 
"\r[OFF]",
 
"\y[ON]"
}

new 
HpAdd
new HpMax
new HpAddTime

new hp[33],g_activ_hp[33]

public 
plugin_init() 
{
 
register_plugin(PLUGINVERSIONAUTHOR)
 
 
RegisterHam(Ham_Spawn,"player","Reset",1)
 
 
register_clcmd("say /hpregen","ShowMenu")
 
 
HpAddTime register_cvar("hp_regen_time","1.0")
 
HpAdd register_cvar("hp_regen_add","5")
 
HpMax register_cvar("hp_regen_max","100")
}
public 
client_putinserver(id)
{
 
hp[id] = 0
 g_activ_hp
[id] = 0
}
public 
Reset(id
{
 
hp[id] = 0
 g_activ_hp
[id] = 0
}
public 
ShowMenu(id)
{
 if(
is_user_alive(id))
 {
  new 
MenuFormat[128]
  new 
szMenu menu_create("Hp regen menu","handler_hpregen")
  
formatex(MenuFormat,charsmax(MenuFormat),hp[id] == "HP Regen %s" "HP Regen %s",ON_OFF[g_activ_hp[id]])
  
menu_additem(szMenu,MenuFormat)
  
  
menu_display(id,szMenu)
 }
 else
 {
  
client_print(id,print_chat,"[AMXX]: You need to be alive for open the menu!")
 }
 return 
PLUGIN_HANDLED
}
public 
handler_hpregen(id,menu,item)
{
 if(
item == MENU_EXIT)
 {
  
menu_destroy(menu)
  return 
PLUGIN_HANDLED
 
}
 switch(
item)
 {
  case 
0:
  {
   switch(
hp[id])
   {
    case 
0:
    {
     
client_print(id,print_chat,"[AMXX]: You have now the hp regenerate!")
     
hp[id] = 1
     g_activ_hp
[id] = 1
     set_task
(get_pcvar_float(HpAddTime),"hp_add",id+TASK_REGEN,_,_,"b")
    }
    case 
1:
    {
     
hp[id] = 0
     g_activ_hp
[id] = 0
     hp_add
(id)
     
remove_task(id+TASK_REGEN)
    }
   }
  }
 }
 
ShowMenu(id)
 return 
PLUGIN_HANDLED
}
public 
hp_add(id)
{
 if(
g_activ_hp[id] == 1)
 {
  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))
   
g_activ_hp[id] = 0
   ShowMenu
(id)
   
client_print(id,print_chat,"[AMXX]: Your hp regenerate has been set to the maximum!")
   
remove_task(id+TASK_REGEN)
   return 
PLUGIN_HANDLED
  
}
 }
 return 
PLUGIN_HANDLED

If you want to buy:

PHP Code:
#include <amxmodx>
#include <hamsandwich>
#include <cstrike>
#include <fun>
 
#define PLUGIN "HP Regen"
#define VERSION "1.0"
#define AUTHOR "EFFx"
 
enum(+= 1000)
{
 
TASK_REGEN
}
new const 
ON_OFF[][] =
{
 
"\r[OFF]",
 
"\y[ON]"
}
 
new 
HpAdd
new HpMax
new HpAddTime
 
new hp[33],g_activ_hp[33]
 
public 
plugin_init() 
{
 
register_plugin(PLUGINVERSIONAUTHOR)
 
 
RegisterHam(Ham_Spawn,"player","Reset",1)
 
 
register_clcmd("say /hpregen","ShowMenu")
 
 
HpAddTime register_cvar("hp_regen_time","1.0")
 
HpAdd register_cvar("hp_regen_add","5")
 
HpMax register_cvar("hp_regen_max","100")
}
public 
client_putinserver(id)
{
 
hp[id] = 0
 g_activ_hp
[id] = 0
}
public 
Reset(id
{
 
hp[id] = 0
 g_activ_hp
[id] = 0
}
public 
ShowMenu(id)
{
 if(
is_user_alive(id))
 {
  new 
MenuFormat[128]
  new 
szMenu menu_create("Hp regen menu","handler_hpregen")
  
formatex(MenuFormat,charsmax(MenuFormat),hp[id] == "HP Regen %s" "HP Regen %s",ON_OFF[g_activ_hp[id]])
  
menu_additem(szMenu,MenuFormat)
  
  
menu_display(id,szMenu)
 }
 else
 {
  
client_print(id,print_chat,"[AMXX]: You need to be alive for open the menu!")
 }
 return 
PLUGIN_HANDLED
}
public 
handler_hpregen(id,menu,item)
{
 if(
item == MENU_EXIT)
 {
  
menu_destroy(menu)
  return 
PLUGIN_HANDLED
 
}
 switch(
item)
 {
  case 
0:
  {
   switch(
hp[id])
   {
    case 
0:
    {
     new 
iPrice cs_get_user_money(id) - 5000
     
if(iPrice 0)
     {
      
client_print(id,print_chat,"[AMXX]: You've not sufficient founds to buy hp regenerate!")
     }
     else
     {
      if(
get_user_health(id) == get_pcvar_num(HpMax))
      {
       
client_print(id,print_chat,"[AMXX]: You already have the maximum hp for regenerate!")
      }
      else
      {
       
client_print(id,print_chat,"[AMXX]: You have now the hp regenerate!")
       
hp[id] = 1
       g_activ_hp
[id] = 1
       set_task
(get_pcvar_float(HpAddTime),"hp_add",id+TASK_REGEN,_,_,"b")
       
cs_set_user_money(id,iPrice)
      }
     }
    }
    case 
1:
    {
     
hp[id] = 0
     g_activ_hp
[id] = 0
     hp_add
(id)
     
remove_task(id+TASK_REGEN)
    }
   }
  }
 }
 
ShowMenu(id)
 return 
PLUGIN_HANDLED
}
public 
hp_add(id)
{
 if(
g_activ_hp[id] == 1)
 {
  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))
   
g_activ_hp[id] = 0
   ShowMenu
(id)
   
client_print(id,print_chat,"[AMXX]: Your hp regenerate has been set to the maximum!")
   
remove_task(id+TASK_REGEN)
   return 
PLUGIN_HANDLED
  
}
 }
 return 
PLUGIN_HANDLED

__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo

Last edited by EFFx; 04-07-2016 at 19:49.
EFFx 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 #13

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
Chihuahuax
Senior Member
Join Date: Oct 2014
Location: Malaysia
Old 04-08-2016 , 02:51   Re: Simple method to hp regenerate
Reply With Quote #14

No offense EFFx but u really need to improve your scripting skill
Chihuahuax is offline
Send a message via Skype™ to Chihuahuax
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 04-08-2016 , 03:05   Re: Simple method to hp regenerate
Reply With Quote #15

Create only one task in plugin_init and loop all players. Don't create 32 tasks.
__________________
HamletEagle is offline
NiHiLaNTh
Way Past Expiration
Join Date: May 2009
Location: Latvia
Old 04-08-2016 , 04:44   Re: Simple method to hp regenerate
Reply With Quote #16

omg I already told you to use Ham_TakeHealth, it does all the checks for you, really.
__________________

NiHiLaNTh is offline
Send a message via Skype™ to NiHiLaNTh
Kowalsky
Senior Member
Join Date: Mar 2015
Location: Poland
Old 04-08-2016 , 04:46   Re: Simple method to hp regenerate
Reply With Quote #17

Try this :

Code:
#include < amxmodx > #include < fakemeta > #include < hamsandwich > public plugin_init( ) {     register_plugin( "Simple HP Regen", "1.0", "Podarok" );         set_task( 0.5, "regenerate", 1337, _, _, "b" ); } public regenerate( ) {     new iPlayers[ 32 ], iCount, i, id;     get_players( iPlayers, iCount, "ac" );         for ( i = 0; i < iCount; i++ ) {         id = iPlayers[ i ];                 if( pev( id, pev_bInDuck ) )             ExecuteHamB( Ham_TakeHealth, id, 5.0, DMG_GENERIC );     } } public plugin_end( )     remove_task( 1337 );

Or use the code that EFFX provided, he seems to be a decent coder.
__________________
I ONLY LOVE STEAM, NON-STEAM IS VERY BAD FOR YOUR HEALTH!

Last edited by Kowalsky; 04-08-2016 at 09:45.
Kowalsky is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 04-08-2016 , 07:06   Re: Simple method to hp regenerate
Reply With Quote #18

Quote:
Originally Posted by Kowalsky View Post
Try this :

Code:
#include < amxmodx > #include < fakemeta > #include < hamsandwich > public plugin_init( ) {     register_plugin( "Simple HP Regen", "1.0", "Podarok" );         set_task( 0.5, "regenerate", 1337, _, _, "b" ); } public regenerate( ) {     new iPlayers[ 32 ], iCount, i;     get_players( iPlayers, iCount, "ac" );         for ( i = 0; i < iCount; i++ ) {         id = iPlayers[ i ];                 if( pev( id, pev_bInDuck ) )             ExecuteHamB( Ham_TakeHealth, id, 5.0, DMG_GENERIC );     } } public plugin_end( )     remove_task( 1337 );

Or use the code that EFFX provided, he seems to be a decent coder.
He clearly isn't.
__________________
HamletEagle is offline
Kowalsky
Senior Member
Join Date: Mar 2015
Location: Poland
Old 04-08-2016 , 09:40   Re: Simple method to hp regenerate
Reply With Quote #19

Quote:
Originally Posted by HamletEagle View Post
He clearly isn't.
I was being sarcastic at that point.

Also wanted to ask - is it really more efficient to set one task looping through all players rather than setting a task for each individual player? In this here case I agree one task instead of 32 is way much better, but let's imagine a case where only 1/3 of all clients are needed to be set on the task.
__________________
I ONLY LOVE STEAM, NON-STEAM IS VERY BAD FOR YOUR HEALTH!

Last edited by Kowalsky; 04-08-2016 at 09:47.
Kowalsky is offline
siriusmd99
Veteran Member
Join Date: Oct 2013
Location: Republic of Moldova
Old 04-08-2016 , 11:32   Re: Simple method to hp regenerate
Reply With Quote #20

Quote:
Originally Posted by Kowalsky View Post
I was being sarcastic at that point.

Also wanted to ask - is it really more efficient to set one task looping through all players rather than setting a task for each individual player? In this here case I agree one task instead of 32 is way much better, but let's imagine a case where only 1/3 of all clients are needed to be set on the task.
1/3 clients > one task

It's anyway efficient because it will loop only 1/3 of players (with get_players and after that for cycle).

There are different methods, one of them is to set individual task on ham_spawn and remove it on disconnect or deathevent so that task won't work useless.

In conclusion I can say that the best method is to set a task on ham_takedamage for the player and heal him until he gets 100 hp and then remove task.

Last edited by siriusmd99; 04-08-2016 at 11:34.
siriusmd99 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