View previous topic :: View next topic |
Author |
Message |
GiffE
Joined: 08 Oct 2006 Posts: 141 Location: USA, CT
|
Posted: Sun Mar 02, 2008 3:00 pm Post subject: [Tutorial] CSQC Progress Bar |
|
|
People requested CSQC Tutorials, I was working on this and figured I'd make a tutorial out of it since CSQC Tutorials are hard to come accross.
It makes a Counter-strike style Progress bar which is controllable via client cvar and command.
NOTE: I based my coded off of the csqc scratch files in this forum and it works with DP (not tested in FTE)
By the end of this tutorial you should be able to:
-Draw and Fill shapes onto the screen
-Register and use CVARs and CMDs for use in CSQC
Lets get started:
First thing we need to do is a few declare a few things.
Open up Defs.QC
Paste these at the very bottom:
Code: | float vid_conwidth, vid_conheight;
float progress; |
progress is a boolean variable whether or not to draw, and the others are used to center the drawing on your screen.
Now we have to setup our cvar and showprogress command.
Open Main.QC
Find the function:
Code: | void CSQC_Init(void) |
Inside this function add the lines:
Code: | progress = FALSE; // By default we want our progress bar to not be on
registercmd("showprogress"); // This command turns on and off the progress bar
registercvar("c_progressbar","0"); // This cvar is the percent of the progress bar you would like to be filled |
That registers the command and progress bar cvar.
Now to implement our new command ("showprogress")
Scroll down until you find the function:
Code: | float CSQC_ConsoleCommand(string strMessage) |
Inside there is a switch statement which determines what to do with client commands.
Add this case statement to that switch
Code: | case "showprogress": // This command turns on and off the progress bar
if(progress == TRUE)
progress = FALSE;
else
progress = TRUE;
break; |
Now we have to start drawing our progress bar.
Open View.QC
Find the function:
Code: | void CSQC_UpdateView(void) |
Directly above R_AddEntities Paste this code:
Code: | // Set the console size vars
vid_conwidth = cvar("vid_conwidth");
vid_conheight = cvar("vid_conheight"); |
Its time to add our draw functions now, I commented this so you should be able to understand whats going on.
First it draws an empty box (using 4 lines)
Then It takes the value from the cvar and makes a fill proportional to our progress bar and draws it in.
Now at the very top of the file (view.qc)
Add this code:
Code: | // Just put this function together to make drawing the empty box easier, you could use drawline and go around the points but
// I found having the
void drawline_center(vector center_ofs, vector linesize, vector do_rgb, float do_alpha, float do_flags)
{
local vector barpos;
barpos_x = vid_conwidth;
barpos_y = vid_conheight;
barpos = barpos*0.5 + center_ofs;
drawfill(barpos, linesize, do_rgb, do_alpha, do_flags);
}
// This function draws an empty
void DrawProgressEmpty(void)
{
drawline_center(' -200 -2 0 ', '400 1 0', '1 0.91 0.51', 0.7, 0); // Top
drawline_center(' -200 -2 0 ', '1 9.5 0', '1 0.91 0.51', 0.7, 0); // Left
drawline_center(' -200 7 0 ', '400 0.5 0', '1 0.91 0.51', 0.7, 0); // Bottom
drawline_center(' 200 -2 0 ', '1 9.5 0', '1 0.91 0.51', 0.7, 0); // Right
}
// This Draws the progress bar
void DrawProgress(void)
{
local vector barpos, fillsize;
local float progrs;
progrs = cvar("c_progressbar"); // Get the progress
DrawProgressEmpty(); // Draw an empty box
fillsize_x = (progrs*396) / 100; // This finds the correct % of our fill
fillsize_y = 6; // Give it a hieght of 6
barpos_x = vid_conwidth;
barpos_y = vid_conheight;
barpos = barpos*0.5 - '198 0.25 0'; // center the progress bar on the screen
//Draw the bar
drawfill(barpos, fillsize, '1 0.91 0.51', 0.7, 0); // The Fill //'396 6 0'
} |
When Drawing you must call the draw functions below
R_RenderScene(); to work.
So back inside the CSQC_UpdateView function:
Below R_RenderScene add:
Code: |
if(progress == TRUE)
DrawProgress();
|
Hope that helps anyone who is completely lost in CSQC. |
|
Back to top |
|
 |
RenegadeC

Joined: 15 Oct 2004 Posts: 370 Location: The freezing hell; Canada
|
Posted: Mon Mar 03, 2008 2:25 am Post subject: |
|
|
Very awesome, this could come in handy. Thanks! |
|
Back to top |
|
 |
CocoT

Joined: 14 Dec 2004 Posts: 599 Location: Belly-Gum
|
Posted: Mon Mar 03, 2008 4:58 am Post subject: |
|
|
Yeah, really, really neat, GiffE!
I'm sure lots of people would love to see more CSQC tutorials like this! _________________ http://www.planetcocot.net/ |
|
Back to top |
|
 |
GiffE
Joined: 08 Oct 2006 Posts: 141 Location: USA, CT
|
Posted: Tue Mar 04, 2008 12:13 am Post subject: |
|
|
Thanks!
It is something v. simple but that could be useful I suppose
CSQC is really no different than standard qc just needs a little thinking to figure out how it works. Word just needs to get out about it.
Sorry about not using the "Submit Tutorial" I didn't really notice that or have it all typed outside of the post. Its also embarrassingly badly formatted and figured its not up to par with the tutorials page.
I'll do some more CSQC tut's if anyone has any suggestions. If not I'm gonna work on a scripted HUD system. |
|
Back to top |
|
 |
Stealth Kill
Joined: 29 Dec 2006 Posts: 83
|
Posted: Wed Mar 05, 2008 7:39 pm Post subject: |
|
|
Can I use this with QC?
i donīt know what CSQC is  |
|
Back to top |
|
 |
leileilol

Joined: 15 Oct 2004 Posts: 1321
|
Posted: Wed Mar 05, 2008 7:40 pm Post subject: |
|
|
CSQC stands for Counter-Strike QuakeC as you can clearly see this is the bomb defusing bar _________________
 |
|
Back to top |
|
 |
RenegadeC

Joined: 15 Oct 2004 Posts: 370 Location: The freezing hell; Canada
|
Posted: Wed Mar 05, 2008 9:10 pm Post subject: |
|
|
leileilol wrote: | CSQC stands for Counter-Strike QuakeC as you can clearly see this is the bomb defusing bar |
 |
|
Back to top |
|
 |
Urre

Joined: 05 Nov 2004 Posts: 1073 Location: Sweden
|
Posted: Thu Mar 06, 2008 7:56 am Post subject: |
|
|
Funny  _________________ Look out for Twigboy |
|
Back to top |
|
 |
ceriux

Joined: 06 Sep 2008 Posts: 969 Location: Florida, USA
|
|
Back to top |
|
 |
|