Quake 2 is another classic from id software.While not modded quite as much as it's predecessor or Q3A, it is still a blast to play and the mod's on offer are bundles of fun. Just step into Quake 2 Rocket Arena, armed with the new and almighty rocket and rail gun and you will be gibbing for hours on end.If you dig fast paced action, then load up the good ole Quake 2, fire up a mod or two and have some fun!

Post tutorial Report RSS Understanding Quake2's print functions

This small but powerful tutorial will get you started on printing messages to the client.

Posted by on - Basic Client Side Coding

[page=Introduction]
Hello! Welcome to another one of Paril's Quake2 Tutorials.

First off, I'd like to start this (and every) tutorial with this:

Down at Paril's Projects, we like to keep things simple and clean. I think that ALL modders and sourcers (engine modifiers) should heavily comment their code and keep it in seperate files, which then include in a global header file. It makes things easier and cleaner to read. Also, keep tabs and spacing easy to follow!

Anyways, let's get started on the actual prints.

[page=Print Levels]

First, you have to know the print levels...

PRINT_LOW = Near the bottom, pickup messages
PRINT_MEDIUM = Death messages
PRINT_HIGH = Stuff seen at the top of screen, important
PRINT_CHAT = Chat messages

[page=Gi.Cprintf]

gi.cprintf is probably the most customizable of them all. cprintf can send a message to anything in any situation, but you have to be careful not to send it to a non-client, or you'll get that age-old error..

**********************************
Error: cprintf to a non-client
**********************************

Anyways, cprintf is broken up into 4 parts, but can be only 3. Let's check them out. Here's an example. Make sure to check the code to make sure that whatever ent, other, targ, attacker, whatever is a client!! Let's do the most simple and obvious:

gi.cprintf (ent, PRINT_HIGH, "Welcome to my server %s!\n", ent->client->pers.netname);

It's not hard to know what's going on.

gi.cprintf (entity that must be a client, print_level (see page Print Levels), "Main Text and use \n for a new line\n, and use %s for strings and such, %n and some others can be used in different\nsituations.", used for seeing what is what or to check a variable or whatever);

A few examples..

if (ent->client->team == 1)
{
    DoSomeFunction (ent);
    gi.cprintf (ent, PRINT_HIGH, "You are team 1, %s", ent->client->pers.netname);
}

void CheckLevelName (edict_t *ent)
{
    gi.cprintf (ent, PRINT_HIGH, "The current level is %s", level.level_name);
}

[page=Gi.Centerprintf]

Centerprintf you have to be careful when using. It's hard when you use this alot since it will override the other, but it's useful for getting attention.

Use it like cprintf, but leaving out the print_level since it displays in middle

gi.centerprintf (ent, "Welcome to my server %s!", ent->client->pers.netname);

[page=bprintf]

Bprintf is used for special messages. Doesn't need to be though. It's my personal favorite!

bprinf sends the message to ALL players in server, therefore no need to worry about non-client messages.

gi.bprintf (PRINT_HIGH, "%s entered the game at %s.", ent->client->pers.netname, level.time);

[page=dprintf]

Dprintf is a debug print, only used when a/the debug cvar is 1.
It only has text and variables, therefore always high and always sent to everyone.

gi.dprintf ("%s at %s", point1, point2);

This is used for testing stuff, making sure it gets to the right spot, right code, etc...

[page=End]

Well, that's all. Get printing!

My next tutorial will include how to add new sounds, and some other goodies.

Paril
jonno.5000@gmail.com
Paril101.planetquake.gamespy.com

Post a comment

Your comment will be anonymous unless you join the community. Or sign in with your social account: