diff --git a/addons/source-python/packages/source-python/entities/_base.py b/addons/source-python/packages/source-python/entities/_base.py index 910ace954..27fdca05c 100644 --- a/addons/source-python/packages/source-python/entities/_base.py +++ b/addons/source-python/packages/source-python/entities/_base.py @@ -212,6 +212,15 @@ def find_or_create(cls, classname): return entity + @classmethod + def from_inthandle(cls, inthandle): + """Create an entity instance from an inthandle. + :param int inthandle: + The inthandle. + :rtype: Entity + """ + return cls(index_from_inthandle(inthandle)) + @classmethod def _obj(cls, ptr): """Return an entity instance of the given pointer.""" diff --git a/addons/source-python/packages/source-python/entities/dictionary.py b/addons/source-python/packages/source-python/entities/dictionary.py index 8f1241ec6..864b45825 100644 --- a/addons/source-python/packages/source-python/entities/dictionary.py +++ b/addons/source-python/packages/source-python/entities/dictionary.py @@ -10,6 +10,7 @@ from core import AutoUnload # Entities from entities.entity import Entity +from entities.helpers import index_from_inthandle # Listeners from listeners import on_entity_deleted_listener_manager @@ -60,6 +61,14 @@ def __delitem__(self, index): # Remove the given index from the dictionary... super().__delitem__(index) + def from_inthandle(self, inthandle): + """Get an entity instance from an inthandle. + + :param int inthandle: The inthandle. + :rtype: Entity + """ + return self[index_from_inthandle(inthandle)] + def on_automatically_removed(self, index): """Called when an index is automatically removed."""