Forum

[Tutorial] CSQC Progress Bar

Discuss CSQC related programming.

Moderator: InsideQC Admins

[Tutorial] CSQC Progress Bar

Postby GiffE » Sun Mar 02, 2008 3:00 pm

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.

Image

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

Postby RenegadeC » Mon Mar 03, 2008 2:25 am

Very awesome, this could come in handy. Thanks!
User avatar
RenegadeC
 
Posts: 391
Joined: Fri Oct 15, 2004 10:19 pm
Location: The freezing hell; Canada

Postby CocoT » Mon Mar 03, 2008 4:58 am

Yeah, really, really neat, GiffE!
I'm sure lots of people would love to see more CSQC tutorials like this!
Neurotic Conversions - New location: Update your bookmarks!
User avatar
CocoT
 
Posts: 695
Joined: Tue Dec 14, 2004 5:39 pm
Location: Belly-Gum

Postby GiffE » Tue Mar 04, 2008 12:13 am

Thanks!
It is something v. simple but that could be useful I suppose :D
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

Postby Stealth Kill » Wed Mar 05, 2008 7:39 pm

Can I use this with QC?

i don´t know what CSQC is :oops:
Stealth Kill
 
Posts: 83
Joined: Fri Dec 29, 2006 12:34 pm

Postby leileilol » Wed Mar 05, 2008 7:40 pm

CSQC stands for Counter-Strike QuakeC as you can clearly see this is the bomb defusing bar
i should not be here
leileilol
 
Posts: 2783
Joined: Fri Oct 15, 2004 3:23 am

Postby RenegadeC » Wed Mar 05, 2008 9:10 pm

leileilol wrote:CSQC stands for Counter-Strike QuakeC as you can clearly see this is the bomb defusing bar


:lol:
User avatar
RenegadeC
 
Posts: 391
Joined: Fri Oct 15, 2004 10:19 pm
Location: The freezing hell; Canada

Postby Urre » Thu Mar 06, 2008 7:56 am

Funny :)
I was once a Quake modder
User avatar
Urre
 
Posts: 1109
Joined: Fri Nov 05, 2004 2:36 am
Location: Moon

Postby ceriux » Tue Mar 17, 2009 4:53 am

i think posts like this should be stickyed.
User avatar
ceriux
 
Posts: 2223
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Re: [Tutorial] CSQC Progress Bar

Postby Cobalt » Thu Jan 23, 2014 3:37 am

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?
User avatar
Cobalt
 
Posts: 445
Joined: Wed Jun 10, 2009 2:58 am
Location: New England, USA

Re: [Tutorial] CSQC Progress Bar

Postby Cobalt » Thu Jan 23, 2014 4:15 am

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
User avatar
Cobalt
 
Posts: 445
Joined: Wed Jun 10, 2009 2:58 am
Location: New England, USA

Re: [Tutorial] CSQC Progress Bar

Postby gnounc » Thu Jan 23, 2014 7:24 am

that section should look like this

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.
User avatar
gnounc
 
Posts: 424
Joined: Mon Apr 06, 2009 6:26 am

Re: [Tutorial] CSQC Progress Bar

Postby Cobalt » Thu Jan 23, 2014 6:42 pm

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 ?



gnounc wrote:that section should look like this
User avatar
Cobalt
 
Posts: 445
Joined: Wed Jun 10, 2009 2:58 am
Location: New England, USA

Re: [Tutorial] CSQC Progress Bar

Postby gnounc » Thu Jan 23, 2014 9:09 pm

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.
User avatar
gnounc
 
Posts: 424
Joined: Mon Apr 06, 2009 6:26 am

Re: [Tutorial] CSQC Progress Bar

Postby Cobalt » Fri Jan 24, 2014 2:31 am

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?
User avatar
Cobalt
 
Posts: 445
Joined: Wed Jun 10, 2009 2:58 am
Location: New England, USA

Next

Return to CSQC Programming

Who is online

Users browsing this forum: No registered users and 1 guest