Clientside text in chatarea


(Discovery) #1

Hi all,

I am new to modding ET, but I just want to try to make my own mod. I added things like the option to display teamkill obits as TEAMKILL: <normal obit> but I want to add an option to display the obits in the chat area instead of the popup area. The problem is: I cannot find the clientside command to put the obits over there. I know how I can add client side popups, but not client side chat messages. I don’t want to send the obits to the server, so the server can add them to the chat (I know how to do that :wink: ), I just want to add them clientside.

I hope my question is clear now and you guys can help me :slight_smile: .

Discovery


(Discovery) #2

Was my question really that noobish? :wink:

I shall say what I have done now, but it doesn’t seem right to me so ANY help is much appreciated.

I copied this from cg_servercmds.c to cg_event.c:

/*
=======================
CG_AddToTeamChat

Dens Copied to here from cg_servercmds.c to make it possible for obits to appear in the chat area
=======================
*/
static void CG_AddToTeamChat( const char *str, int clientnum ) {
	int len;
	char *p, *ls;
	int lastcolor;
	int chatHeight;

	if (cg_teamChatHeight.integer < TEAMCHAT_HEIGHT) {
		chatHeight = cg_teamChatHeight.integer;
	} else {
		chatHeight = TEAMCHAT_HEIGHT;
	}

	if (chatHeight <= 0 || cg_teamChatTime.integer <= 0) {
		// team chat disabled, dump into normal chat
		cgs.teamChatPos = cgs.teamLastChatPos = 0;
		return;
	}

	len = 0;

	p = cgs.teamChatMsgs[cgs.teamChatPos % chatHeight];
	*p = 0;

	lastcolor = '7';

	ls = NULL;
	while (*str) {
		if (len > TEAMCHAT_WIDTH - 1) {
			if (ls) {
				str -= (p - ls);
				str++;
				p -= (p - ls);
			}
			*p = 0;

			cgs.teamChatMsgTimes[cgs.teamChatPos % chatHeight] = cg.time;
			cgs.teamChatMsgTeams[cgs.teamChatPos % chatHeight] = cgs.clientinfo[ clientnum ].team;

			cgs.teamChatPos++;
			p = cgs.teamChatMsgs[cgs.teamChatPos % chatHeight];
			*p = 0;
			*p++ = Q_COLOR_ESCAPE;
			*p++ = lastcolor;
			len = 0;
			ls = NULL;
		}

		if ( Q_IsColorString( str ) ) {
			*p++ = *str++;
			lastcolor = *str;
			*p++ = *str++;
			continue;
		}
		if (*str == ' ') {
			ls = p;
		}
		*p++ = *str++;
		len++;
	}
	*p = 0;

	cgs.teamChatMsgTeams[cgs.teamChatPos % chatHeight] = cgs.clientinfo[ clientnum ].team;
	cgs.teamChatMsgTimes[cgs.teamChatPos % chatHeight] = cg.time;
	cgs.teamChatPos++;

	if (cgs.teamChatPos - cgs.teamLastChatPos > chatHeight)
		cgs.teamLastChatPos = cgs.teamChatPos - chatHeight;
}

And then after de case MOD_XXX part of the code, i replaced the CG_AddPmItem part with this:

...
case MOD_SMOKEGRENADE: // rain
			// bani - more amusing
			message = "danced on his airstrike marker";
			break;
		case MOD_SUICIDE: // Dens Copied to here, otherwhise the game would skip suicide
			message = "committed suicide";
			break;
		// no obituary message if changing teams
		case MOD_SWITCHTEAM:
			return;
		default:
			message = "killed himself";
			break;
		}
	}
if (message) {
		message = CG_TranslateString( message );
			if(dens_cg_obit.integer >= 1){ // Dens If obits should be shown
	//	CG_AddPMItem( PM_DEATH, va( "%s %s.", targetName, message ), deathShader );
				CG_Printf( va( "%s %s.
", targetName, message ) );
				CG_AddToTeamChat( va( "%s %s.", targetName, message ), -1 );
		return;
			}else{return;} // Dens
	} 

It now seems to work correctly: the obits are shown in the chat area instead of the cpm area, but I think this way of putting obits over there isn’t the best way. Furthermore I am very uncertain about the -1 from “G_AddToTeamChat( va( “%s %s.”, targetName, message ), -1 );”. Should this value be -1 or should I change this?

I hope anyone of you can help me with this :slight_smile: .


(jaybird) #3

This is essentially correct. I do not see the need to copy all of that code though. I can’t remember if that function is static by default. If it is, simply make it not static, and throw its prototype into cg_local.h.

The -1 means to send the message to all clients.


(Discovery) #4

Thank you for answering. It is just nice to know if the things I do are correct.

This is essentially correct. I do not see the need to copy all of that code though. I can’t remember if that function is static by default. If it is, simply make it not static, and throw its prototype into cg_local.h.

I shall try that later tonight :slight_smile: .

The -1 means to send the message to all clients.

Thats what I guessed, but I wasn’t sure enough.