Weapon Restriction System

Please post any questions about developing your plugin here. Please use the search function before posting!
Predz
Senior Member
Posts: 158
Joined: Wed Aug 08, 2012 9:05 pm
Location: Bristol, United Kingdom

Weapon Restriction System

Postby Predz » Tue Aug 16, 2016 5:52 pm

I am trying to use the current restriction system included in SP. Was using my old version until I realised there is now a version included, so have opted to use that instead now. However I am getting a few problems when trying to restrict weapons to a player. For some reason it seems to not recognise the team number in the TeamRestrictions dict.

Traceback below:

Code: Select all

[SP] Caught an Exception:

Traceback (most recent call last):

File '../addons/source-python/packages/source-python/weapons/restrictions.py', line 384, in _on_weapon_bump

make_object(Player, args[0]), edict_from_pointer(args[1]).classname)

File '../addons/source-python/packages/source-python/weapons/restrictions.py', line 67, in on_player_bumping_weapon

value = handler.on_player_bumping_weapon(player, weapon_name)

File '../addons/source-python/packages/source-python/weapons/restrictions.py', line 286, in on_player_bumping_weapon

return not self.is_player_restricted(player, weapon)

File '../addons/source-python/packages/source-python/weapons/restrictions.py', line 312, in is_player_restricted

return self.is_team_restricted(player.team, weapon_name)

File '../addons/source-python/packages/source-python/weapons/restrictions.py', line 322, in is_team_restricted

return weapon_manager[weapon].basename in self.team_restrictions[team]

File '../addons/source-python/packages/source-python/weapons/restrictions.py', line 191, in __getitem__

''{0}' is neither a team number nor an alias.'.format(item))



KeyError: ''3' is neither a team number nor an alias.'
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: Weapon Restriction System

Postby Ayuto » Tue Aug 16, 2016 6:04 pm

Do you have code to reproduce the issue?
Predz
Senior Member
Posts: 158
Joined: Wed Aug 08, 2012 9:05 pm
Location: Bristol, United Kingdom

Re: Weapon Restriction System

Postby Predz » Tue Aug 16, 2016 7:06 pm

Yeh, sry :S


Syntax: Select all

from events import Event
from filters.weapons import WeaponClassIter
from players.entity import Player
from weapons.restrictions import weapon_restriction_handler

_knifeonly = set(weapon.basename for weapon in WeaponClassIter(not_filters='knife'))

@Event('player_spawn')
def _on_player_spawn_restrict(event):
player = Player.from_userid(event['userid'])
weapon_restriction_handler.add_player_restrictions(player, *_knifeonly)
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: Weapon Restriction System

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

I'll do some testing in a bit. A couple quick notes about your plugin. Neither of them really matter, but worth pointing out for future development.

First, in Python3, you can declare a set like this:

Syntax: Select all

_knifeonly = {weapon.basename for weapon in WeaponClassIter(not_filters='knife')}

Your way works perfectly fine, and I can see how this way could possibly get confusing with {} also being used for dictionaries. I tend to use it, myself, though.

Second, if you are just using the base weapon_restriction_handler and not creating your own, you can just use the Player.restrict_weapons method.
Image
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: Weapon Restriction System

Postby Ayuto » Wed Aug 17, 2016 5:20 pm

I'm not able to reproduce the issue on my machine. Which game are you testing? Are you using the latest version? When you updated your server, did you also update the data directory?

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 48 guests