Renegade Public Forums
C&C: Renegade --> Dying since 2003™, resurrected in 2024!
Home » Renegade Discussions » Mod Forum » Non case-sensitive chat commands?
Non case-sensitive chat commands? [message #367682] Sat, 17 January 2009 22:02 Go to next message
a000clown
Messages: 363
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 Go to previous messageGo to next message
Genesis2001
Messages: 1397
Registered: August 2006
Karma: 0
General (1 Star)
Use the native chat hook ssgm provides and sscanf/strcmp/stricmp parse it. Wink

char Command[80], params[256];
if (sscanf(Message, "%s %s", &Command, &params) == 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* Smile lol

[Updated on: Sat, 17 January 2009 22:43]

Report message to a moderator

Re: Non case-sensitive chat commands? [message #367715 is a reply to message #367684] Sun, 18 January 2009 06:12 Go to previous messageGo to next message
jnz is currently offline  jnz
Messages: 3396
Registered: July 2006
Location: 30th century
Karma: 0
General (3 Stars)
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);
    }
}


Re: Non case-sensitive chat commands? [message #367720 is a reply to message #367682] Sun, 18 January 2009 06:44 Go to previous messageGo to next message
a000clown
Messages: 363
Registered: May 2005
Location: Canada
Karma: 0
Commander
Ah, didn't expect solutions so soon, I should have asked months ago Razz

Thanks guys Thumbs Up
Re: Non case-sensitive chat commands? [message #367829 is a reply to message #367715] Sun, 18 January 2009 19:59 Go to previous messageGo to next message
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! Very Happy
Re: Non case-sensitive chat commands? [message #367897 is a reply to message #367682] Mon, 19 January 2009 05:10 Go to previous message
jnz is currently offline  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.
Previous Topic: Alternative to tiled textures?
Next Topic: Changing FONT in renegade
Goto Forum:
  


Current Time: Mon Oct 14 09:23:31 MST 2024

Total time taken to generate the page: 0.00728 seconds