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
__________________