This is how you would remove a specific weapon from a player's inventory:
Syntax: Select all
from events import Event
from players.entity import PlayerEntity
from players.helpers import index_from_userid
from entities.entity import BaseEntity
@Event
def player_say(GameEvent):
# Get the player's userid
userid = GameEvent.GetInt('userid')
# Get the player's index
index = index_from_userid(userid)
# Get the player's PlayerEntity instance
player = PlayerEntity(index)
# Get the player's secondary weapon's index
weapon_index = player.get_secondary()
# Get the weapon's BaseEntity instance
weapon = BaseEntity(weapon_index)
# Have the player drop the weapon
player.drop_weapon(weapon.pointer, True, True)
# Remove the weapon from the server
weapon.remove()
This is how you would remove all weapons except the knife from the player's inventory:
Syntax: Select all
from events import Event
from players.entity import PlayerEntity
from players.helpers import index_from_userid
from entities.entity import BaseEntity
@Event
def player_say(GameEvent):
# Get the player's userid
userid = GameEvent.GetInt('userid')
# Get the player's index
index = index_from_userid(userid)
# Get the player's PlayerEntity instance
player = PlayerEntity(index)
# Loop through all weapons in the player's inventory
for weapon_index in player.weapon_indexes(not_filters='knife'):
# Get the weapon's BaseEntity instance
weapon = BaseEntity(weapon_index)
# Have the player drop the weapon
player.drop_weapon(weapon.pointer, True, True)
# Remove the weapon from the server
weapon.remove()
Of course, this will only work on games that have the dynamic functions for DropWeapon and UTIL_Remove implemented.
If you do not remove the weapons, you can also use the drop_weapon functionality to cause players to drop their weapons (including grenades and even their knife).
Satoon