Post tutorial RSS [QC] [Tutorial] Displaying another players Name

How to print a players name that you are looking at in QuakeC

Posted by on - Basic Client Side Coding

This tutorial will enable you to display another players name directly on the screen if you are looking at him/her/it.
First off, open up defs.qc, and scroll all the way to the bottom, and add this:

float display_time;


Save and close. Now open up client.qc and scroll down to the function Player_Pre_Think

Right above that function, Add this:

void() Display_Name =
{
local vector src, dir;
dir = aim (self, 1000); //make sure it is coming out face forward

makevectors(self.v_angle); //And it is in the players view

src = self.origin + v_forward*10;
src_z = self.absmin_z + self.size_z * 0.7;

traceline (src, src + dir*1000, FALSE, self); //Send out a line
puff_org = trace_endpos - dir*4;

if (trace_ent.takedamage) //return what the line hit. (something that has health, obviously)
{
if (trace_ent.classname == "player") //Make sure it is a player you are targeting
centerprint (self, trace_ent.netname);
}
display_time = time + 0.2; //Update time.
};


Now go down to Player_Pre_Think, And right after this piece:

if (self.deadflag >= DEAD_DEAD)
{
PlayerDeathThink ();
return;
}
if (self.deadflag == DEAD_DYING)
return; // dying, so do nothing


Add this:

if (self.ishuman == TRUE) //Check is only necesary if you have bots. It saves memory so that bots //dont do it
if (display_time < time)
Display_Name();


And that is it! Go look at a bot or player, And It will tell you who that guy is. [Tut Fixed]

Comments
VodkaEagle
VodkaEagle

Why don't you just enable this for the main game instead make us do it?

Reply Good karma Bad karma-1 votes
f34rthereaper
f34rthereaper

-_-
this is just a tutorial on HOW to do it if u wanna make a game urself

Reply Good karma Bad karma+3 votes
TCPixel Author
TCPixel

Hahahahahahah... Nub

Reply Good karma+4 votes
VodkaEagle
VodkaEagle

Oh. Well, neat. Your game looks epic. Make the orange color of the hits a bit more red.

Reply Good karma Bad karma+1 vote
joealtair
joealtair

does anyone have an image of this so i can see what it looks like

Reply Good karma Bad karma+1 vote
Post a comment
Sign in or join with:

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.