[CS:GO] Get inflictor entity in TakeDamageInfo

Please post any questions about developing your plugin here. Please use the search function before posting!
rovizon
Junior Member
Posts: 22
Joined: Mon May 31, 2021 3:01 pm
Location: Donbass

[CS:GO] Get inflictor entity in TakeDamageInfo

Postby rovizon » Wed Jul 14, 2021 3:53 pm

How to get / pass the inflictor entity (not attacker and not attacker weapon) which gave damage to player?

Entity give damage to enemy player.

Syntax: Select all

target_player.take_damage(20, DamageTypes.BULLET, owner.index, entity.index)



Syntax: Select all

@EntityPreHook(EntityCondition.is_player, 'on_take_damage')
def pre_take_damage(args):
player = Entity(index_from_pointer(args[0]))
info = make_object(TakeDamageInfo, args[1])

print('Attacker ' + str(info.attacker))
print('Inflictor ' + str(info.inflictor)) # always 0
print('Weapon ' + str(info.weapon)) # always 0
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: [CS:GO] Get inflictor entity in TakeDamageInfo

Postby satoon101 » Wed Jul 14, 2021 9:39 pm

Something must have changed in CS:GO if that is true.

The inflictor is typically never what you want to get in that instance. If the attacker and inflictor are the same, weapon is set to the attacker's active weapon. If the attacker and inflictor are different, the weapon is set to the inflictor. This occurs when a player is hit by a projectile weapon (ie hegrenade).

But, again, if you are seeing 0 for weapon/inflictor in all instances, something got changed inside CS:GO that we need to now take into account.
Image
rovizon
Junior Member
Posts: 22
Joined: Mon May 31, 2021 3:01 pm
Location: Donbass

Re: [CS:GO] Get inflictor entity in TakeDamageInfo

Postby rovizon » Thu Jul 15, 2021 8:12 am

Thank you for reply. I think there is something wrong on my side. I want to get the entity index (like independent sentry gun which has owner player which will be the attacker in TakeDamageInfo) and intercept the damage it does to count the number of kills this entity done.

I tried to pass entity index as weapon_index parameter but it returns 0 in TakeDamageInfo.

Syntax: Select all

target_player.take_damage(20, DamageTypes.BULLET, owner.index, entity.index)


How else can I achieve this?
rovizon
Junior Member
Posts: 22
Joined: Mon May 31, 2021 3:01 pm
Location: Donbass

Re: [CS:GO] Get inflictor entity in TakeDamageInfo

Postby rovizon » Thu Jul 15, 2021 1:07 pm

SOLVED like this, but I am not sure if this is a proper solution:

Syntax: Select all

target_player.take_damage(20, DamageTypes.BULLET, owner.index, weapon=entity.index)
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: [CS:GO] Get inflictor entity in TakeDamageInfo

Postby L'In20Cible » Fri Jul 16, 2021 12:42 am

rovizon wrote:I want to get the entity index (like independent sentry gun which has owner player which will be the attacker in TakeDamageInfo)

My first guess would be that the entity you are passing as weapon index isn't recognized as a known weapon causing this instantiation to fail resulting into no weapon being assigned. Replacing Weapon to Entity could probably work as I don't see anything specific to weapon being used on the object. I can't test, as I don't have an up-to-date server for that game nor that game installed on my machine anymore but, if that works for you feel free to make a PR.

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 33 guests