Raised This Month: $51 Target: $400
 12% 

Solved [HELP] Detect or block player healing events after drowning in water?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
felhasznalo
AlliedModders Donor
Join Date: Aug 2015
Location: Hungary
Old 08-11-2015 , 04:33   [HELP] Detect or block player healing events after drowning in water?
Reply With Quote #1

When a player comes out of water after drowning (taking DMG_DROWN damage), his/her health will regenerate slowly over time.
Where could I find this healing event, and how could I block it?

Last edited by felhasznalo; 09-18-2017 at 08:01.
felhasznalo is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 08-11-2015 , 05:18   Re: [HELP] Detect or block player healing events after drowning in water?
Reply With Quote #2

No event needed.
PHP Code:
const m_idrowndmg       345
const m_idrownrestored  346

set_pdata_int
(idm_idrownrestoredget_pdata_int(idm_idrowndmg)) 
m_idrowndmg is the drown damage that a player got.
m_idrownrestored is the ammount of hp that was restored after the drown occured. We trick the game and make it think that all the damage was restored. You may also reset m_rgbTimeBasedDamage[itbd_DrownRecover](if for amxx < 1.8.3 use set_pdata_char, else set_pdata_byte) but game will do this on next drown dmg automatically.

Reference: https://github.com/Arkshine/CSSDK/bl...lls/player.cpp
__________________

Last edited by HamletEagle; 08-11-2015 at 05:59.
HamletEagle is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 08-11-2015 , 06:19   Re: [HELP] Detect or block player healing events after drowning in water?
Reply With Quote #3

I believe you can just hook CBasePlayer::TakeHealth():
Code:
/**  
 * Description:     Usually called whenever an entity gets a form of a heal.  
 * Forward params:  function(this, Float:health, damagebits); 
 * Return type:     Integer. 
 * Execute params:  ExecuteHam(Ham_TakeHealth, this, Float:health, damagebits); 
 */ 
 Ham_TakeHealth
I don't know what else is it called for, but it is called to recover player from drowning. In that event you could play with member offsets HalmetEagle posted before me, to check if he is really recovering.

Last edited by klippy; 08-11-2015 at 06:20.
klippy is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 08-11-2015 , 19:22   Re: [HELP] Detect or block player healing events after drowning in water?
Reply With Quote #4

Quote:
Originally Posted by HamletEagle View Post
No event needed.
const m_idrowndmg = 345
const m_idrownrestored = 346

set_pdata_int(id, m_idrownrestored, get_pdata_int(id, m_idrowndmg))
@HamletEagle: I know this goes without saying, but you need an event or some means of detecting when the player took this damage or heal. Also, it would be better to set m_idrownrestored one time to a value that will make the condition always false if (m_idrowndmg > m_idrownrestored), instead of incrementing it with each piece of damage.

This will set m_idrownrestored on the first heal (which is blocked) which will prevent any future heals from being called on that player for the rest of the round.
PHP Code:
#include <amxmodx>
#include <hamsandwich>
#include <fakemeta>

public plugin_init() 
{
    
RegisterHamHam_TakeHealth "player" "TakeHealth" );
}
 
public 
TakeHealthiPlayer Float:fHealthHealed DamageBits )
{
    const 
m_idrownrestored 346;
    
    
set_pdata_intiPlayer m_idrownrestored 100 );
    
    return 
HAM_SUPERCEDE;

__________________

Last edited by Bugsy; 08-11-2015 at 22:05.
Bugsy is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 08-12-2015 , 05:11   Re: [HELP] Detect or block player healing events after drowning in water?
Reply With Quote #5

I meant no event need to be blocked. Of course he need an event to detect, but his question was how to block it, so I assumed that he already knows.
Anyway, setting to 100 doesn't seem to be best way, there are custom mods like furien/zm which set health to bigger values. Probably better to get his health at spawn and use that value.
__________________

Last edited by HamletEagle; 08-12-2015 at 05:17.
HamletEagle is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 08-12-2015 , 07:11   Re: [HELP] Detect or block player healing events after drowning in water?
Reply With Quote #6

I thought about setting it at spawn as well but thought it was more relevant to set it when a heal attempt is made instead of setting it on every player every round. I went with 100 assuming no other mods..set it to 5000 instead? I'm not sure what data type is used in the game to store that value.
__________________
Bugsy is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 08-12-2015 , 08:42   Re: [HELP] Detect or block player healing events after drowning in water?
Reply With Quote #7

In zm some players have like 60.000 hp. I think that we should not hardcode the value and do something like that(wrote the snippet from phone, but you get the point).
PHP Code:
new Float:PlayerHealth[33]

public 
CBasePlayer_Spawn(id)
{
    if(
is_user_alive(id)
    {
         
pev(idpev_healthPlayerHealth[id])
    }
}

//later, in CBasePlayer::TakeHealth
set_pdata_int(idm_idrownrestored PlayerHealth[id]) 
__________________

Last edited by HamletEagle; 08-12-2015 at 09:41.
HamletEagle is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 08-12-2015 , 09:35   Re: [HELP] Detect or block player healing events after drowning in water?
Reply With Quote #8

I don't see the point in setting it to health or any other retrieved value, can you give a reason for this? Hard coded to a value that will always make the condition false to prevent TakeHealth from being called again seems best to me.
__________________
Bugsy is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 08-12-2015 , 09:39   Re: [HELP] Detect or block player healing events after drowning in water?
Reply With Quote #9

Because we don't know what value to use, it really depends on the server and the mod that is running.
__________________
HamletEagle is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 08-12-2015 , 11:02   Re: [HELP] Detect or block player healing events after drowning in water?
Reply With Quote #10

Suppose you used spawn health but there is a mod that gives additional health beyond spawn health? Simply setting the value to an unreachably high value is better and safer IMO.
__________________
Bugsy is offline
Old 08-12-2015, 11:02
Bugsy
This message has been deleted by Bugsy. Reason: Double post
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:02.


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