Page 1 of 1

Weapon constants

Posted: Mon Aug 15, 2016 8:29 pm
by arawra
How do I use them in conjunction with weapon restrictions?

Syntax: Select all

from events import Event

from players.entity import Player

from weapons.constants import WeaponType

@Event('player_spawn')
def player_spawn(ev):
player = Player(ev['index'])
player.unrestrict_weapon(WeaponType.EXPLOSIVE.....


WeaponType.EXPLOSIVE is undefined

Re: Weapon constants

Posted: Mon Aug 15, 2016 9:27 pm
by satoon101
You wouldn't do it that way.

Untested, but the gist of how it should be done:

Syntax: Select all

from filters.weapons import WeaponClassIter

_explosives = [weapon.name for weapon in WeaponClassIter('explosive')]

player.restrict_weapons(*_explosives)


Note that the tags used in WeaponClassIter come from the data files:
https://github.com/Source-Python-Dev-Te ... on/weapons

So, for instance, in cstrike.ini (the CS:S specific file), only hegrenade has the 'explosive' tag. If you want all grenades in there, you could use 'grenade' instead.

Re: Weapon constants

Posted: Tue Aug 16, 2016 5:28 pm
by arawra

Code: Select all

[SP] Caught an Exception:
Traceback (most recent call last):
  File '..\addons\source-python\packages\source-python\events\listener.py', line 92, in fire_game_event
    callback(game_event)
  File '..\addons\source-python\plugins\dnd\dnd.py', line 341, in player_spawn
    player.unrestrict_weapons(*_all)
  File '..\addons\source-python\packages\source-python\players\entity.py', line 620, in unrestrict_weapons
    from weapons.restrictions import weapon_restriction_handler
  File '..\addons\source-python\packages\source-python\weapons\restrictions.py', line 387, in <module>
    @EntityPreHook(EntityCondition.is_player, 'buy_internal')
  File '..\addons\source-python\packages\source-python\entities\hooks.py', line 103, in __call__
    if self.initialize(entity):
  File '..\addons\source-python\packages\source-python\entities\hooks.py', line 131, in initialize
    self.hooked_function = getattr(entity, self.function)
  File '..\addons\source-python\packages\source-python\entities\entity.py', line 96, in __getattr__
    if hasattr(server_class, attr):
  File '..\addons\source-python\packages\source-python\memory\manager.py', line 614, in __get__
    func = binary[identifier].make_function(convention, args, return_type)

ValueError: Could not find signature.

Re: Weapon constants

Posted: Tue Aug 16, 2016 5:53 pm
by L'In20Cible
Seems like the signature for "buy_internal" is outdated. What game is this for?

Re: Weapon constants

Posted: Tue Aug 16, 2016 6:12 pm
by arawra
CS:GO

Re: Weapon constants

Posted: Tue Aug 16, 2016 10:07 pm
by satoon101
It seems that Ayuto has fixed the signature, so you will just have to wait until build 416 is available. Unfortunately, it seems like our buildbot has been having issues lately, so we'll have to get those sorted out so it can build version 416.

Re: Weapon constants

Posted: Tue Aug 16, 2016 10:27 pm
by arawra
I was able to come up with a different solution. Keep up the good work.

Re: Weapon constants

Posted: Wed Aug 17, 2016 4:56 am
by Ayuto
Yes, the connection to GitHub seems to timeout sometimes. I will trigger the build again now.