Rage through 32 single player levels and 6 deathmatch levels of sheer terror and fully immersive sound and lighting. Arm yourself against the cannibalistic Ogre, fiendish Vore and indestructible Schambler using lethal nails, fierce Thunderbolts and abominable Rocket and Grenade Launchers.

Post tutorial Report RSS Secondary Trigger in Quake

Creates a secondary trigger function on Quake's weapons system, so you can double the ways to die by weapon!

Posted by on - Intermediate Server Side Coding

Introduction
Modern First-person shooters today are utilizing the Secondary Trigger, or Alternate Fire, or Special Fire. In Quake, it's pretty HARD to do this, unless you do it my way around here ;)

Most mod's "secondary trigger" isn't really a trigger, it's more like a oneway button. Once held down that trigger, it only fires once. Because that's bound to an IMPULSE, and it ain't deep enough

Now you can have a secondary trigger without modifying the Quake engine. And at the same time, you can have a "toggle trigger" and a "pick trigger" impulse for people who prefer it that way, which makes this tutorial very neat and unique. Let's get started shall we?

The first step of coding
First, we open DEFS.QC. Get to the end of the file and paste this:

// Cheapalert - Secondary Trigger Tut
.float finger; // Trigger mode

That's the floating finger, that is really the value of which trigger to use. Now go to WEAPONS.QC. This is where we make most of the changes. Copy the entire W_Attack function and paste to make a new one. Call this function "W_Attack2". We should have a good and well duplicate of the firing function! Go to the old W_Attack function and add this at the top:

if (self.finger == 1)
{
    W_Attack2(); // use the other gun's trigger
    return;
}

This will make sure that the right finger is in the right trigger. Now we're getting somewhere, aren't we?

Selecting the trigger, in two ways
Let's make this thing be toggled. It'll require a new function to do this. But this is for people that TOGGLE firing modes (i.e. System Shock 2 players).

Paste this above W_Attack2:

void() W_MoveFinger =
{
       if (self.finger == 0)
       {
            self.finger = 1; // now put it on the other trigger
            centerprint(self,"Secondary Mode\n"); // let him know
            return;
       }
       if (self.finger == 1)
       {
            self.finger = 0; // ditto
            centerprint(self,"Primary Mode\n");
            return;
       }
};

Now it's getting obvious about what we're doing here. Now let's add the impulses. Paste this under "CheatCommand();":

if (self.impulse == 210)
                self.finger = 0; // primary trigger
        if (self.impulse == 211)
                self.finger = 1; // secondary trigger
        if (self.impulse == 212)
                W_MoveFinger(); // toggle switch

Ahh....

Now you're thinking "Where's the firing impulse?" Well today we're gonna do some aliasing.

The final steps!

I suggest that you copy the following into a new document:

// QUAKE RC begins
// load the base configuration
exec default.cfg

// load the last saved configuration
exec config.cfg

// run a user script file if present
exec autoexec.cfg

//
// stuff command line statements
//
stuffcmds

// start demos if not allready running a server
startdemos demo1 demo2 demo3

// Cheapalert - putting in the triggers
alias +primary "impulse 210;+attack"
alias -primary "-attack"
alias +secondary "impulse 211;+attack"
alias -secondary "-attack"

Save as "QUAKE.RC" into your mod's root folder. (not your source code folder)

Compile your mod and run. If you get "Unknown value "W_Attack2"" message, make a prototype at the top of Weapons.QC saying:

void() W_Attack2;

then compile.

If you like the new keys I aliased, go ahead and bind +primary as your main shoot button and +secondary as your other shoot button. Or if you're the toggle kind of guy, bind a key to impulse 212. Or if you like to use 2 keys to pick what you want, bind a key to impulse 210 and another (preferably close) to impulse 211. There. Many ways to fire a second trigger. Two times the ways to die with a weapon.

Have fun and go trigger happy!

Post a comment

Your comment will be anonymous unless you join the community. Or sign in with your social account: