LucasForums

LucasForums (http://www.lucasforums.com/index.php)
-   JA Coding (http://www.lucasforums.com/forumdisplay.php?f=539)
-   -   Announcement command (http://www.lucasforums.com/showthread.php?t=200340)

Unreliable 09-07-2009 04:43 PM

Announcement command
 
I was wondering how you could make an announcement pop up on the screen, such as

/bigtext i am bigtext hear me roar

arbitraryprint does that, but it's predefined print and you can't edit it (without editing the cmd itself).

Thanks!

-=*Raz0r*=- 09-07-2009 06:56 PM

What do you mean you can't edit it?
There's no basejka way, unless someone's built it under debug mode.
Replicate that command is the easiest thing you can do.
Not sure what you're asking, seeing as you're afraid of editing anything.. =\

Unreliable 09-07-2009 07:23 PM

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"

-=*Raz0r*=- 09-08-2009 04:01 AM

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

Code:

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
Code:

        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

Unreliable 09-08-2009 06:17 PM

Thank you!

And it's ok :3 I could have used a better example than arbitraryprint

-=*Raz0r*=- 09-12-2009 10:24 PM

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

        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.


All times are GMT -4. The time now is 05:51 PM.

Powered by vBulletin®
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
LFNetwork, LLC ©2002-2011 - All rights reserved.