point_hurt: cs go

Please post any questions about developing your plugin here. Please use the search function before posting!
arawra
Senior Member
Posts: 190
Joined: Fri Jun 21, 2013 6:51 am

Postby arawra » Wed May 27, 2015 3:30 pm

That seems to me to be more convoluted. Wouldn't KISS be a better approach in this circumstance? I do have to use point_hurt already for other things.
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Wed May 27, 2015 3:37 pm

What do you mean you "have to use point_hurt" for other things? Any damage you wish to deal can easily be done with <entity>.take_damage without the need of point_hurt.

I really don't see how adjusting the damage within an on_take_damage prehook and then using a TickRepeat or tick_delay.delay to deal further damage is 'convoluted'. The latter portion is pretty much what you would want to do anyway with the extra damage not dealt right then. The only difference is that you would just need to adjust the damage amount instead of creating a point_hurt object to deal further damage immediately.
Image
arawra
Senior Member
Posts: 190
Joined: Fri Jun 21, 2013 6:51 am

Postby arawra » Wed May 27, 2015 3:41 pm

I remember what the problem was...

The weapon is the same as the original attack, so if you nest it you can not determine when to stop the recursion.
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Wed May 27, 2015 7:06 pm

To call the original function within a hook, we have added a call_trampoline() method. Though, that will probably not help in this particular case, because we are hooking OnTakeDamage, but calling TakeDamage. : /
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Wed May 27, 2015 7:29 pm

Actually, I think you would call OnTakeDamage, as well. The reason we are using that function instead of TakeDamage is that it bypasses damage filters which modify the damage given.
Image
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Wed May 27, 2015 7:43 pm

Correct, Entity.take_damage is calling Entity.on_take_damage internally: ../source-python/packages/source-python/entities/specials.py#L143
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Wed May 27, 2015 7:49 pm

Oh, you right. I just checked the code. Well, in that case it would be quite easy to get rid of this problem. We could also update our take_damage() method so that it takes an additional keyword. E.g. try_trampoline=True. Our take_damage() method would then look like this.

Syntax: Select all

def take_damage(
self, damage, damage_type=DamageTypes.GENERIC, attacker_index=None,
weapon_index=None, hitgroup=HitGroup.GENERIC, try_trampoline=True,
**kwargs):
# Code...
if try_trampoline:
try:
# Try calling the trampoline
self.on_take_damage.call_trampoline(take_damage_info)
except ValueError:
# If it failed, the function probably wasn't hooked
self.on_take_damage(take_damage_info)
else:
self.on_take_damage(take_damage_info)
If we use this implementation, we can always use take_damage within a hook and if you would like to "enable" the recursion you can simply set try_trampoline to False.

Edit: After thinking about it again, we should set the default value to False, because other scripts that have a hook on this function will never get notified of the damage done. try_trampoline should only be set to True within a hook.
arawra
Senior Member
Posts: 190
Joined: Fri Jun 21, 2013 6:51 am

Postby arawra » Thu Jul 09, 2015 2:34 am

Why am I not able to get a userid from the given index?

Syntax: Select all

@PreHook(on_take_damage)
def pre_on_take_damage(args):
#ammo attacker base_damage bullet damage damaged_other_players force inflictor penetrated position radius recoil reported_position stats type weapon
info = make_object(TakeDamageInfo, args[1])

# Is this world damage?
print(info.attacker)
if info.attacker == 0:
return

victim = dnd.dndPlayerDictionary[userid_from_pointer(args[0])]

# ValueError: Unable to get a UserID from the given index (xxx).
attacker = dnd.dndPlayerDictionary[userid_from_index(info.attacker)]
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Thu Jul 09, 2015 2:58 am

Syntax: Select all

from entities.constants import WORLD_ENTITY_INDEX

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 46 guests