Wayback Machine
OCT MAY Jun
Previous capture 5 Next capture
2004 2006 2007
10 captures
22 Apr 03 - 5 May 06
sparklines
Close Help

# menu
 
http://www.planethalflife.com/hlprogramming > tutorials > database 

news
 
current
 
submit

tutorials
 
database
  -
mp
  -
client
 
submit
 
search

forum
 
main

contact
 
email

Team Coloured Text and Spectator Chat
Created by Pongles



HalfLife's Code is BLUE
Pongles's Code is RED
Pongles's Commentary is GREEN


This tut will show you how to make spectators stop seeing what alive people are saying and vice-vesa.
just replace Host_Say with this:


// Pongles [
void Host_Say( edict_t *pEntity, int teamonly )
{
CBasePlayer *client;
int j;
char *p;
char text[128];
char szTemp[256];
const char *cpSay = "say";
const char *cpSayTeam = "say_team";
const char *pcmd = CMD_ARGV(0);

CBasePlayer *pSendingPlayer = GetClassPtr((CBasePlayer*)VARS(pEntity));

// We can get a raw string now, without the "say " prepended
if ( CMD_ARGC() == 0 )
return;

if ( !stricmp( pcmd, cpSay) || !stricmp( pcmd, cpSayTeam ) )
{
if ( CMD_ARGC() >= 2 )
{
p = (char *)CMD_ARGS();
}
else
{
// say with a blank message, nothing to do
return;
}
}
else // Raw text, need to prepend argv[0]
{
if ( CMD_ARGC() >= 2 )
{
sprintf( szTemp, "%s %s", ( char * )pcmd, (char *)CMD_ARGS() );
}
else
{
// Just a one word command, use the first word...sigh
sprintf( szTemp, "%s", ( char * )pcmd );
}
p = szTemp;
}

// remove quotes if present
if (*p == ''"'')
{
p++;
p[strlen(p)-1] = 0;
}

// make sure the text has content
for ( char *pc = p; pc != NULL && *pc != 0; pc++ )
{
if ( isprint( *pc ) && !isspace( *pc ) )
{
pc = NULL; // we''ve found an alphanumeric character, so text is valid
break;
}
}

if ( pc != NULL )
return; // no character found, so say nothing

/*
client = NULL;

client = (CBasePlayer*)UTIL_FindEntityByClassname( client, "player" );
*/


// turn on color set 2 (color on, no sound)
if (teamonly && pSendingPlayer->m_iDead == 1)
sprintf( text, "%c*DEAD* (TEAM) %s: ", 2, STRING( pEntity->v.netname ) );
else if (pSendingPlayer->m_iDead == 1)
sprintf( text, "%c*DEAD* %s: ", 2, STRING( pEntity->v.netname ) );
else if ( teamonly )
sprintf( text, "%c(TEAM) %s: ", 2, STRING( pEntity->v.netname ) );
else
sprintf( text, "%c%s: ", 2, STRING( pEntity->v.netname ) );

j = sizeof(text) - 2 - strlen(text); // -2 for /n and null terminator
if ( (int)strlen(p) > j )
p[j] = 0;

strcat( text, p );
strcat( text, "\n" );

// loop through all players
// Start with the first player.
// This may return the world in single player if the client types something between levels or during spawn
// so check it, or it will infinite loop

client = NULL;
while ( ((client = (CBasePlayer*)UTIL_FindEntityByClassname( client, "player" )) != NULL) && (!FNullEnt(client->edict())) )
{
if ( !client->pev )
continue;

if ( client->edict() == pEntity )
continue;

if( !(pSendingPlayer->m_iDead == client->m_iDead))
continue;

if ( !(client->IsNetClient()) ) // Not a client ? (should never be true)
continue;

if ( teamonly && g_pGameRules->PlayerRelationship(client, CBaseEntity::Instance(pEntity)) != GR_TEAMMATE )
continue;

MESSAGE_BEGIN( MSG_ONE, gmsgSayText, NULL, client->pev );
WRITE_BYTE( ENTINDEX(pEntity) );
WRITE_STRING( text );
MESSAGE_END();
}

// print to the sending client
MESSAGE_BEGIN( MSG_ONE, gmsgSayText, NULL, &pEntity->v );
WRITE_BYTE( ENTINDEX(pEntity) );
WRITE_STRING( text );
MESSAGE_END();

// echo to server console
g_engfuncs.pfnServerPrint( text );

char * temp;
if ( teamonly )
temp = "say_team";
else
temp = "say";

// team match?
if ( g_teamplay )
{
UTIL_LogPrintf( "\"%s<%i><%u><%s>\" %s \"%s\"\n",
STRING( pEntity->v.netname ),
GETPLAYERUSERID( pEntity ),
GETPLAYERWONID( pEntity ),
g_engfuncs.pfnInfoKeyValue( g_engfuncs.pfnGetInfoKeyBuffer( pEntity ), "model" ),
temp,
p );
}
else
{
UTIL_LogPrintf( "\"%s<%i><%u><%i>\" %s \"%s\"\n",
STRING( pEntity->v.netname ),
GETPLAYERUSERID( pEntity ),
GETPLAYERWONID( pEntity ),
GETPLAYERUSERID( pEntity ),
temp,
p );
}
}
// Pongles ]


and then create a var "m_iDead" that is set to 1 when ur dead.

isn''t that easy?

all comments etc to pongles@btinternet.com

if you would like to use it same address

Pongles