Jump to content

Home

messagemodes


Dom_152

Recommended Posts

I have Clan Chat in my Mod but at the moment the only way to use it is to write /say_clan Your Message. Is terhe any way of making it so that messagemode4 is my clan chat. So /bind u messagemode4 would allow people to press U type their message and send it just like normal chat. How can i do it? I've looked for ages and I can't work it out.

Link to comment
Share on other sites

4 is already taken.

 

ofc you could write a way in cmd_say_f to intercept something like /clan from messagemode.

 

add this above cmd_say_f:

 

/*
==================
Cmd_Clan_f
==================
*/
void Cmd_Clan_f(gentity_t *ent) 
{
char cmd[12];
char *msg;
int skipargs = 0;

Q_SayArgv(0, cmd, sizeof(cmd));
if(!Q_stricmp(cmd, "say") || !Q_stricmp(cmd, "say_team")) {
	skipargs = 1;
	Q_SayArgv(1, cmd, sizeof(cmd));
}
if(Q_SayArgc() < 3+skipargs) {
	SP(va2("Usage: %s [name|slot#] [message]\n\"", cmd));
	return;
}
Q_SayArgv(1+skipargs, name, sizeof(name));
msg = Q_SayConcatArgs(2+skipargs);

G_Say(ent, NULL, SAY_CLAN, msg);
}

 

replace the old cmd_say_f with this:

 

/*
==================
Cmd_Say_f
==================
*/
void Cmd_Say_f( gentity_t *ent, int mode, qboolean arg0 )
{
char *args;
//	char *msg;

if(trap_Argc() < 2 && !arg0) return;
args = Q_SayConcatArgs(0);

if (!Q_stricmpn(args, "say /clan ", 8) ||
	 !Q_stricmpn(args, "say_team /clan ", 13)) {
	Cmd_Clan_f( ent );
}
else {
	G_Say(ent, NULL, mode, ConcatArgs(((arg0) ? 0 : 1)));
}
}

 

make sure these are defined below ConcatArgs, and then add them to g_local.h somewhere so you can use them above and elsewhere.

 

// replaces all occurances of "\n" with '\n'
char *Q_AddCR(char *s)
{
char *copy, *place, *start;

if(!*s) return s;
start = s;
while(*s) {
	if(*s == '\\') {
		copy = s;
		place = s;
		*s++;
		if(*s && *s == 'n') {
			*copy = '\n';
			while(*++s) {
				*++copy = *s;
			}
			*++copy = '\0';
			s = place;
			continue;
		}
	}
	*s++;
}
return start;
}

// A replacement for trap_Argc() that can correctly handle
//   say "!cmd arg0 arg1"
// as well as
//   say !cmd arg0 arg1
// The client uses the latter for messages typed in the console
// and the former when the message is typed in the chat popup
int Q_SayArgc(void) 
{
int c = 1;
char *s;

s = ConcatArgs(0);
if(!*s) return 0;
while(*s) {
	if(*s == ' ') {
		*s++;
		if(*s != ' ') {
			c++;
			continue;
		}
		while(*s && *s == ' ') *s++;  
		c++;
	}
	*s++;
}
return c;
}

// A replacement for trap_Argv() that can correctly handle
//   say "!cmd arg0 arg1"
// as well as
//   say !cmd arg0 arg1
// The client uses the latter for messages typed in the console
// and the former when the message is typed in the chat popup
qboolean Q_SayArgv(int n, char *buffer, int bufferLength)
{
int bc = 1;
int c = 0;
char *s;

if(bufferLength < 1) return qfalse;
if(n < 0) return qfalse;
*buffer = '\0';
s = ConcatArgs(0);
while(*s) {
	if(c == n) {
		while(*s && (bc < bufferLength)) {
			if(*s == ' ') {
				*buffer = '\0';
				return qtrue;
			}
			*buffer = *s;
			*buffer++;
			*s++;
			bc++;
		}
		*buffer = '\0';
		return qtrue;
	}
	if(*s == ' ') {
		*s++;
		if(*s != ' ') {
			c++;
			continue;
		}
		while(*s && *s == ' ') *s++;  
		c++;
	}
	*s++;
}
return qfalse;
}

 

Now, all you have to do is maybe add password support to cmd_clan_f and make sure msgs checks 3+skiparg, then just do the rest of the checking in g_say and g_sayto.

 

the only way you can make a new messagemode is to write a client hack to load a menu that has a textbox and allows you to press enter and close the menu and send your /say cmd. which imo is very difficult.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...