diff --git a/addons/source-python/packages/source-python/entities/_base.py b/addons/source-python/packages/source-python/entities/_base.py index 1495b2f7f..47528eead 100644 --- a/addons/source-python/packages/source-python/entities/_base.py +++ b/addons/source-python/packages/source-python/entities/_base.py @@ -94,11 +94,13 @@ def __init__(cls, classname, bases, attributes): # Set whether or not this class is caching its instances by default try: - cls._caching = signature( - cls.__init__ - ).parameters['caching'].default + cls._caching = bool( + signature( + vars(cls)['__init__'] + ).parameters['caching'].default + ) except KeyError: - cls._caching = True + cls._caching = bool(vars(cls).get('caching', False)) # Add the class to the registered classes _entity_classes.add(cls) @@ -305,14 +307,16 @@ def find_or_create(cls, classname): return entity @classmethod - def from_inthandle(cls, inthandle): + def from_inthandle(cls, inthandle, caching=None): """Create an entity instance from an inthandle. :param int inthandle: The inthandle. + :param bool caching: + Whether to lookup the cache for an existing instance or not. :rtype: Entity """ - return cls(index_from_inthandle(inthandle)) + return cls(index_from_inthandle(inthandle), caching=caching) @classmethod def _obj(cls, ptr): diff --git a/addons/source-python/packages/source-python/players/_base.py b/addons/source-python/packages/source-python/players/_base.py index cf3b5b57c..eda5700e2 100644 --- a/addons/source-python/packages/source-python/players/_base.py +++ b/addons/source-python/packages/source-python/players/_base.py @@ -92,14 +92,16 @@ def __init__(self, index, caching=True): object.__setattr__(self, '_playerinfo', None) @classmethod - def from_userid(cls, userid): + def from_userid(cls, userid, caching=None): """Create an instance from a userid. :param int userid: The userid. + :param bool caching: + Whether to lookup the cache for an existing instance or not. :rtype: Player """ - return cls(index_from_userid(userid)) + return cls(index_from_userid(userid), caching=caching) @property def net_info(self):