Page 1 of 1

[CS:GO] Get inflictor entity in TakeDamageInfo

Posted: Wed Jul 14, 2021 3:53 pm
by rovizon
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

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

Posted: Wed Jul 14, 2021 9:39 pm
by satoon101
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.

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

Posted: Thu Jul 15, 2021 8:12 am
by rovizon
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?

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

Posted: Thu Jul 15, 2021 1:07 pm
by rovizon
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)

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

Posted: Fri Jul 16, 2021 12:42 am
by L'In20Cible
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.