Page 1 of 1

Help with Client Command Filter to force players to join specified team

Posted: Sat Feb 15, 2014 9:27 pm
by BrunoG
Hello,

I've this ES snippet

Syntax: Select all

import es

def load():

es.addons.registerClientCommandFilter(cc_filter)

def unload():

es.addons.unregisterClientCommandFilter(cc_filter)

def cc_filter(userId, args):

if args[0].lower() == 'jointeam':

team = getPlayer(userId).getAllowedTeam()

es.server.queuecmd('es_xchangeteam %i %i' % (userId, teams[team]))

return False

return True


That basically, whenever a player connects and choses a team, i force the user to join the team he specified elsewhere (in this case website, it's for a simple pug system), hence the team = ..

It's works nicelly, but i'm having issues porting this to SP, the code i have

Syntax: Select all

from commands.client import ClientCommandManager

def load():

ClientCommandManager.register_filter(client_command_filter)

def unload():

ClientCommandManager.unregister_filter(client_command_filter)

def client_command_filter(player, CCommand):

print('Testing')

'''
if CCommand == 'jointeam':

team = getPlayer(userId).getAllowedTeam()

es.server.queuecmd('es_xchangeteam %i %i' % (userId, teams[team]))

return False

return True
'''


But it always says that the plugin was unable to be loaded and is there a way to have better debugging so that i know where it's wrong?

Posted: Sat Feb 15, 2014 9:39 pm
by Ayuto
Your code should run without any problems. I guess you are running an out-dated version of SP.

To enable better debugging take a look at cfg\source-python\core_settings.ini.

Posted: Sat Feb 15, 2014 9:44 pm
by BrunoG
I've managed to figure out the not loading issue, was a left over import es, on another addon that i'm importing some variables, my bad.

Thanks for the info about the logging =)

Posted: Sun Feb 16, 2014 1:41 am
by satoon101

Posted: Sun Feb 16, 2014 7:46 am
by satoon101
Also, now that I actually looked at your code, you should register the command instead of using a filter. All registering a client command does is listen for it to be called as a client command. It does not actually register the command (same goes with say commands). So, instead of using a filter, you can just use a client command:
http://www.sourcepython.com/showwiki.php?title=Wiki:commands+client#register_commands
http://www.sourcepython.com/showwiki.php?title=Wiki:commands+client#unregister_commands

Or even better, the decorator class for client commands:
http://www.sourcepython.com/showwiki.php?title=Wiki:commands+client#ClientCommand

Satoon

Posted: Sun Feb 16, 2014 1:55 pm
by BrunoG
Thanks Satoon, i'll have a look into those later, seems to be a better approach.