Error on restrict weapon

Please post any questions about developing your plugin here. Please use the search function before posting!
existenz
Senior Member
Posts: 111
Joined: Thu Feb 09, 2017 3:33 pm
Location: France
Contact:

Error on restrict weapon

Postby existenz » Thu Feb 09, 2017 3:42 pm

Hi every body !

I have an error which spamming on my server. I need your help to fix it.
I think the problem is that event player_spawn has been called before player is really spawn but i don't know if it's the real problem.

Syntax: Select all

_knifeonly = set(weapon.basename for weapon in WeaponClassIter()) - { 'weapon_knife', 'weapon_c4' }


Syntax: Select all

.
@events('player_spawn')
def _on_player_spawn(self, player, **eargs):
player.restrict_weapons(*_knifeonly)
for weapon in player.weapons(not_filters=['knife', 'c4']):
player.drop_weapon(weapon.pointer, None, None)

@events('player_death')
def _on_player_death(self, player, **eargs):
player.unrestrict_weapons(*_knifeonly)


Syntax: 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: '"2" is neither a team number nor an alias.'


Sincerly Existenz.
Last edited by satoon101 on Thu Feb 09, 2017 11:25 pm, edited 1 time in total.
Reason: Python syntax highlighting
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: Error on restrict weapon

Postby satoon101 » Thu Feb 09, 2017 11:24 pm

First, welcome to the forums!

A pull request has been submitted and merged to fix this issue. Thank you for reporting. This fix will be available when build 552 is ready.

For future reference, please use [python][/python] when posting Python code on the forums. I have updated your post accordingly.
Image
existenz
Senior Member
Posts: 111
Joined: Thu Feb 09, 2017 3:33 pm
Location: France
Contact:

Re: Error on restrict weapon

Postby existenz » Fri Feb 10, 2017 8:27 am

Thanks :)
No worries I would use this in the future.
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: Error on restrict weapon

Postby L'In20Cible » Fri Feb 10, 2017 10:12 am

As a side note, the following line:

Syntax: Select all

player.drop_weapon(weapon.pointer, None, None)
Could simply be:

Syntax: Select all

player.drop_weapon(weapon)
existenz
Senior Member
Posts: 111
Joined: Thu Feb 09, 2017 3:33 pm
Location: France
Contact:

Re: Error on restrict weapon

Postby existenz » Fri Feb 10, 2017 12:49 pm

Thanks L'In20Cible.
I will change that in my code.
existenz
Senior Member
Posts: 111
Joined: Thu Feb 09, 2017 3:33 pm
Location: France
Contact:

Re: Error on restrict weapon

Postby existenz » Mon Feb 27, 2017 9:33 am

Hey
Your fix work on my old error, but a new error comes.
Have you an idea why ?

I used last version of sourcepython.

Syntax: Select all

_scoutonly =  set(weapon.name for weapon in WeaponClassIter()) - {'weapon_knife', 'weapon_ssg08', 'weapon_c4'}

@events('player_spawn')
def _on_player_spawn(self, player, **eargs):
player.restrict_weapons(*_scoutonly)
_have_scout = False
for weapon in player.weapons():
if weapon.class_name != 'weapon_ssg08' and weapon.class_name != 'weapon_knife':
player.drop_weapon(weapon)
elif weapon.class_name == 'weapon_ssg08':
_have_scout = True

if not _have_scout:
player.give_named_item('weapon_ssg08', 0, None, True)


Error :

Syntax: Select all

[SP] Caught an Exception:
Traceback (most recent call last):
File "../addons/source-python/packages/source-python/weapons/restrictions.py", line 388, 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 290, in on_player_bumping_weapon
return not self.is_player_restricted(player, weapon)
File "../addons/source-python/packages/source-python/weapons/restrictions.py", line 316, in is_player_restricted
return self.is_team_restricted(player.team, weapon_name)
File "../addons/source-python/packages/source-python/weapons/restrictions.py", line 326, 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: '"0" is neither a team number nor an alias.'
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: Error on restrict weapon

Postby L'In20Cible » Mon Feb 27, 2017 11:42 am

Add this check prior any other code into your _on_player_spawn method:

Syntax: Select all

#Is the player in a valid team?
if player.team <= 1:
return
This happens because that event is called when the players are joining the server before they actually select a team.
existenz
Senior Member
Posts: 111
Joined: Thu Feb 09, 2017 3:33 pm
Location: France
Contact:

Re: Error on restrict weapon

Postby existenz » Mon Feb 27, 2017 1:21 pm

Thanks for your answer.
I will try your solution when I would come back from work.
existenz
Senior Member
Posts: 111
Joined: Thu Feb 09, 2017 3:33 pm
Location: France
Contact:

Re: Error on restrict weapon

Postby existenz » Mon Feb 27, 2017 7:42 pm

Thanks, i think it works.

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 35 guests