Skip to content

Commit d55b1e0

Browse files
committed
Fixed some issues with SendProp changes in players.weapons. Made projectiles methods more dynamic.
1 parent b560c82 commit d55b1e0

File tree

1 file changed

+37
-17
lines changed
  • addons/source-python/packages/source-python/players/weapons

1 file changed

+37
-17
lines changed

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

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,27 @@ class _ProjectileMeta(type):
1010
def __new__(mcl, name, bases, odict):
1111
'''Create the class and create its methods dynamically'''
1212

13+
# Store values to use later
14+
temp = {'_classname': None, '_is_filters': None, '_not_filters': None}
15+
16+
# Loop through the base class attributes
17+
for attribute in ('_classname', '_is_filters', '_not_filters'):
18+
19+
# Try to store the odict's value of
20+
# the attribute and delete it from odict
21+
try:
22+
temp[attribute] = odict[attribute]
23+
del odict[attribute]
24+
25+
# If the attribute is not found in odict, just leave it as None
26+
except KeyError:
27+
continue
28+
1329
# Create the object
1430
cls = super().__new__(mcl, name, bases, odict)
1531

1632
# Is the the baseclass that uses the metaclass?
17-
if not bases:
33+
if len(bases) != 1 or bases[0].__name__ != '_ProjectileBase':
1834

1935
# Do not add any methods
2036
return cls
@@ -25,22 +41,30 @@ def __new__(mcl, name, bases, odict):
2541
# Create the iterator <weapon>_indexes method
2642
setattr(
2743
cls, '{0}_indexes'.format(method_name),
28-
lambda self: self._projectile_indexes)
44+
property(lambda self: cls._projectile_indexes(
45+
self, temp['_classname'],
46+
temp['_is_filters'], temp['_not_filters'])))
2947

3048
# Create the get_<weapon>_indexes method
3149
setattr(
3250
cls, 'get_{0}_indexes'.format(method_name),
33-
lambda self: self._get_projectile_index_list())
51+
lambda self: cls._get_projectile_index_list(
52+
self, temp['_classname'],
53+
temp['_is_filters'], temp['_not_filters']))
3454

3555
# Create the get_<weapon>_count method
3656
setattr(
3757
cls, 'get_{0}_count'.format(method_name),
38-
lambda self: self._get_projectile_ammo())
58+
lambda self: cls._get_projectile_ammo(
59+
self, temp['_classname'],
60+
temp['_is_filters'], temp['_not_filters']))
3961

4062
# Create the set_<weapon>_count method
4163
setattr(
4264
cls, 'set_{0}_count'.format(method_name),
43-
lambda self, value: self._set_projectile_ammo(value))
65+
lambda self, value: cls._set_projectile_ammo(
66+
self, value, temp['_classname'],
67+
temp['_is_filters'], temp['_not_filters']))
4468

4569
# Return the new class
4670
return cls
@@ -54,25 +78,21 @@ class _ProjectileBase(metaclass=_ProjectileMeta):
5478
_is_filters = None
5579
_not_filters = None
5680

57-
def _projectile_indexes(self):
81+
def _projectile_indexes(self, classname, is_filters, not_filters):
5882
'''Iterates over all indexes the player owns for the projectile type'''
59-
return self.weapon_indexes(
60-
self._classname, self._is_filters, self._not_filters)
83+
return self.weapon_indexes(classname, is_filters, not_filters)
6184

62-
def _get_projectile_index_list(self):
85+
def _get_projectile_index_list(self, classname, is_filters, not_filters):
6386
'''Returns a list of indexes the player owns for the projectile type'''
64-
return self.get_weapon_index_list(
65-
self._classname, self._is_filters, self._not_filters)
87+
return self.get_weapon_index_list(classname, is_filters, not_filters)
6688

67-
def _get_projectile_ammo(self):
89+
def _get_projectile_ammo(self, classname, is_filters, not_filters):
6890
'''Returns the ammo amount the player has for the projectile type'''
69-
return self._get_weapon_ammo(
70-
self._classname, self._is_filters, self._not_filters)
91+
return self._get_weapon_ammo(classname, is_filters, not_filters)
7192

72-
def _set_projectile_ammo(self, value):
93+
def _set_projectile_ammo(self, value, classname, is_filters, not_filters):
7394
'''Sets the ammo amount of the player for the projectile type'''
74-
self._set_weapon_ammo(
75-
value, self._classname, self._is_filters, self._not_filters)
95+
self._set_weapon_ammo(value, classname, is_filters, not_filters)
7696

7797

7898
class _HEGrenade(_ProjectileBase):

0 commit comments

Comments
 (0)