MAGSEC4 - Secondary Function
Created By: Marius
eMail: lordshoel@yahoo.com
Difficulty Scale: Easy


This tutorial is a follow-up to the first MagSec4 Tutorial. This time we will add a button to change to a Secondary Mode of fire. In this case the Seconadry Mode will work only on the MagSec4, however it can be done to may other weapons quite easily. Note to complete this tutorial you must\ have already completed the original Magsec4 tutorial.

Step 1.

Open up Defs.qc and at the very bottom paste the following variables:

	//Magsec4 Floats
	.float	MAGSEC_MODE;
	float		PRIMARY	= 1;
	float 	SECONDARY	= 2;
Explanation:
The first varible is the container for the mode.
The next two variables are the modes: PRIMARY/SECONDARY.

Step 2.

Once you've created the above variables open up Weapons.qc and scroll down to function ImpulseCommands. Then above QuadCheat paste the code block below:

if (self.impulse == 15)		
{
	if (self.weapon == IT_NAILGUN)
	{
		if (self.MAGSEC_MODE == PRIMARY) 
		{ 
			self.MAGSEC_MODE = SECONDARY; 
			centerprint (self, "Secondary Mode of Fire\n\n Three Round Burst");
		}
		else if (self.MAGSEC_MODE == SECONDARY) 
		{ 
			self.MAGSEC_MODE = PRIMARY; 
			centerprint (self, "Primary Mode of Fire\n\n Single Shot");
		}
	}
}

Step 3.

Now find the W_Attack function then find the following section:

	else if (self.weapon == IT_NAILGUN)
	{
		player_shot1 ();
		W_FireMagsec ();
		self.attack_finished = time + 0.25;
	}
Replace the above with what follows:

	else if (self.weapon == IT_NAILGUN)
	{
		player_shot1 ();
		if (self.MAGSEC_MODE == PRIMARY) 
		{ 
			W_FireMagsec ();
			self.attack_finished = time + 0.25;
		}
		else if (self.MAGSEC_MODE == SECONDARY) 
		{
			if (self.ammo_nails < 3) return;	//If less than three nails don't fire
			W_FireMagsecBurst ();
			self.attack_finished = time + 0.6;
		}
	}

Step 4.

Once finished the above step save then open up Client.qc and find PutClientInServer function. In that function find W_SetCurrentAmmo and above that put:

	self.MAGSEC_MODE = PRIMARY;
This sets the mode to Primary on spawning.

Step 5.

Save Client.qc and open Magsec4.qc. Scroll to the end and paste the following after W_FireMagsec:

void() W_FireMagsecBurst =
{
	local vector	dir, org1, org2, org3, case;
	local entity	old;
	
	makevectors(self.v_angle);
	case = aim (self,10000);

	if (self.ammo_nails < 3) return;	//If less than three nails don't fire
	self.currentammo = self.ammo_nails = self.ammo_nails - 3;

	sound (self, CHAN_WEAPON, "weapons/spike2.wav", 1, ATTN_NORM);

	//Origin For Bullet No. 1
	if (random() < 0.1) org1 = self.origin + '0 0 20'+(v_right * -2);
	else if (random() < 0.2) org1 = self.origin + '0 0 16'+(v_right * 3);
	else if (random() < 0.3) org1 = self.origin + '0 0 12'+(v_right * -1);
	else if (random() < 0.4) org1 = self.origin + '0 0 16'+(v_right * 1);
	else if (random() < 0.5) org1 = self.origin + '0 0 18'+(v_right * -4);
	else if (random() < 0.6) org1 = self.origin + '0 0 14'+(v_right * 4);
	else if (random() < 0.7) org1 = self.origin + '0 0 13'+(v_right * -3);
	else if (random() < 0.8) org1 = self.origin + '0 0 17'+(v_right * 2);
	else if (random() < 0.9) org1 = self.origin + '0 0 20'+(v_right * 1);
	else org1 = self.origin + '0 0 16';

	//Origin For Bullet No. 2
	if (random() < 0.1) org2 = self.origin + '0 0 20'+(v_right * -2);
	else if (random() < 0.2) org2 = self.origin + '0 0 16'+(v_right * 3);
	else if (random() < 0.3) org2 = self.origin + '0 0 12'+(v_right * -1);
	else if (random() < 0.4) org2 = self.origin + '0 0 16'+(v_right * 1);
	else if (random() < 0.5) org2 = self.origin + '0 0 18'+(v_right * -4);
	else if (random() < 0.6) org2 = self.origin + '0 0 14'+(v_right * 4);
	else if (random() < 0.7) org2 = self.origin + '0 0 13'+(v_right * -3);
	else if (random() < 0.8) org2 = self.origin + '0 0 17'+(v_right * 2);
	else if (random() < 0.9) org2 = self.origin + '0 0 20'+(v_right * 1);
	else org2 = self.origin + '0 0 16';

	//Origin For Bullet No. 3
	if (random() < 0.1) org3 = self.origin + '0 0 20'+(v_right * -2);
	else if (random() < 0.2) org3 = self.origin + '0 0 16'+(v_right * 3);
	else if (random() < 0.3) org3 = self.origin + '0 0 12'+(v_right * -1);
	else if (random() < 0.4) org3 = self.origin + '0 0 16'+(v_right * 1);
	else if (random() < 0.5) org3 = self.origin + '0 0 18'+(v_right * -4);
	else if (random() < 0.6) org3 = self.origin + '0 0 14'+(v_right * 4);
	else if (random() < 0.7) org3 = self.origin + '0 0 13'+(v_right * -3);
	else if (random() < 0.8) org3 = self.origin + '0 0 17'+(v_right * 2);
	else if (random() < 0.9) org3 = self.origin + '0 0 20'+(v_right * 1);
	else org3 = self.origin + '0 0 16';

	LaunchProjectile(org1); //Fire Bullet No. 1
	eject_case (((self.origin + (v_forward * 12)) + (v_up * 13)),case);
	LaunchProjectile(org2); //Fire Bullet No. 2
	eject_case (((self.origin + (v_forward * 12)) + (v_up * 13)),case);
	LaunchProjectile(org3); //Fire Bullet No. 3
	eject_case (((self.origin + (v_forward * 12)) + (v_up * 13)),case);

	self.punchangle_x = -2;
};

Step 6.

That should be it. What you've done is create an impulse to allow the switching of Firing Modes, created a function for the Secondary Mode and made it so when spawning the mode reverts to normal. Once compiled go ahead and have fun with a gun of two modes. Marius