Client Commands

Official Announcements about Source.Python.
User avatar
ashbash1987
Developer
Posts: 20
Joined: Tue Jul 10, 2012 12:01 pm
Location: Sheffield, UK
Contact:

Client Commands

Postby ashbash1987 » Wed Nov 28, 2012 9:12 pm

Since you've all been waiting for it, here's the first pass for Client Commands! It's now in the latest source code revision. Here's a quick sample I whipped up:

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.
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Thu Nov 29, 2012 1:04 am

Awesome, Ash!!! Can't wait to test this out and get the Python API written!!

Satoon
Omega_K2
Senior Member
Posts: 227
Joined: Sat Jul 07, 2012 3:05 am
Location: Europe
Contact:

Postby Omega_K2 » Thu Nov 29, 2012 3:10 pm

Nice :D

For now at the very least you can do "public" say commands though player_say event, so that's not much of an issue.

On another note, was the problem with crashing fixed for server commands when you passed object methods (ex. myobj.mymethod) instead of normal methods (or classes with __call__) ? The ticket I submitted on SP was never closed nor I can renember seeing this in the changelog being fixed, but I might have overlooked it.
Libraries: k2tools
Plugins (any): GSRPG (soon) | Pretty Status List | MySQLAds (soon)
Plugins (game-specific): None atm

If you happen to find a bug or need help, either post in the release threads or contact me in IRC gamesurge.net:6667 / #sourcepython
Tuck
Global Moderator
Posts: 205
Joined: Sat Jul 14, 2012 9:35 pm
Location: Copenhagen

Postby Tuck » Thu Nov 29, 2012 5:53 pm

does this mean we can start getting menu selection from clients? :)
-Tuck

Return to “News & Announcements”

Who is online

Users browsing this forum: No registered users and 18 guests