skip_hooks=True doesn't work as expected, because on_take_damage is a virtual function. Example:
- Hook
on_take_damage on a human player.
- Call
take_damage with skip_hooks=True on a bot.
The hook will still get called, because bots have their own implementation (CCSBot) of on_take_damage which later calls the overwritten implementation (CCSPlayer).
One workaround would be to create an OnTakeDamage listener and let Source.Python call the listener from an internal hook. Here's some pseudo-code:
# Internal SP code
disabled = False
def internal_hook(args):
if disabled:
return
OnTakeDamage.manager.notify(...)
def take_damage(self, ..., skip_hooks=True): # Let it default to True
global disabled
disabled = skip_hooks
# Use try/finally just to be sure
try:
really_do_damage()
finally:
disabled = False
# Plugin code
@OnTakeDamage
def on_take_damage(entity, info):
# You can call it directly
take_damage()
# Or delayed
delay(10, take_damage)
# Or from somewhere else
take_damage()
The listener would also make hooking on_take_damage much easier for plugin authors.
skip_hooks=Truedoesn't work as expected, becauseon_take_damageis a virtual function. Example:on_take_damageon a human player.take_damagewithskip_hooks=Trueon a bot.The hook will still get called, because bots have their own implementation (CCSBot) of
on_take_damagewhich later calls the overwritten implementation (CCSPlayer).One workaround would be to create an
OnTakeDamagelistener and let Source.Python call the listener from an internal hook. Here's some pseudo-code:The listener would also make hooking
on_take_damagemuch easier for plugin authors.