Skip to content

Conversation

@vinci6k
Copy link
Contributor

@vinci6k vinci6k commented Feb 8, 2019

Similarly to from_userid() that the Player and PlayerDictionary have, I think this can be very useful for plugins that work with active weapons a lot.

from events import Event
from players.dictionary import PlayerDictionary
from weapons.dictionary import WeaponDictionary


player_instances = PlayerDictionary()
weapon_instances = WeaponDictionary()


@Event('weapon_fire')
def weapon_fire(event):
    player = player_instances.from_userid(event['userid'])
    weapon = weapon_instances.from_inthandle(player.active_weapon_handle)

:rtype: Weapon
"""
return cls(index_from_inthandle(inthandle))

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would make more sense if that would be added to the Entity class.

:param int inthandle: The inthandle.
:rtype: Weapon
"""
return self[index_from_inthandle(inthandle)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for this one. It should be added to EntityDictionary.

@vinci6k
Copy link
Contributor Author

vinci6k commented Feb 9, 2019

Oh, right! I completely forgot about the other inthandles (m_hGroundEntity, m_hOwnerEntity, m_hOwner).
I've moved them to the Entity and EntityDictionary classes.

@vinci6k vinci6k changed the title Added from_inthandle() to the Weapon and WeaponDictionary classes. Added from_inthandle() to the Entity and EntityDictionary classes. Feb 9, 2019
@Ayuto
Copy link
Member

Ayuto commented Feb 10, 2019

Thanks!

It's not because of these three attributes. Even if I couldn't provide a single scenario I would add it to those two base classes. Simply because of the possible existance of such scenarios.

@Ayuto Ayuto merged commit 6bf64cc into Source-Python-Dev-Team:master Feb 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants