SayCommands and args

Please post any questions about developing your plugin here. Please use the search function before posting!
User avatar
Kami
Global Moderator
Posts: 263
Joined: Wed Aug 15, 2012 1:24 am
Location: Germany

SayCommands and args

Postby Kami » Thu Jan 18, 2018 8:10 pm

Hey guys,

I've been trying to fetch arguments for SayCommands. My example is changerace from WCS. I try to read the chatmessage:

Code: Select all

changerace undead


and want to read the argument given. but when I use arg_string or command_string it just returns changerace, not everything I say.

Now I'm wondering if this is on purpose and if so what should I use alternatively to do this.

I noticed that ClientCommand can read the args, but in this case I really need the SayCommand.

Thank you! :)


Edit: The code I use:

Syntax: Select all

@SayCommand('changerace')
@ClientCommand('changerace')
def _changerace_command(command, index, team=None):
userid = userid_from_index(index)
if not command.arg_string:
changerace.HowChange(userid)
else:
changerace.HowChange(userid,command.arg_string)
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: SayCommands and args

Postby L'In20Cible » Thu Jan 18, 2018 9:21 pm

Hm, command_string works fine for me.

Syntax: Select all

from commands.say import SayCommand

@SayCommand('test')
def _test_command(command, index, team_only=False):
if not len(command) > 1:
return print('No argument given.')
print('command_string =', command.command_string)
for index, arg in enumerate(command):
print(f'Argument #{index} = {arg}')
"""
No argument given.
L'In20Cible: test

command_string = test foo bar test blah lol 69
Argument #0 = test
Argument #1 = foo
Argument #2 = bar
Argument #3 = test
Argument #4 = blah
Argument #5 = lol
Argument #6 = 69
L'In20Cible: test foo bar test blah lol 69
"""

You should also take a look at TypedSayCommand: http://wiki.sourcepython.com/developing ... mands.html
User avatar
Kami
Global Moderator
Posts: 263
Joined: Wed Aug 15, 2012 1:24 am
Location: Germany

Re: SayCommands and args

Postby Kami » Fri Jan 19, 2018 5:11 pm

I'm very sorry, you are right. I'm beeing stupid. I forgot I had a say filter, which was cause for this problem.

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 25 guests