Skip to content

Commit 8a7bf2c

Browse files
committedFeb 9, 2016
Added the ability to deal damage and skip all on_take_damage hooks
1 parent 4563f74 commit 8a7bf2c

File tree

1 file changed

+11
-3
lines changed
  • addons/source-python/packages/source-python/entities

1 file changed

+11
-3
lines changed
 

‎addons/source-python/packages/source-python/entities/specials.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ class _EntitySpecials(object):
3737

3838
def take_damage(
3939
self, damage, damage_type=DamageTypes.GENERIC, attacker_index=None,
40-
weapon_index=None, hitgroup=HitGroup.GENERIC, **kwargs):
40+
weapon_index=None, hitgroup=HitGroup.GENERIC, skip_hooks=False,
41+
**kwargs):
4142
"""Method used to hurt the entity with the given arguments."""
4243
# Import Entity classes
4344
# Doing this in the global scope causes cross import errors
@@ -136,5 +137,12 @@ def take_damage(
136137
# Set the offset's value
137138
setattr(take_damage_info, item, kwargs[item])
138139

139-
# Call the function with the victim's pointer and the CTakeDamageInfo
140-
self.on_take_damage(take_damage_info)
140+
if skip_hooks:
141+
try:
142+
# Try calling the trampoline
143+
self.on_take_damage.call_trampoline(take_damage_info)
144+
except ValueError:
145+
# If it failed, the function probably wasn't hooked
146+
self.on_take_damage(take_damage_info)
147+
else:
148+
self.on_take_damage(take_damage_info)

0 commit comments

Comments
 (0)
Please sign in to comment.