Syntax: Select all
from filters.weapons import WeaponClassIter
from players.entity import Player
from weapons.restrictions import WeaponRestrictionHandler
my_handler = WeaponRestrictionHandler()
# Restrict Terrorists from using any weapon besides their knife
my_handler.add_team_restrictions(
2, *[weapon.basename for weapon in WeaponClassIter(not_filters='knife')])
# Restrict CTs from using knives
my_handler.add_team_restrictions(
3, *[weapon.basename for weapon in WeaponClassIter('knife')])
# Restrict a specific player from using a glock
my_handler.add_player_restrictions(Player(1), 'glock')
# Allow Terrorists to use ak47s and glocks
my_handler.remove_team_restrictions(2, 'glock', 'ak47')
# Unrestrict the specific player from the glock
my_handler.remove_player_restrictions(Player(1), 'glock')
The handler gets added to the weapon_restriction_manager object. So, if you want to find out if a player/team is restricted from a weapon, use the weapon_restriction_manager object itself:
Syntax: Select all
from weapons.restrictions import weapon_restriction_manager
print(weapon_restriction_manager.is_player_restricted(Player(1), 'glock'))
print(weapon_restriction_manager.is_team_restricted(2, 'ak47')
You can also inherit from WeaponRestrictionHandler to override the built-in functionality of any of the following methods:
- on_player_bumping_weapon
- on_player_purchasing_weapon
- is_player_restricted
- is_team_restricted
- on_player_restriction_added
- on_team_restriction_added
- on_player_carrying_restricted_weapon
For instance:
Syntax: Select all
from messages import SayText2
from players.teams import teams_by_number
from weapons.restrictions import WeaponRestrictionHandler
class TestWeaponRestrictionHandler(WeaponRestrictionHandler):
def on_player_purchasing_weapon(self, player, weapon):
"""Disable weapon purchasing altogether."""
return False
def on_team_restriction_added(self, team, weapon):
"""Notify the team that the weapon was restricted."""
SayText2('Your team was restricted from using weapon "{0}".'.format(
weapon).send(PlayerIter(teams_by_number[team]))
super().on_team_restriction_added(team, weapon)
def on_player_carrying_restricted_weapon(self, player, weapon):
"""Notify the player that the weapon was restricted."""
SayText2('You were just restricted from using weapon "{0}", '
'forcing your weapon to be dropped.'.format(
weapon)).send(player.index)
my_handler = TestWeaponRestrictionHandler()