[Tutorial] CSQC Progress Bar
Moderator: InsideQC Admins
31 posts
• Page 1 of 3 • 1, 2, 3
[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:
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:
Inside this function add the lines:
That registers the command and progress bar cvar.
Now to implement our new command ("showprogress")
Scroll down until you find the function:
Inside there is a switch statement which determines what to do with client commands.
Add this case statement to that switch
Now we have to start drawing our progress bar.
Open View.QC
Find the function:
Directly above R_AddEntities Paste this code:
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:
When Drawing you must call the draw functions below
R_RenderScene(); to work.
So back inside the CSQC_UpdateView function:
Below R_RenderScene add:
Hope that helps anyone who is completely lost in CSQC.
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: Select all
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: Select all
void CSQC_Init(void)
Inside this function add the lines:
- Code: Select all
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: Select all
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: Select all
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: Select all
void CSQC_UpdateView(void)
Directly above R_AddEntities Paste this code:
- Code: Select all
// 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: Select all
// 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: Select all
if(progress == TRUE)
DrawProgress();
Hope that helps anyone who is completely lost in CSQC.
- GiffE
- Posts: 170
- Joined: Sun Oct 08, 2006 3:39 pm
- Location: USA, CT
Yeah, really, really neat, GiffE!
I'm sure lots of people would love to see more CSQC tutorials like this!
I'm sure lots of people would love to see more CSQC tutorials like this!
Neurotic Conversions - New location: Update your bookmarks!
-

CocoT - Posts: 695
- Joined: Tue Dec 14, 2004 5:39 pm
- Location: Belly-Gum
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.
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.
- GiffE
- Posts: 170
- Joined: Sun Oct 08, 2006 3:39 pm
- Location: USA, CT
Re: [Tutorial] CSQC Progress Bar
Hmm, I been putting off learning more about csqc, this looked like a good way to get back on track.
The CSQC_ConsoleCommand float in my file was merely doing: return (false) , nothing else in there, so I pasted your code above that...hope thats correct?
Next, I dont have a view.qc believe it or not in my csqcbase package. I searched for R_RenderScene in all the files, and its being called once in another file, and I located the built in definition for it. Do you mean post it below the definition or below where ite already being called?
The CSQC_ConsoleCommand float in my file was merely doing: return (false) , nothing else in there, so I pasted your code above that...hope thats correct?
Next, I dont have a view.qc believe it or not in my csqcbase package. I searched for R_RenderScene in all the files, and its being called once in another file, and I located the built in definition for it. Do you mean post it below the definition or below where ite already being called?
-

Cobalt - Posts: 445
- Joined: Wed Jun 10, 2009 2:58 am
- Location: New England, USA
Re: [Tutorial] CSQC Progress Bar
Ok, you meant post it underneath R_Renderscene(). My view.qc is actually in main.qc, that was part of the trouble.
Next, I got a compile error on the break;
client/main.qc:48: error: CSQC_ConsoleCommand: function contains illegal breaks
commented it out, but its still not liking to compile that area, says:
in function drawline_center (line 52),
client/main.qc:60: error: drawline_center: function contains illegal cases
Next, I got a compile error on the break;
client/main.qc:48: error: CSQC_ConsoleCommand: function contains illegal breaks
commented it out, but its still not liking to compile that area, says:
in function drawline_center (line 52),
client/main.qc:60: error: drawline_center: function contains illegal cases
-

Cobalt - Posts: 445
- Joined: Wed Jun 10, 2009 2:58 am
- Location: New England, USA
Re: [Tutorial] CSQC Progress Bar
that section should look like this
also take note of this.
if problem persists, update fteqcc to a recent version.
- Code: Select all
float CSQC_ConsoleCommand(string strMessage)
{
local float nReturn;
nReturn = TRUE;
// Tokenize String
tokenize(strMessage);
// Acquire Command
local string strCmd;
strCmd = argv(0);
switch(strCmd)
{
case "showprogress": // This command turns on and off the progress bar
if(progress == TRUE)
progress = FALSE;
else
progress = TRUE;
break;
default:
nReturn = FALSE;
break;
}
return nReturn;
}
also take note of this.
- Code: Select all
// CSQC_ConsoleCommand : Used to parse commands in the console that have been registered with the "registercmd" function
// Return value should be 1 if CSQC handled the command, otherwise return 0 to have the engine handle it.
if problem persists, update fteqcc to a recent version.
-

gnounc - Posts: 424
- Joined: Mon Apr 06, 2009 6:26 am
Re: [Tutorial] CSQC Progress Bar
Tried that, and had to declare those built in's, but it compiled and nwo works, thanks !
Im using csqc files that I think Nahuel put up a while ago....and I think some others have collaborated with. Theres a compass up top,
and other options. Theres also something in the readme about the intermisisons view problem, and some ssqc to fix it, however, the clients
.fixangle is not TRUE anymore, and you can mouselook during the intermission. Do we have to redeclare fixangle and intermission_running in the csqc, and apply it ?
Im using csqc files that I think Nahuel put up a while ago....and I think some others have collaborated with. Theres a compass up top,
and other options. Theres also something in the readme about the intermisisons view problem, and some ssqc to fix it, however, the clients
.fixangle is not TRUE anymore, and you can mouselook during the intermission. Do we have to redeclare fixangle and intermission_running in the csqc, and apply it ?
gnounc wrote:that section should look like this
-

Cobalt - Posts: 445
- Joined: Wed Jun 10, 2009 2:58 am
- Location: New England, USA
Re: [Tutorial] CSQC Progress Bar
Shouldn't have to, no.
I'm glad you got it working.
That csqc source you have probably came from some early version of sevens "small mod compilation".
I believe seven and nahuel both work on that.
I pilfered my csqc base from Arkages Chasm mod, who in turn pinched it from dresk.
I've updated mine considerably to reflect changes to fte's builtins.
At some point I need to test it against darkplaces and make it properly compatable, though I believe it should be
pretty much compatable as is.
I'm glad you got it working.
That csqc source you have probably came from some early version of sevens "small mod compilation".
I believe seven and nahuel both work on that.
I pilfered my csqc base from Arkages Chasm mod, who in turn pinched it from dresk.
I've updated mine considerably to reflect changes to fte's builtins.
At some point I need to test it against darkplaces and make it properly compatable, though I believe it should be
pretty much compatable as is.
-

gnounc - Posts: 424
- Joined: Mon Apr 06, 2009 6:26 am
Re: [Tutorial] CSQC Progress Bar
Ok, well mostly the defs look the same as ssqc. Still at a loss why the .fixangle is not being observed during intermission.
intermission_running is the float server side that lets us know the intermission service is running, howerver in the csqc, it seems to be phrased ' intermission '.
Not sure why thats different? Any idea how to resolve this?
intermission_running is the float server side that lets us know the intermission service is running, howerver in the csqc, it seems to be phrased ' intermission '.
Not sure why thats different? Any idea how to resolve this?
-

Cobalt - Posts: 445
- Joined: Wed Jun 10, 2009 2:58 am
- Location: New England, USA
31 posts
• Page 1 of 3 • 1, 2, 3
Who is online
Users browsing this forum: No registered users and 1 guest

