In this tutorial, I will teach you how to add Muzzle Flashes, or that Fire that comes out of weapons, To your weapons.
First off, open up weapons.qc, and Right under This function:
Add this:
Next, Goto the function I posted earlier, void() W_Precache =
And Add this at the top of it.
That let's quake know you want to use them. If you don't add a precache for a model, You will get an error.
Should look like this:
http://codepad.org/y0bL1P5N
And Before we add it to a certain weapon, I just want you to know that you can add more weapons to that switch statement:
Now, Go down to any Firing function. In this tutorial, we are going to go down to W_FireShotgun
Now just add this To the top of the function or anywhere in the function:
Now a Muzzle Flash will spawn when you Fire the weapon. Add that to any function to spawn the Flash.
-Mexicouger
First off, open up weapons.qc, and Right under This function:
void() W_Precache =
Add this:
void() MuzzleFlash =
{
local entity flash;
flash = spawn();
flash.movetype = MOVETYPE_NONE;
flash.solid = SOLID_NOT; //Can't hit anything
flash.owner = self;
switch (self.weapon) //Evaluates the weapon you have and spawns the appropriate Flash
{
case IT_SHOTGUN:
setmodel (flash, "progs/flash.spr");
break;
case IT_NAILGUN:
setmodel (flash, "progs/flash2.spr");
break;
default:
setmodel (flash, "progs/flash3.spr");
}
setorigin (flash, self.origin + '0 0 16' + v_forward * 16); //Sets the flash right in front of the player
flash.think = SUB_Remove; //The flash removes itself from the world.
flash.nextthink = time + 0.1;
};
Next, Goto the function I posted earlier, void() W_Precache =
And Add this at the top of it.
precache_model ("progs/flash1.spr");
precache_model ("progs/flash2.spr");
precache_model ("progs/flash3.spr");
That let's quake know you want to use them. If you don't add a precache for a model, You will get an error.
Should look like this:
http://codepad.org/y0bL1P5N
And Before we add it to a certain weapon, I just want you to know that you can add more weapons to that switch statement:
switch (self.weapon) //Evaluates the weapon you have and spawns the appropriate Flash
{
case IT_SHOTGUN:
setmodel (flash, "progs/flash.spr");
break;
case IT_NAILGUN:
setmodel (flash, "progs/flash2.spr");
break;
case IT_SUPER_SHOTGUN: //Just add more weapons like that.
setmodel (flash, "progs/flash2.spr");
break;
default: //If the player/entity doesn't have any of the weapons above, then use this one
setmodel (flash, "progs/flash3.spr");
}
Now, Go down to any Firing function. In this tutorial, we are going to go down to W_FireShotgun
Now just add this To the top of the function or anywhere in the function:
MuzzleFlash();
Now a Muzzle Flash will spawn when you Fire the weapon. Add that to any function to spawn the Flash.
-Mexicouger