Information for hooks

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

Information for hooks

Postby arawra » Sat Sep 05, 2020 3:17 pm

In l4d2 I am trying to hook damage dealt to the 'infected' enemies.

Syntax: Select all

@EntityPreHook(EntityCondition.is_not_player, 'on_take_damage')
def infected_pre_take_damage(stack_data):
print("Non-player took damage")
victim = make_object(Entity, stack_data[0])
info = make_object(TakeDamageInfo, stack_data[1])
attacker = Entity(info.attacker)
pprint(dir(victim))
if attacker.is_player():
pprint(victim)
'''
weapon = Entity(info.attacker)
owner = Player(index_from_inthandle(weapon.owner_handle))
info.attacker = owner.index
info.inflictor = owner.index
'''
print(victim.classname)
#if victim.classname in ('infected', 'witch', 'player'):
print("%s %s was attacked"%(victim.index, victim.classname,))
print("done")



This works just fine for physics or player entities (when modified) but for whatever reason, infected don't appear to be entities? What baffles me even more is that in 'infected_hurt', I am able to created an entity from the userid -> index and it will return a classname. What would I need to do to hook damage to them?

I think I need to find the appropriate function to hook for when they take damage. However I am not sure where to find a list of appropriate functions. I've been perusing https://developer.valvesoftware.com/ for any information I can obtain but I haven't found much luck. There's gotta be a better way than reverse engineering via disassemblers/memory editing etc...?
User avatar
VinciT
Senior Member
Posts: 331
Joined: Thu Dec 18, 2014 2:41 am

Re: Information for hooks

Postby VinciT » Sat Sep 05, 2020 5:19 pm

I mostly work with HL2DM, CSS, and CSGO - so my go to when it comes to looking into how things work are the HL2SDK and the CSS Community Edition repos. From those two I can usually get enough information to get things working. If I get stuck - I search around on the SM and SP forums. If I'm still stuck after all that.. then I make a post asking for help. :tongue:

Now onto your problem. There are usually 3 functions you can hook for damage. OnTakeDamage, OnTakeDamage_Alive, and TraceAttack. The first two we have access to, and if you'd like to hook TraceAttack you'll have to get the offset and add it to your data. Do keep in mind that TraceAttack is only used for hitscan weapons.

I've never made plugins for L4D2 so I'm not sure if these other functions will work. In case they don't, you could take a peek at the Alien Swarm SDK or the recently leaked CSGO source code. Those engine branches were made after L4D2 and as such there might be some remnants of L4D2 related code in there.

Edit: Forgot to mention that hurt/damage events usually get created in the OnTakeDamage_Alive function.
ImageImageImageImageImage
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: Information for hooks

Postby satoon101 » Sat Sep 05, 2020 5:36 pm

Here is a list of all events for L4D2:
http://wiki.sourcepython.com/developing ... /l4d2.html

The infected_death might work better in this instance:
http://wiki.sourcepython.com/developing ... cted-death

Also, you might try to find what entity type infected are by using the dumpentityfactories command.
Image
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: Information for hooks

Postby satoon101 » Sat Sep 05, 2020 5:53 pm

I just reread your original post, and I noticed you said you can get an Entity instance using infected_hurt. If you print out the classname of that entity, you can then use that classname in your EntityPreHook.

Syntax: Select all

@EntityPreHook(EntityCondition.equals_entity_classname('<classname>'), 'on_take_damage')

The reason your is_not_player condition didn't work is because the very first time any non-player entity is damaged, that specific OnTakeDamage function is hooked, which might not be the same exact function that works for the entity you want it to hook.
Image
arawra
Senior Member
Posts: 190
Joined: Fri Jun 21, 2013 6:51 am

Re: Information for hooks

Postby arawra » Sat Sep 05, 2020 6:00 pm

Nah, still nothing.

Syntax: Select all

infected = EntityCondition.equals_datamap_classname('infected')
@EntityPreHook(infected, 'on_take_damage')
def infected_pre_take_damage(stack_data):
print("Non-player took damage")
victim = make_object(Entity, stack_data[0])

info = make_object(TakeDamageInfo, stack_data[1])
attacker = Entity(info.attacker)

if attacker.is_player():

Player(attacker.index).health += 5


#if victim.classname in ('infected', 'witch', 'player'):
print("%s %s was attacked"%(victim.index, victim.classname,))
print("done")


I double-checked in infected_hurt to make sure that the specific entity for infected had the 'on_take_damage' function and it was there.
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: Information for hooks

Postby satoon101 » Sat Sep 05, 2020 6:12 pm

Ok. If I have time tonight, I will run some tests to figure out what you want to use.
Image
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: Information for hooks

Postby L'In20Cible » Sat Sep 05, 2020 10:14 pm

arawra wrote:

Syntax: Select all

infected = EntityCondition.equals_datamap_classname('infected')


Should be:

Syntax: Select all

infected = EntityCondition.equals_entity_classname('infected')

The datamap classname would be the value of Entity.datamap.class_name which would be something like CInfected.

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 25 guests