Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
ammoprop = LocalWeaponData.m_iPrimaryAmmoType
secondary_fire_ammoprop = LocalWeaponData.m_iSecondaryAmmoType
owner_handle = m_hOwner
clip = m_iClip1
secondary_fire_clip = m_iClip2
_clip = m_iClip1
_secondary_fire_clip = m_iClip2
flip_view_model = LocalWeaponData.m_bFlipViewModel
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ a list of points you should always try to provide:

1. A precise description of the problem.
2. A tested code snipped to reproduce the issue.
3. The full traceback of the exception (if an exception was raised).

Thank you!
Original file line number Diff line number Diff line change
Expand Up @@ -567,8 +567,8 @@ def take_damage(
if attacker is not None and weapon is None:

# Try to use the attacker's active weapon
with suppress(AttributeError, ValueError, OverflowError):
weapon = Weapon(index_from_inthandle(attacker.active_weapon))
with suppress(AttributeError):
weapon = attacker.active_weapon

# Try to set the hitgroup
with suppress(AttributeError):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,20 @@ class Weapon(Entity):

def get_clip(self):
"""Return the amount of ammo in the weapon's clip."""
return self.clip if self.clip != -1 else 0
return self._clip if self._clip != -1 else 0

def set_clip(self, value):
"""Set the amount of ammo in the weapon's clip."""
# Does the weapon have ammo?
if self.clip != -1:
if self._clip != -1:

# Set the clip amount
self.clip = value
self._clip = value

# Set the "clip" property methods
clip = property(
get_clip, set_clip,
doc="""Property to get/set the weapon's clip.""")

def get_ammo(self):
"""Return the amount of ammo the player has for the weapon."""
Expand Down Expand Up @@ -81,16 +86,27 @@ def set_ammo(self, value):

def get_secondary_fire_clip(self):
"""Return the amount of ammo in the weapon's secondary fire clip."""
return (
self.secondary_fire_clip if self.secondary_fire_clip != -1 else 0)
# Does the weapon have secondary fire ammo?
if self._secondary_fire_clip != -1:

# Return the secondary fire clip amount
return self._secondary_fire_clip

# If it doesn't, return zero
return 0

def set_secondary_fire_clip(self, value):
"""Set the amount of ammo in the weapon's secondary fire clip."""
# Does the weapon have secondary fire ammo?
if self.secondary_fire_clip != -1:
if self._secondary_fire_clip != -1:

# Set the secondary fire clip amount
self.secondary_fire_clip = value
self._secondary_fire_clip = value

# Set the "secondary_fire_clip" property methods
secondary_fire_clip = property(
get_secondary_fire_clip, set_secondary_fire_clip,
doc="""Property to get/set the weapon's secondary fire clip.""")

def get_secondary_fire_ammo(self):
"""Return the secondary fire ammo the player has for the weapon."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,46 @@ def get_ammo(self):
"""Return the amount of ammo the player has for the weapon."""
# Is the weapon a projectile?
if 'grenade' in weapon_manager[self.classname].tags:
return super(Weapon, self).get_ammo()

# Do we have a valid ammoprop?
if self.ammoprop == -1:
raise ValueError(
'Unable to get ammoprop for {0}'.format(self.classname))

# Get the owner of the weapon
player = self.owner

# Does no one currently own the weapon?
if player is None:
return

# Return the ammo
return player.get_property_ushort(
weapon_manager.ammoprop + '%03d' % self.ammoprop)

return self.primary_ammo_count

def set_ammo(self, value):
"""Set the player's ammo property for the weapon."""
# Is the weapon a projectile?
if 'grenade' in weapon_manager[self.classname].tags:
super(Weapon, self).set_ammo(value)

# Do we have a valid ammoprop?
if self.ammoprop == -1:
raise ValueError(
'Unable to set ammoprop for {0}'.format(self.classname))

# Get the owner of the weapon
player = self.owner

# Does no one currently own the weapon?
if player is None:
return

# Set the ammo
player.set_property_ushort(
weapon_manager.ammoprop + '%03d' % self.ammoprop, value)

return

self.primary_ammo_count = value
Expand Down