Non case-sensitive chat commands? [message #367682] |
Sat, 17 January 2009 22:02  |
a000clown
Messages: 364 Registered: May 2005 Location: Canada
Karma: 0
|
Commander |
|
|
So I have the most basic of chat commands:
class ExampleChatCommand : public ChatCommandClass {
void Triggered(int ID,const TokenClass &Text,int ChatType) {
Send_Message(255,255,255,StrFormat("Example.").c_str());
}
};
ChatCommandRegistrant<ExampleChatCommand> ExampleChatCommandReg("!example;!EXAMPLE",CHATTYPE_ALL,0,GAMEMODE_ALL);
!example works
!EXAMPLE works
But what if I was typing fast and did !Example
I've been searching for a way to disable case-sensitivity for awhile but haven't found anything useful yet.
Any pointers would help a lot.
[Updated on: Sat, 17 January 2009 22:03] Report message to a moderator
|
|
|
Re: Non case-sensitive chat commands? [message #367684 is a reply to message #367682] |
Sat, 17 January 2009 22:42   |
Genesis2001
Messages: 1397 Registered: August 2006
Karma: 0
|
General (1 Star) |
|
|
Use the native chat hook ssgm provides and sscanf/strcmp/stricmp parse it. 
char Command[80], params[256];
if (sscanf(Message, "%s %s", &Command, ¶ms) == 0) // granted not 100% sure how to grab anything after the first request...
{
if (stricmp(Command, "!test") == 0) // could be strcmp for case in-sensitive matches, but then again...not sure
{
// do stuffz
}
}
*pokes RoShamBo the mentor* lol
[Updated on: Sat, 17 January 2009 22:43] Report message to a moderator
|
|
|
|
|
Re: Non case-sensitive chat commands? [message #367829 is a reply to message #367715] |
Sun, 18 January 2009 19:59   |
Genesis2001
Messages: 1397 Registered: August 2006
Karma: 0
|
General (1 Star) |
|
|
RoShamBo wrote on Sun, 18 January 2009 06:12 |
char Command[80], params[256];
*params = 0;
char msg[256];
strcpy(msg, "msg !test called with: ");
if (sscanf(Message, "%s %[^\n]", Command, params) != 0)
{
if (stricmp(Command, "!test") == 0)
{
if(*params != 0)
{
strcat(msg, params);
}
else
{
strcat(msg, "no params")
}
Console_Input(msg);
}
}
|
Thanks to you too for correcting me!
|
|
|
Re: Non case-sensitive chat commands? [message #367897 is a reply to message #367682] |
Mon, 19 January 2009 05:10  |
 |
jnz
Messages: 3396 Registered: July 2006 Location: 30th century
Karma: 0
|
General (3 Stars) |
|
|
In sscanf, %[] means "everything" the '^' character means "except this"
%[^g] would mean everything except 'g' %[\n] means everything except '\n'. You can also combine them, %[^\ngasd] "everything except '\n','g','a','s','d'"
If you don't have the '^' character you can use it to match "specific" characters.
%[abcd] would only match 'a','b','c','d'
%s in sscanf means a word, so it will stop reading when it meets whitespace or a newline. Not sure on the exact characters it actually reads.
scanf returns the number of variables matched, so we want 2 vars out of the string, we use == 2 or >1 to make sure it succeeded.
Lastly, whitespace in the format string means "whitespace" and not a single space.
sscanf("hello world!", "%s %s", hello, world) //fill hello and world
This applies to everything
sscanf("123 321", "%d %d", &i, &u) //123 321
stricmp is non-case sensitive.
|
|
|