Raised This Month: $ Target: $400
 0% 

HAM_OVERRIDE usage in Ham_TakeDamage event to change value


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Owyn
Veteran Member
Join Date: Nov 2007
Old 03-04-2009 , 16:20   HAM_OVERRIDE usage in Ham_TakeDamage event to change value
Reply With Quote #1

i heard HAM_OVERRIDE make call still be executed, but instead will change the return value. so i want to change value in ham_takedamage with HAM_OVERRIDE cuz there's a bug on my server so sometimes knife right attack can hit player in non-body-part and deal 195dmg (mb a generic hitzone or something like that), so i want make a check if dmg is 195 and weapon made this dmg is a knife and change 195 to 65 and let other plugins or this plugin extension take care of changed dmg, but i saw almost no HAM_OVERRIDE usage in plugins so i'm asking how to.
Owyn is offline
Send a message via ICQ to Owyn
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
Owyn
Veteran Member
Join Date: Nov 2007
Old 03-05-2009 , 04:11   Re: HAM_OVERRIDE usage in Ham_TakeDamage event to change value
Reply With Quote #3

why do you check for dmg_grenade? =\ can knife deal dmg with granade damagetype? =\

* thx, works fine ^_^ now players will be able to have fun at knife maps normally
Owyn is offline
Send a message via ICQ to Owyn
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 03-05-2009 , 06:14   Re: HAM_OVERRIDE usage in Ham_TakeDamage event to change value
Reply With Quote #4

Quote:
I'm not sure if you actually need to use HAM_OVERRIDE for this case;
HAM_HANDLED; is fine here.
Arkshine is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 03-05-2009 , 07:19   Re: HAM_OVERRIDE usage in Ham_TakeDamage event to change value
Reply With Quote #5

Quote:
Originally Posted by .Owyn. View Post
why do you check for dmg_grenade? =\ can knife deal dmg with granade damagetype? =\
He is making sure that the damage dealt was not from a grenade.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Owyn
Veteran Member
Join Date: Nov 2007
Old 03-05-2009 , 07:52   Re: HAM_OVERRIDE usage in Ham_TakeDamage event to change value
Reply With Quote #6

Quote:
Originally Posted by Exolent[jNr] View Post
He is making sure that the damage dealt was not from a grenade.
i think i get it now, player throws a granade then switches to knife at time granade deals dmg... but anyway, how come granade can deal 195dmg?
Owyn is offline
Send a message via ICQ to Owyn
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 03-05-2009 , 08:48   Re: HAM_OVERRIDE usage in Ham_TakeDamage event to change value
Reply With Quote #7

HE CHECKS IF DAMAGE IS NOT FROM GRENADE BUT OTHER WEAPON!

Learn to read FFS...
__________________
hleV is offline
Owyn
Veteran Member
Join Date: Nov 2007
Old 03-05-2009 , 08:58   Re: HAM_OVERRIDE usage in Ham_TakeDamage event to change value
Reply With Quote #8

^^ forgot to read
but what for is that check needed anyway? ^^"
Owyn is offline
Send a message via ICQ to Owyn
XxAvalanchexX
Veteran Member
Join Date: Oct 2004
Location: abort73.com
Old 03-05-2009 , 23:36   Re: HAM_OVERRIDE usage in Ham_TakeDamage event to change value
Reply With Quote #9

Quote:
Originally Posted by arkshine View Post
HAM_HANDLED; is fine here.
Cool, I didn't know that! Thank you.

.Owyn.: You have it right. I check to make sure that the damage is not from a grenade, so that it won't count if they throw a grenade and then switch to the knife. I don't know if a grenade can actually deal 195.0 damage or not; I just put it there for safety. You can probably remove it and not have any problems if you'd like.
__________________
No longer around. Thanks your support, everyone! As always:
THIS ONES FOR YOU
3000 PTS
XxAvalanchexX is offline
MeRcyLeZZ
Veteran Member
Join Date: Dec 2007
Old 03-07-2009 , 21:31   Re: HAM_OVERRIDE usage in Ham_TakeDamage event to change value
Reply With Quote #10

I'm guessing CZ nades can deal that much, so it's not an useless check after all heh.
__________________
MeRcyLeZZ 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:02.


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