Haste Powerup
Created By: Marius
eMail: lordshoel@yahoo.com
Difficulty Scale: Easy


This tutorial will show anyone how to make the Haste Power-Up for their mods. Haste will affect your movement speed and weapon fire rate. We'll replace that terrible waste of an item the Biosuit with our Haste. Download haste.zip and unzip the model file - Haste.mdl into your progs folder for this mod. After you've done that lets get started by just following the easy steps that follow...

Step 1.

First open up Defs.qc and scroll to the very bottom, once there paste the following variables:

//Haste Floats
.float		haste_time;
.float		haste_finished;
Save then close Defs.qc.

Step 2.

Open up Items.qc, scroll down to the functions for the powerups. Above item_artifact_invulnerability paste the following function:

void() item_haste =
{
	self.touch = powerup_touch;

	precache_model ("progs/haste.mdl");
	precache_sound ("items/damage3.wav");
	self.noise = "items/damage3.wav";
	setmodel (self, "progs/haste.mdl");
	self.netname = "Haste";
	setsize (self, '-16 -16 -24', '16 16 32');
	StartItem ();
};
Now find the function Item_Artifact_Envirosuit and replace it with the below code:

void() item_artifact_envirosuit =
{
	self.classname = "item_haste";
	item_haste();
	return;
};
Once thats done scroll up to Powerup_Touch and find the following within that function:

	if (self.classname == "item_artifact_envirosuit")
	{
		other.rad_time = 1;
		other.radsuit_finished = time + 30;
	}
Replace that segment only with the following:

	if (self.classname == "item_haste")
	{
		other.haste_time = 1;
		other.haste_finished = time + 30;
	}	
Save Items.qc and then close it. Continue on to Step 3.

Step 3.

Open up Client.qc and find PutClientInServer. Above W_SetCurrentAmmo(); paste what follows:

	self.haste_time = 0;
	self.haste_finished = 0;
Save then find the function CheckPowerups. Within that function at the end add what follows:

// Haste Power-Up	
	if (self.haste_finished)
	{
		if (self.haste_finished < time + 3)
		{
			if (self.haste_time == 1)
			{
				sprint (self, "Haste Powerup Wearing Off...\n");
				stuffcmd (self, "bf\n");
				sound (self, CHAN_AUTO, "items/damage3.wav", 1, ATTN_NORM);
				self.haste_time = time + 1;
			}
			
			if (self.haste_time < time)
			{
				self.haste_time = time + 1;
				stuffcmd (self, "bf\n");
			}
		}

		if (self.haste_finished < time)
		{	// just stopped
			self.haste_time = 0;
			self.haste_finished = 0;
		}
		if (self.haste_finished > time)
			self.effects = self.effects | EF_DIMLIGHT;
		else
			self.effects = self.effects - (self.effects & EF_DIMLIGHT);
	}	
Ok now save Client.qc then scroll a little further down to PlayerPostThink. At the end after CheckPowerups add the line:

	Set_Speed();
Save then close.

Step 4.

Open up Weapons.qc and find the function ImpulseCommands add the code below:

/*
============
Set Speed
Sets speed of Player for Haste
============
*/
void() Set_Speed =
{
      local string daspeed;
      local float deespeed, basicspd;

	if (self.haste_finished > time) basicspd = 500;
	else basicspd = 340;

      deespeed = basicspd/2;
      daspeed = ftos(deespeed);
      stuffcmd(self, "cl_forwardspeed ");
      stuffcmd(self, daspeed);
      stuffcmd(self, "\n");
      stuffcmd(self, "cl_sidespeed ");
      stuffcmd(self, daspeed);
      stuffcmd(self, "\n");
      stuffcmd(self, "cl_backspeed ");
      stuffcmd(self, daspeed);
      stuffcmd(self, "\n");
};
Save then follow Step 5.

Step 5.

Still in Weapons.qc, find and replace the function W_attack with the function below: Note this is the standard W_attack Function previously unmodified.

void() W_Attack =
{
	local	float	r;

	if (!W_CheckNoAmmo ())
		return;

	makevectors	(self.v_angle);			// calculate forward angle for velocity
	self.show_hostile = time + 1;	// wake monsters up

	if (self.weapon == IT_AXE)
	{
		sound (self, CHAN_WEAPON, "weapons/ax1.wav", 1, ATTN_NORM);
		r = random();
		if (r < 0.25)
			player_axe1 ();
		else if (r<0.5)
			player_axeb1 ();
		else if (r<0.75)
			player_axec1 ();
		else
			player_axed1 ();

		if (self.haste_finished > time) self.attack_finished = time + 0.25;
		else self.attack_finished = time + 0.5;
	}
	else if (self.weapon == IT_SHOTGUN)
	{
		player_shot1 ();
		W_FireShotgun ();
		if (self.haste_finished > time) self.attack_finished = time + 0.25;
		else self.attack_finished = time + 0.5;
	}
	else if (self.weapon == IT_SUPER_SHOTGUN)
	{
		player_shot1 ();
		W_FireSuperShotgun ();
		if (self.haste_finished > time) self.attack_finished = time + 0.35;
		else self.attack_finished = time + 0.7;
	}
	else if (self.weapon == IT_NAILGUN)
	{
		player_nail1 ();
	}
	else if (self.weapon == IT_SUPER_NAILGUN)
	{
		player_nail1 ();
	}
	else if (self.weapon == IT_GRENADE_LAUNCHER)
	{
		player_rocket1();
		W_FireGrenade();
		if (self.haste_finished > time) self.attack_finished = time + 0.3;
		else self.attack_finished = time + 0.6;
	}
	else if (self.weapon == IT_ROCKET_LAUNCHER)
	{
		player_rocket1();
		W_FireRocket();
		if (self.haste_finished > time) self.attack_finished = time + 0.4;
		else self.attack_finished = time + 0.8;
	}
	else if (self.weapon == IT_LIGHTNING)
	{
		player_light1();
		if (self.haste_finished > time) self.attack_finished = time + 0.07;
		else self.attack_finished = time + 0.1;
		sound (self, CHAN_AUTO, "weapons/lstart.wav", 1, ATTN_NORM);
	}
};
Now save and open up Player.qc then find Player_Nail1 and Player_Nail2 functions. Then both with the below code:

void() player_nail1   =[$nailatt1, player_nail2  ] 
{
	self.effects = self.effects | EF_MUZZLEFLASH;

	if (!self.button0) {player_run ();return;}
	self.weaponframe = self.weaponframe + 1;
	if (self.weaponframe == 9) self.weaponframe = 1;
	SuperDamageSound();
	W_FireSpikes (4);
	if (self.haste_finished > time) self.attack_finished = time + 0.01;
	else self.attack_finished = time + 0.2;
};
void() player_nail2   =[$nailatt2, player_nail1  ]
{
	self.effects = self.effects | EF_MUZZLEFLASH;

	if (!self.button0) {player_run ();return;}
	self.weaponframe = self.weaponframe + 1;
	if (self.weaponframe == 9)self.weaponframe = 1;
	SuperDamageSound();
	W_FireSpikes (-4);
	if (self.haste_finished > time) self.attack_finished = time + 0.1;
	else self.attack_finished = time + 0.2;
};
Now thats it (I Hope). Save then cloase Player.qc

Step 6.

So ther you go. The Haste Power Up is quite cool. It increases the speed of your movement from 340 to 500 and halfs the attack time of all weapons. Now that wasn't too hard was it? Save everything and then Compile. Have fun gaming...
Marius