Raised This Month: $ Target: $400
 0% 

HAM_OVERRIDE usage in Ham_TakeDamage event to change value


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
XxAvalanchexX
Veteran Member
Join Date: Oct 2004
Location: abort73.com
Old 03-04-2009 , 23:36   Re: HAM_OVERRIDE usage in Ham_TakeDamage event to change value
Reply With Quote #2

Hi,

To answer your original question, you could override the return value like this:

Code:
public plugin_init() {     RegisterHam(Ham_TakeDamage,"player","ham_player_takedamage",0); } public ham_player_takedamage(id,idinflictor,idattacker,Float:damage,damagebits) {     SetHamReturnInteger(42);     return HAM_OVERRIDE; }

In addition to SetHamReturnInteger, there is SetHamReturnFloat, SetHamReturnVector, SetHamReturnEntity, and SetHamReturnString, depending on the return type of the function.

It seems that using HAM_OVERRIDE will let the original TakeDamage go through as usual, but instead of returning whatever it would normally return, it will return what you set. In comparison, using HAM_SUPERCEDE will stop the original TakeDamage function entirely, in addition to returning what you set.

However, the catch here is that the return value for TakeDamage isn't the amount of damage done. The amount of damage is actually passed as a parameter. So you can either stop the original TakeDamage and do another with your new damage, or potentially change the value of the parameter.

Here is how you would do the former:

Code:
#define DMG_GRENADE (1<<24) // thanks arkshine public plugin_init() {     RegisterHam(Ham_TakeDamage,"player","ham_player_takedamage",0); } public ham_player_takedamage(id,idinflictor,idattacker,Float:damage,damagebits) {     if(damage == 195.0 && !(damagebits & DMG_GRENADE) && is_user_connected(idattacker) && get_user_weapon(idattacker) == CSW_KNIFE)     {         ExecuteHamB(Ham_TakeDamage,id,idinflictor,idattacker,65.0,damagebits);         return HAM_SUPERCEDE;     }     return HAM_IGNORED; }

The latter method, which I've never tried but should work, would go like this:

Code:
public plugin_init() {     RegisterHam(Ham_TakeDamage,"player","ham_player_takedamage",0); } public ham_player_takedamage(id,idinflictor,idattacker,Float:damage,damagebits) {     if(damage == 195.0 && !(damagebits & DMG_GRENADE) && is_user_connected(idattacker) && get_user_weapon(idattacker) == CSW_KNIFE)     {         SetHamParamFloat(4,65.0);         return HAM_OVERRIDE;     }     return HAM_IGNORED; }

Again, there are several other SetHamParam* functions based on the paramater type. The first paramter for SetHamParamFloat is 4 because that is the parameter number for damage in TakeDamage (id would be parameter 1). I'm not sure if you actually need to use HAM_OVERRIDE for this case; you could try both with and without and see what works.

The only other thing you should be careful of is to make sure that the knife damage done is really 195.0 exactly, not some other decimal value or a higher number that gets reduced because of armor. If it is something weird, you could probably just check to see if the damage is more than or equal to 195.0 and is not a headshot.

Hopefully this helps you.

Cheers,

Ava
__________________
No longer around. Thanks your support, everyone! As always:
THIS ONES FOR YOU
3000 PTS

Last edited by BAILOPAN; 03-10-2009 at 02:45.
XxAvalanchexX is offline
 



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:07.


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