Both SayFilters and SayCommands will have 3 arguments passed:
- index - the index of the player that said something
- teamonly - bool value for whether the say_team command was used instead of say
- CCommand - the CCommand instance that allows you to get all text
Syntax: Select all
from commands.say import SayFilter
from commands.say.command import SayCommandDictionary
@SayFilter
def say_filter(index, teamonly, CCommand):
# Get the text used
# The entire text is in argument 1, since it is encased in ""
text = CCommand[1]
# Get the first word
word = text.split()[0]
# Was a command used?
if word in SayCommandDictionary:
# Do nothing
return True
# Do not allow the text in chat if not a command
return False
Syntax: Select all
from commands.say import SayCommand
from entities.entity import BaseEntity
from filters.weapontags import WeaponTagIter
from players.entity import PlayerEntity
from weapons.manager import WeaponManager
# Store a list of primary and secondary weapons
_weapons = {
'primary': list(WeaponTagIter('primary', return_types='classname')),
'secondary': list(WeaponTagIter('secondary', return_types='classname')),
}
@SayCommand('!give')
def test_command(index, teamonly, CCommand):
# Get the text
text = CCommand[1].split()
# Was a weapon given?
if not len(text) > 1:
# Do nothing
return True
# Get the weapon
# text[0] is the "!give" command itself
weapon = text[1]
# Was a proper weapon name given?
if not weapon in WeaponManager:
# Do nothing
return True
# Get the player's PlayerEntity instance
player = PlayerEntity(index)
# Get the weapon's proper name
weapon = WeaponManager[weapon].name
# Loop through primary and secondary weapons
for weapon_type in _weapons:
# Is the weapon in the current list?
if not weapon in _weapons[weapon_type]:
# If not, continue to the next weapon type
continue
# Get the player's current weapon of this type
weapon_index = player.get_weapon_index(is_filters=weapon_type)
# Does the player currently have a weapon of this type?
if weapon_index is None:
# If not, no need to remove their current weapon
break
# Get the weapon's BaseEntity instance
current_weapon = BaseEntity (index)
# Is the given weapon the same as the one the player already owns?
if current_weapon.classname == weapon:
# If so, no need to remove their current weapon
break
# Remove the weapon from the player's inventory
player.drop_weapon(current_weapon.pointer, True, True)
current_weapon.remove()
# Give the player the new weapon
player.give_named_item(weapon, 0, True)
If you have any questions, please feel free to ask. If you have any suggestions, please feel free to post them, as well.
Satoon