Skip to content

Commit 18bf7a4

Browse files
committed
Fixed issue #86
1 parent 2bae353 commit 18bf7a4

1 file changed

Lines changed: 6 additions & 22 deletions

File tree

  • addons/source-python/packages/source-python/players/weapons

addons/source-python/packages/source-python/players/weapons/__init__.py

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -362,38 +362,22 @@ def weapon_indexes(
362362
# =========================================================================
363363
def get_weapon_color(self):
364364
"""Return a tuple value for the player's active weapon's color."""
365-
# Get the handle of the player's active weapon
366-
handle = self.active_weapon
367-
368-
# Get the weapon's BaseHandle instance
369-
index = index_from_inthandle(handle)
370-
371-
# Was no index found?
372-
if index is None:
373-
374-
# Raise an error
365+
try:
366+
index = index_from_inthandle(self.active_weapon)
367+
except (ValueError, OverflowError):
375368
raise ValueError(
376369
'No active weapon found for player "{0}"'.format(self.userid))
377370

378-
# Return the entity's color
379371
return Entity(index).color
380372

381373
def set_weapon_color(self, color):
382374
"""Set the player's active weapon's color."""
383-
# Get the handle of the player's active weapon
384-
handle = self.active_weapon
385-
386-
# Get the weapon's BaseHandle instance
387-
index = index_from_inthandle(handle)
388-
389-
# Was no index found?
390-
if index is None:
391-
392-
# Raise an error
375+
try:
376+
index = index_from_inthandle(self.active_weapon)
377+
except (ValueError, OverflowError):
393378
raise ValueError(
394379
'No active weapon found for player "{0}"'.format(self.userid))
395380

396-
# Set the entity's color
397381
Entity(index).color = color
398382

399383

0 commit comments

Comments
 (0)