.qc (dot qc) - the group for quake c coders of all denominations. If you make quake one mods and write code in quake c, join our group! I'll try to answer any quake c questions - please post your inquiry in the forums...

Forum Thread
  Posts  
Print and formatting (Groups : qc : Forum : vault() : Print and formatting) Locked
Thread Options
numbersix
numbersix quake-c coder++
Jan 13 2014 Anchor

Display of data in the console is mostly a developer concern.
You dont want players to rely on hastily scrolling data for game play - that is why there is centerprint and HUD.
To update the HUD you need a client side qc enabled engine like darkplaces.
(note: client side qc "draws" most HUD data, but you will still have to convert numerics to string with ftos / vtos...)

With quake, you can not, however, use a formatted printf type statement.
Quake c only handles string data in a print:


// defs.qc

// when client is specified, only that client will get the message
// printed center screen for client - this print does not scroll with console and will expire in cvar "scr_centertime" seconds
void(entity client, string s) centerprint = #73;

// tricky coder!
// note - the same centerprint, but with multiple string arguments
// the engine takes all the strings and centerprints them together
// you can have more centerprints with more string arguments, up to the max for a function
void(entity client, string s, string s1) centerprint2 = #73;
void(entity client, string s, string s1, string s2) centerprint3 = #73;

// print to console
void(entity client, string s) sprint = #24;

// print to every console for all connected clients and server
void (string s) bprint = #23;
// developer print - only display when cvar "developer" is 1
void (string s) dprint = #25;

// to display float / integer data you need "float to string"
// note: you can NOT format integer or float - if there is any non integer data it will display after a decimal point: 3.14159265
string (float f) ftos = #26;

// to display vector data you need "vector to string" - vectors are float / integer data as well
string (vector v) vtos = #27;


Here is how to display some numerical data:

// code samples

// bprint to console (this example could be used in ammo_touch of items.qc)
bprint(" *** warning: ");
bprint(ftos(other.ammo_cells));
bprint(" count cells now in player inventory");

// finish with a new line so the next print doesnt just tag it on to our recent print
bprint("\n");

You can have complex print data - you have to put it together ONE printed string at a time!
A few numeric functions are available to aid you: fabs(), rint(), floor(), ceil()
(fabs = floating absolute, any c reference will identify the rest.)

// comes with the flame thrower add in with my mods
// note: centerprint does not need "\n" unless you have multiple lines to print
// if you centerprint multiple lines with "\n", they will NOT block format unless you pad all to the same length with spaces
// to print a ftos / vtos number or multiple strings, you MUST use the multi-string centerprint[N]
// the next centerprint will wipe out the previous, they are not "added" together
centerprint(other,"You are on fire! Find water!");

// multi string example with numeric data
centerprint3(other,"You have ",ftos(5)," buckets");

Now you can notify players of danger and be apprised of game state changes while you are coding your mod.


Quake C manual ver 3.4 entries:

8.9 Print messages

Function: bprint

void bprint (string text)
text = text of the message

Broadcast a message to all players on the current server.

Function: centerprint

void centerprint( entity client, string text)
client = player that is to receive the message
text = text of the message

Sends a message to a specific player, and print it centered.

Function: sprint

void sprint (entity client, string text)
client = player that is to receive the message
text = text of the message

Sends a message to a player.

Edited by: numbersix

Reply to thread
click to sign in and post

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.