-
Notifications
You must be signed in to change notification settings - Fork 36
Closed
Labels
Description
Issue
Weapon.find simply returns instances of entities.entity.Entity class.
Weapon.find_or_create returns instance of the Weapon class if the weapon was created, and instance of the Entity class if it existed.
Code to reproduce
from events import Event
from weapons.entity import Weapon
@Event('player_jump')
def on_player_jump(game_event):
weapon = Weapon.find_or_create("weapon_deagle")
print("type(weapon): {}, index: {}".format(type(weapon), weapon.index))Jump twice. Output:
type(weapon): <class 'weapons._entity.csgo.Weapon'>, index: 229
type(weapon): <class 'entities.entity.Entity'>, index: 229
Source of the problem
entity.py, line 159
@staticmethod
def find(classname):
"""Try to find an entity with the given classname.
If not entity has been found, None will be returned.
:param str classname: The classname of the entity.
:return: Return the found entity.
:rtype: Entity
"""
entity = BaseEntity.find(classname)
if entity is not None and entity.is_networked():
return Entity(entity.index)
return NoneAs you can see, this method, unlike .create method, always returns instances of the Entity class.
Possible solution
Make this method classmethod instead of staticmethod and replace line 171 with
return cls(entity.index)