Forum

[Tutorial PSP/PC] - Adding a nohud Cvar.

Post tutorials on how to do certain tasks within game or engine code here.

Moderator: InsideQC Admins

[Tutorial PSP/PC] - Adding a nohud Cvar.

Postby Team Xlink » Fri Jan 14, 2011 10:59 pm

It has been a while since I've made a tutorial, the effect of this one is simple, but it shows how to setup cvars, and what the return command does.

The code for this is my own, I implemented it in a different engine, thus it may require changes for stock Quake, but hey you never know. ;)

Somewhere near the top of cl_main.c, where the other cvar_t lines are add this line of code:

Code: Select all
cvar_t  nohud = {"nohud", "0"}; //TeamXlink - nohud cvar



Now in CL_init add this along with all of the other cvar register lines:

Code: Select all
Cvar_RegisterVariable (&nohud);  //TeamXlink - nohud cvar



This is where it starts to get engine specific.

If your using the PSP open video_hardware_draw.cpp if your using another engine open the equivalent file, it may be gl_draw.c if I'm not mistaken.


Go to Draw_Crosshair.

And before this line:

Code: Select all
if (crosshair.value >= 2)


Add this:

Code: Select all
//TeamXlink - nohud cvar start
if ( nohud.value )
return;
//TeamXlink - nohud cvar end


Now that was just a simple if statement, it used our cvar as the starting value, and used the .value as the line on the other side of the operator, if nohud is equal to anything except 0 it goes to the next line.

This line simply makes it not continue and return back.

Now, that was for the crosshair, this next part is for the actual hud.

Open sbar.c and near the top add this line:

Code: Select all
extern  cvar_t  nohud; //TeamXlink - nohud cvar


This line tells the compiler that our cbar "nohud" is defined externally in another file.


Now find the Sbar_Draw function, and near the top add this:

Code: Select all
//TeamXlink - nohud cvar start
if ( nohud.value )
return;
//TeamXlink - nohud cvar end


That code acted just like the code we used before for the crosshair.

That is all.

This code I wrote for this tutorial was written a long time ago, and it probably has some improvements that could and should be made.

As usual post questions, comments, concerns, hate mail etc, at the bottom of this post.

Thank you.

Credits:

TeamXlink
Team Xlink
 
Posts: 368
Joined: Thu Jun 25, 2009 4:45 am
Location: Michigan

Postby Mexicouger » Sat Jan 15, 2011 5:43 am

This may help PSP modders other than me and Jukki :)

I look forward to your tutorials. I added the same Cvar into my engine, except made it Hide_Hud.
User avatar
Mexicouger
 
Posts: 514
Joined: Sat May 01, 2010 10:12 pm


Return to Programming Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest