You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 codedisabled=Falsedefinternal_hook(args):
ifdisabled:
returnOnTakeDamage.manager.notify(...)
deftake_damage(self, ..., skip_hooks=True): # Let it default to Trueglobaldisableddisabled=skip_hooks# Use try/finally just to be suretry:
really_do_damage()
finally:
disabled=False
# Plugin code@OnTakeDamagedefon_take_damage(entity, info):
# You can call it directlytake_damage()
# Or delayeddelay(10, take_damage)
# Or from somewhere elsetake_damage()
The listener would also make hooking on_take_damage much easier for plugin authors.
The text was updated successfully, but these errors were encountered:
* Added the ability to disable hooks
Generic fix for issue #236
* Moved HooksDisabled-check to the top
* Updated documentation for hooks_disabled context manager
skip_hooks=True
doesn't work as expected, becauseon_take_damage
is a virtual function. Example:on_take_damage
on a human player.take_damage
withskip_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:The listener would also make hooking
on_take_damage
much easier for plugin authors.The text was updated successfully, but these errors were encountered: