Solitude (Working Title) is a PSP and PC game using a heavily modified Quake engine, expanding upon the story of Halo: Combat Evolved. Expect a great, brand new single player story and all of the most popular multiplayer modes from Halo: CE! Our team is working hard to bring the game to you as fast as possible so be sure to stay tuned for any new updates. More information can be found on our site at www.halosolitude.com. Note: We are NOT ripping anything from any of Halos! All our models and textures are our own, made by using the original Halo art only as reference.
A tutorial on how to add reloading to Quakes shotgun in qc code, and other tips to help you get started codeing for Quake.
Posted by Ark_ on Jan 14th, 2010
Basic Client Side Coding.
This is my first tutorial on programming, ok with the confession out of the way lets move on shall we.
For this tutorial I assume that you have at least a familiarity with the basic structure for how programming works, a bit of general knowledge really.
I don’t want this to be a copy, paste and your done style tutorial instead I will try to explain how and why it works so that you can code more that just reloading.
It can be good practice to think you code thought before you start to actually code it in, Programming is problem solving and the best way to solve a problem is to break it up into small steps and that’s what we will do here.
Main Goal: add reloading to Quakes shot gun.
As an example lets say we have 50 shells in our inventory for the shot gun.
The clip can hold 12.
The player shoots 5 shells and then reloads.
What we want is for each shot to take 1 shell from the clip.
So after those 5 shots are taken away from the clip (12-5=7) we have 7 shells left in the clip.
Now we only want take away the shots fired from our inventory (50) so to do this we need to know how many shots the player fired, now there are two ways to do this.
I prefer the latter method and that’s what we will be using in this tutorial.
Ok so lets start with the code shall we, I will explain more as we go along.
Note in this code “pistol_clip” will be the shotguns clip(due to convience for me as I was using it as such). First off we will need to make a place to store the amount of shots in the clip, “pistolclip in this case. The best place to do this is in the file “Defs.qc” this is where most of quakes variables are declared.
It is important to not that QC has a build order, think of all those .qc files as being just one pasted in the order according to the “progs.src” file. So the .qc file listed first would be before any thing else in the qc code. This is important because in QC functions can only know what is above them but not below, this is way defs.qc is near the to, so that the rest of the code can read these values.
Ok back on topic lets add our variable that will hold the shell in our clip.
Open up the file “Defs.qc” and scroll to the bottom of the file and add the following lines of code.
Now what this does is set up a place for us to store the clips vaule. The “.” Means that it can be assigned to an entity like the player and the float means that it’s a number.
Now we need to change some of the “W_FireShotgun” (you can do a search by holding ctrl and pressing F in most code editors)
Replace this line:
With this line:
The comment should explain whats happening there.
Next we will add the check so that the shotgun will only shoot when it has ammo and also a check that if the clip is empty to automatically reload.
Still in “Weapons.qc” go to the function “W_Attack” and replace this:
Now lets make the reload function mentioned above.
Go to the top of the “Weapons.qc” file and copy the following in there.
The comments should explain it well enough.
Now its all well and good the shot gun will now fire 12 shots and then reload automaticly ( with a four second pause) but what if you want to be able to reload at any time. Read on as this is very easy.
Still in “Weapons.qc” go to the “Impulsecommands” function, this is where the impulses are set up (where you type impulse (number) in to quakes console) and it is here where we will make our own for reloading.
Put the next block of code after:
Then code to put after the above:
All that code does is if impulse 16 was typed in to the console run the function called “reload”.
You can bind that impulse to a key with the console command: bind(th key here) “impulse 16” Then save that to your configs.
Now you should have a shot gun with a clip that reloads when the clip is empty or you type impulse 16. The limit at the moment is that the gun doesn’t animate when reloading, I may address this in a later tutorial or add on to this one.
Now try adding reloading to the other weapons in quake with different clip sizes or even try one of you ideas that you are bound to have, I hope that this tutorial has given you a nice introduction to qc and that you have picked up some of the ins and outs of the language.
If you want to try one of those ideas you are bound to have had, remember to break it up into steps, the odd are that some of IDs code does something similar to one or more of those steps so you will often find yourself repurposing some of the existing code to suit your needs.
Please leave a comment if you found this tutorial useful, thanks.