-
Notifications
You must be signed in to change notification settings - Fork 36
Closed
Labels
Description
skip_hooks=True doesn't work as expected, because on_take_damage is a virtual function. Example:
- Hook
on_take_damageon a human player. - Call
take_damagewithskip_hooks=Trueon 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.
Mahi and thetredev