Weapon constants

Please post any questions about developing your plugin here. Please use the search function before posting!
arawra
Senior Member
Posts: 190
Joined: Fri Jun 21, 2013 6:51 am

Weapon constants

Postby arawra » Mon Aug 15, 2016 8:29 pm

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
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: Weapon constants

Postby satoon101 » Mon Aug 15, 2016 9:27 pm

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.
Image
arawra
Senior Member
Posts: 190
Joined: Fri Jun 21, 2013 6:51 am

Re: Weapon constants

Postby arawra » Tue Aug 16, 2016 5:28 pm

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.
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: Weapon constants

Postby L'In20Cible » Tue Aug 16, 2016 5:53 pm

Seems like the signature for "buy_internal" is outdated. What game is this for?
arawra
Senior Member
Posts: 190
Joined: Fri Jun 21, 2013 6:51 am

Re: Weapon constants

Postby arawra » Tue Aug 16, 2016 6:12 pm

CS:GO
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: Weapon constants

Postby satoon101 » Tue Aug 16, 2016 10:07 pm

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.
Image
arawra
Senior Member
Posts: 190
Joined: Fri Jun 21, 2013 6:51 am

Re: Weapon constants

Postby arawra » Tue Aug 16, 2016 10:27 pm

I was able to come up with a different solution. Keep up the good work.
User avatar
Ayuto
Project Leader
Posts: 2193
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: Weapon constants

Postby Ayuto » Wed Aug 17, 2016 4:56 am

Yes, the connection to GitHub seems to timeout sometimes. I will trigger the build again now.

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 39 guests