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

Please post any questions about developing your plugin here. Please use the search function before posting!
BrunoG
Junior Member
Posts: 6
Joined: Sat Nov 09, 2013 8:28 pm

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

Postby BrunoG » Sat Feb 15, 2014 9:27 pm

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?
User avatar
Ayuto
Project Leader
Posts: 2193
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Sat Feb 15, 2014 9:39 pm

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.
BrunoG
Junior Member
Posts: 6
Joined: Sat Nov 09, 2013 8:28 pm

Postby BrunoG » Sat Feb 15, 2014 9:44 pm

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

Postby satoon101 » Sun Feb 16, 2014 1:41 am

User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Sun Feb 16, 2014 7:46 am

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
BrunoG
Junior Member
Posts: 6
Joined: Sat Nov 09, 2013 8:28 pm

Postby BrunoG » Sun Feb 16, 2014 1:55 pm

Thanks Satoon, i'll have a look into those later, seems to be a better approach.

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 25 guests