Syntax: Select all
# ../commands/commands.py
# =============================================================================
# >> IMPORTS
# =============================================================================
# Source.Python Imports
from Source import ClientCmd
# =============================================================================
# >> COMMAND CALLBACKS
# =============================================================================
def command_callback(entity, command):
print("I am command callback 1. I have %d arguments: %s" % (command.ArgC(), command.ArgS()))
return ClientCmd.ClientCommandReturn.BLOCK
def command_callback2(entity, command):
print("I am command callback 2. I have %d arguments: %s" % (command.ArgC(), command.ArgS()))
return ClientCmd.ClientCommandReturn.CONTINUE
def command_callback3(entity, command):
print("I am command callback 3. I have %d arguments: %s" % (command.ArgC(), command.ArgS()))
return ClientCmd.ClientCommandReturn.CONTINUE
def jointeam_callback(entity, command):
print("I am a jointeam callback. I have %d arguments: %s" % (command.ArgC(), command.ArgS()))
return ClientCmd.ClientCommandReturn.CONTINUE
my_cmd = ClientCmd.GetClientCommand("my_command")
jointeam_cmd = ClientCmd.GetClientCommand("jointeam")
# =============================================================================
# >> ADDON LOAD/UNLOAD
# =============================================================================
def load():
"""
Called upon addon load.
"""
my_cmd.AddToEnd(command_callback)
my_cmd.AddToEnd(command_callback2)
my_cmd.AddToStart(command_callback3)
jointeam_cmd.AddToEnd(jointeam_callback)
def unload():
"""
Called upon addon unload.
"""
my_cmd.Remove(command_callback)
my_cmd.Remove(command_callback2)
my_cmd.Remove(command_callback3)
jointeam_cmd.Remove(jointeam_callback)
As you can see, the structure is very much like ConCommands, except the callbacks are called with 2 parameters: an entity and a command argument structure. Note here that I've also hooked into pre-existing client commands ('jointeam' in this example), and that I can block execution of the client command if I wish to with .BLOCK (as a quick example off the top of my head, think a class limiter in TF2 which would .BLOCK execution of 'joinclass' if there are too many of a certain class, or .CONTINUE if ok). Blocking a client command will stop execution of that command further down the queue and since this executes before being passed further down into the engine, it would prevent the final server-based action arising from the client command to execute.
Have a play with it, see what you can come up with :)
As an aside, 'say'/'say_team' doesn't work with this, as this is not client command that can be hooked this way, so say commands are currently not ready.