Page 1 of 1

BaseHandle to Index conversion failure

Posted: Thu Sep 17, 2020 5:26 am
by arawra
CSGO on Win10x64

Using August 16th release

Code: Select all

[SP] Caught an Exception:
Traceback (most recent call last):
    File "..\addons\source-python\plugins\dnd5e\dnd5e.py", line 751, in preDamagePlayer
        info.attacker

ValueError: Conversion from "BaseHandle" (<_entities.BaseEntityHandle object at 0x016A1020>) to "Index" failed.


Syntax: Select all

@EntityPreHook(EntityCondition.is_player, 'on_take_damage')
def preDamagePlayer(stack_data):
# if 'riot' in victim.get_model().path
victim = make_object(Entity, stack_data[0])
if not victim.is_player:
return
info = make_object(TakeDamageInfo, stack_data[1])
info.attacker
attacker = Entity(info.attacker)

Re: BaseHandle to Index conversion failure

Posted: Thu Sep 17, 2020 7:05 pm
by arawra
It appears the index for the attacking player can be determined from info.inflictor.

Syntax: Select all

@EntityPreHook(EntityCondition.is_player, 'on_take_damage')
def preDamagePlayer(stack_data):
# if 'riot' in victim.get_model().path
victim = make_object(Entity, stack_data[0])
if not victim.is_player:
return
info = make_object(TakeDamageInfo, stack_data[1])
attacker = players.from_userid(Player(info.inflictor).userid)
messageServer(attacker.name)

Re: BaseHandle to Index conversion failure

Posted: Sun Sep 20, 2020 6:03 am
by VinciT
I've been having the same problem with TakeDamageInfo.attacker as of late. I'm not sure what's causing it.
Do keep in mind that you might get a non-Player index when accessing TakeDamageInfo.inflictor if the damage was done by a grenade/projectile.

Syntax: Select all

try:
# Try to get a Player instance.
player = Player(info.inflictor)
except ValueError:
# Damage wasn't done directly, try with an inthandle instead.
player = Player.from_inthandle(Entity(info.inflictor).owner_handle)
This snippet can still fail if the damage was caused by the world, or an entity without an owner. So you'd have to add in a couple more checks before attempting to get the Player instance.

Re: BaseHandle to Index conversion failure

Posted: Sun Sep 20, 2020 3:29 pm
by Ayuto
There were changes to the CTakeDamageInfo class which we haven't taken into account yet. This was a CSGO specific change.