Skip to content

Commit 586738c

Browse files
committed
Fixed slowness in Entity.find for CS:GO.
1 parent 397a65d commit 586738c

File tree

1 file changed

+15
-7
lines changed
  • addons/source-python/packages/source-python/entities/engines/csgo

1 file changed

+15
-7
lines changed

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

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,22 @@ def create(cls, classname):
4444

4545
@classmethod
4646
def find(cls, classname):
47-
from filters.entities import EntityIter
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 EntityIter(_weapon_parents[classname]):
51-
if entity.item_definition_index == index:
52-
return entity
50+
for entity in BaseEntityIter(_weapon_parents[classname]):
51+
if not entity.is_networked():
52+
continue
53+
if entity.get_network_property_int(
54+
'm_AttributeManager.m_Item.m_iItemDefinitionIndex'
55+
) == index:
56+
return cls(entity.index)
5357
elif classname in _parent_weapons:
54-
for entity in EntityIter(classname):
55-
if entity.item_definition_index in (index, 0):
56-
return entity
58+
for entity in BaseEntityIter(classname):
59+
if not entity.is_networked():
60+
continue
61+
if entity.get_network_property_int(
62+
'm_AttributeManager.m_Item.m_iItemDefinitionIndex'
63+
) in (index, 0):
64+
return cls(entity.index)
5765
return super().find(classname)

0 commit comments

Comments
 (0)