BaseHandle to Index conversion failure

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

BaseHandle to Index conversion failure

Postby arawra » Thu Sep 17, 2020 5:26 am

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)
arawra
Senior Member
Posts: 168
Joined: Fri Jun 21, 2013 6:51 am

Re: BaseHandle to Index conversion failure

Postby arawra » Thu Sep 17, 2020 7:05 pm

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)
User avatar
VinciT
Senior Member
Posts: 213
Joined: Thu Dec 18, 2014 2:41 am

Re: BaseHandle to Index conversion failure

Postby VinciT » Sun Sep 20, 2020 6:03 am

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.
ImageImageImageImageImage
User avatar
Ayuto
Project Leader
Posts: 2098
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: BaseHandle to Index conversion failure

Postby Ayuto » Sun Sep 20, 2020 3:29 pm

There were changes to the CTakeDamageInfo class which we haven't taken into account yet. This was a CSGO specific change.

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 12 guests