Skip to content

Commit 75c5c2d

Browse files
committed
Improved performance of Entity.find for CS:GO.
1 parent 7045425 commit 75c5c2d

File tree

1 file changed

+9
-4
lines changed
  • addons/source-python/packages/source-python/entities/engines/csgo

1 file changed

+9
-4
lines changed

addons/source-python/packages/source-python/entities/engines/csgo/__init__.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
# =============================================================================
66
# >> IMPORTS
77
# =============================================================================
8-
# Source.Python Imports
8+
# Source.Python
9+
from entities import BaseEntityGenerator
910
from entities._base import Entity as _Entity
1011
from weapons.manager import weapon_manager
1112

@@ -44,18 +45,22 @@ def create(cls, classname):
4445

4546
@classmethod
4647
def find(cls, classname):
47-
from filters.entities import BaseEntityIter
4848
index = _weapon_names_for_definition.get(classname)
4949
if classname in _weapon_parents and index is not None:
50-
for entity in BaseEntityIter(_weapon_parents[classname]):
50+
parent_classname = _weapon_parents[classname]
51+
for entity in BaseEntityGenerator():
52+
if entity.classname != parent_classname:
53+
continue
5154
if not entity.is_networked():
5255
continue
5356
if entity.get_network_property_int(
5457
'm_AttributeManager.m_Item.m_iItemDefinitionIndex'
5558
) == index:
5659
return cls(entity.index)
5760
elif classname in _parent_weapons:
58-
for entity in BaseEntityIter(classname):
61+
for entity in BaseEntityGenerator():
62+
if entity.classname != classname:
63+
continue
5964
if not entity.is_networked():
6065
continue
6166
if entity.get_network_property_int(

0 commit comments

Comments
 (0)