Jump to content

Home

Announcement command


Recommended Posts

Nono, i mean.

 

You can't do

 

/arbitraryprint i will display on the screen

 

because it will still pop up with

"Blah blah blah"

 

I wanted to make a command that does that but displays what you type on the screen, and not the same thing whenever you use a command, like this.

 

/bigtext I will be displayed on the big screen

"I will be displayed on the big screen"

Link to post
Share on other sites

First, here's your function you'll want to call

 

void Cmd_announce_f( gentity_t *ent )
{
char p[1024];//This buffer will fit ~1024 characters
if ( trap_Argc () < 2 )
{//if there are less than 2 args print help (the actual command counts as an arg)
	trap_SendServerCommand( ent-g_entities, va( "print \"^5Command Usage: ^7announce <message> ^3Prints a message to every client\n\"" ) );
	return; //if there are less than 2 args print help (the actual command counts as an arg)
}

strcpy(p, ConcatArgs(1)); //Grab the second arg and put it in our buffer (the actual command counts as an arg)

//TODO: insert line-feed handling stuff here

G_LogPrintf( "announce: %s: %s\n", ent->client->pers.netname, p ); //log the action in the server console
trap_SendServerCommand( -1, va("cp \"%s\"", p) ); //print it on-screen

return;
}

 

Then chuck in this code in the ClientCommand function appropriately

	else if (!Q_stricmp(cmd, "announce"))
{
	Cmd_announce_f(ent);
	return;
}

 

I haven't implemented handling line feeds into that yet, so if you want that you'll have to do it yourself I'm afraid. (A line feed goes to the next line by using '\n')

Sorry for not understanding earlier, I hadn't poked around 'arbitraryprint' in a while and thought it automatically did this =P

 

Feel free to use this code. I'm not gonna ask for money ;P

Link to post
Share on other sites

Well okay, I found a way to get line-feeds working =P

	p = G_NewString(p);		//insert line-breaks and stuff

G_LogPrintf( "announce: %s: %s\n", ent->client->pers.netname, p ); //log the action in the server console
trap_SendServerCommand( -1, va("cp \"%s\"", p) ); //print it on-screen

free(p);

return;

Mind you, I use a custom version of G_NewString which uses 'newb = (char*)malloc(l);' rather than 'newb = (char *) G_Alloc( l );'

You must free your memory! otherwise the server will crash after the function is called too many times.

Edited by -=*Raz0r*=-
Link to post
Share on other sites
×
×
  • Create New...