2x Laser
Author: Mr. PinkSource: https://www.insideqc.com/qctut/qctut-4.shtml
Step 1
First, you need to open defs.qc and go until line 403, write under: entity newmis; this:
entity newmis;
entity newmis2; // to add a new entity
Step 2
Then, you'll need to go to the top of your weapons.qc file and find the W_PreCache function. Just add
the lines inside the heading.
void() W_Precache =
{
precache_sound ("weapons/r_exp3.wav"); // new rocket explosion
precache_sound ("weapons/rocket1i.wav"); // spike gun
precache_sound ("weapons/sgun1.wav");
precache_sound ("weapons/guncock.wav"); // player shotgun
precache_sound ("weapons/ric1.wav"); // ricochet (used in c code)
precache_sound ("weapons/ric2.wav"); // ricochet (used in c code)
precache_sound ("weapons/ric3.wav"); // ricochet (used in c code)
precache_sound ("weapons/spike2.wav"); // super spikes
precache_sound ("weapons/tink1.wav"); // spikes tink (used in c code)
precache_sound ("weapons/grenade.wav"); // grenade launcher
precache_sound ("weapons/bounce.wav"); // grenade bounce
precache_sound ("weapons/shotgn2.wav"); // super shotgun
// Add the code in blue
precache_sound ("enforcer/enfstop.wav"); // laser shot
precache_sound ("enforcer/enfire.wav"); // laser sizzle
precache_model ("progs/laser.mdl"); // laser model
// End of additional code
};
Step 3
Third, open up your weapons.qc file and find the W_FireSuperShotgun function. Put the
following code directly above it.
void() LaserHit =
{
local vector org;
if (other == self.owner)
return; // don't explode on owner
if (pointcontents(self.origin) == CONTENT_SKY)
{
remove(self);
return;
}
//Sizzle noise that you hear when the enforcer's laser contacts
sound (self, CHAN_WEAPON, "enforcer/enfstop.wav", 1, ATTN_STATIC);
org = self.origin - 8*normalize(self.velocity);
if (other.health)
{
SpawnBlood (org, self.velocity*0.2, 40);
T_Damage (other, self, self.owner, 60);
// You can change the amount of damage it does
}
else
{
WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
WriteByte (MSG_BROADCAST, TE_GUNSHOT);
WriteCoord (MSG_BROADCAST, org_x);
WriteCoord (MSG_BROADCAST, org_y);
WriteCoord (MSG_BROADCAST, org_z);
}
remove(self);
};
Step4
Now delete the W_FireSuperShotgun function and put this function in instead.
void(vector org) W_FireSuperShotgun =
{
local vector dir;
local vector dir2;
local entity newmis2;
self.currentammo = self.ammo_shells = self.ammo_shells - 1;
sound (self, CHAN_WEAPON, "enforcer/enfire.wav", 1, ATTN_NORM);
newmis = spawn ();
newmis.owner = self;
newmis.movetype = MOVETYPE_FLYMISSILE;
newmis.solid = SOLID_BBOX;
dir = aim (self, 1000);
newmis.angles = vectoangles(dir);
newmis.touch = LaserHit;
newmis.classname = "laser";
newmis.nextthink = time + 6; // Time before laser disappears
newmis.think = SUB_Remove;
newmis.effects = self.effects | EF_DIMLIGHT; // Make it glow a little
setmodel (newmis, "progs/laser.mdl");
setsize (newmis, '0 0 0', '0 0 0');
setorigin (newmis, self.origin + v_forward*8 + v_right*-3 + '0 0 16'); // make it go a little to the left.
newmis.velocity = dir * 1000;
// What are you gonna see next is just a copy of whats above but with all the newmis renamed to newmis2 and all the dir renamed to dir2.
newmis2 = spawn ();
newmis2.owner = self;
newmis2.movetype = MOVETYPE_FLYMISSILE;
newmis2.solid = SOLID_BBOX;
dir2 = aim (self, 1000);
newmis2.angles = vectoangles(dir2);
newmis2.touch = LaserHit;
newmis2.classname = "laser";
newmis2.nextthink = time + 6;
newmis2.think = SUB_Remove;
newmis2.effects = self.effects | EF_DIMLIGHT;
setmodel (newmis2, "progs/laser.mdl");
setsize (newmis2, '0 0 0', '0 0 0');
setorigin (newmis2, self.origin + v_forward*8 + v_right*3 + '0 0 16'); //make it go a little to the right
newmis2.velocity = dir * 1000;
};
Step 5
Well there you are, compile it and have fun with your SuperShotgun that now fires two laser bolts.. cool
or what?, see ya.
Tags: tutorial, quakec, qc, insideqc, weapon