From 140bb42a75e6b39b39a5c7dbaed56aa30a11af0a Mon Sep 17 00:00:00 2001 From: KirillMysnik Date: Tue, 5 Jan 2016 01:18:55 +0300 Subject: [PATCH 1/2] Updated entities.specials to support conversion functions w/o 'raise_exception' kwarg. --- .../packages/source-python/entities/specials.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/addons/source-python/packages/source-python/entities/specials.py b/addons/source-python/packages/source-python/entities/specials.py index 8e8ce6cc7..25a968412 100644 --- a/addons/source-python/packages/source-python/entities/specials.py +++ b/addons/source-python/packages/source-python/entities/specials.py @@ -75,21 +75,20 @@ def take_damage( # Try to get the attacker based off of the weapon's owner with suppress(ValueError): attacker_index = index_from_inthandle(weapon.current_owner) - if attacker_index is not None: - attacker = Entity(attacker_index) + attacker = Entity(attacker_index) # Is there an attacker but no weapon? if attacker is not None and weapon is None: # Does the attacker have a weapon attribute? if hasattr(attacker, 'active_weapon'): + with suppress(ValueError): - # Get the attacker's current weapon index - weapon_index = index_from_inthandle( - attacker.active_weapon, False) + # Get the attacker's current weapon index + weapon_index = index_from_inthandle( + attacker.active_weapon) - # Get the weapon's Weapon instance if it is valid - if weapon_index is not None: + # Get the weapon's Weapon instance weapon = Weapon(weapon_index) # Is hitgroup a valid attribute? From a786d3f9ae8b9d49d4e79490378e15e551978a34 Mon Sep 17 00:00:00 2001 From: KirillMysnik Date: Tue, 5 Jan 2016 03:01:25 +0300 Subject: [PATCH 2/2] Added OverflowError because index_from_inthandle only accepts unsigned ints and weapon.current_owner/attacker.active_weapon can equal to -1. --- .../source-python/packages/source-python/entities/specials.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/source-python/packages/source-python/entities/specials.py b/addons/source-python/packages/source-python/entities/specials.py index 25a968412..9a597c255 100644 --- a/addons/source-python/packages/source-python/entities/specials.py +++ b/addons/source-python/packages/source-python/entities/specials.py @@ -73,7 +73,7 @@ def take_damage( if attacker is None and weapon is not None: # Try to get the attacker based off of the weapon's owner - with suppress(ValueError): + with suppress(ValueError, OverflowError): attacker_index = index_from_inthandle(weapon.current_owner) attacker = Entity(attacker_index) @@ -82,7 +82,7 @@ def take_damage( # Does the attacker have a weapon attribute? if hasattr(attacker, 'active_weapon'): - with suppress(ValueError): + with suppress(ValueError, OverflowError): # Get the attacker's current weapon index weapon_index = index_from_inthandle(