R-42 Assault Rifle
by : Rezhin

Step 1)

        In weapons.qc, insert this all below the plain shotgun code: 

//-------------------------------------------------------------------- 
// Ok, I'm not gonna lie. This is Percile Maniole's code (y'know, Bort!)! 
//-------------------------------------------------------------------- 
void() ShellHit = 
{ 
 if (self.ltime <= (time - 0.2))   // prevent sound if last shell hit sound occured within last 2 frames 
  sound (self, CHAN_WEAPON, "weapons/shellhit.wav", 1, ATTN_NORM);//play the sound 
 self.ltime = time;                // marks time of current touch trigger activation 
}; 

void() DropShell = 
{ 
 self.movetype = MOVETYPE_BOUNCE;  //the shell bounces 
 self.solid = SOLID_BBOX; //it's very solid, baybee! 
 setmodel (self, "progs/shelcase.mdl"); //what's it look like? 
 setsize (self, VEC_ORIGIN, VEC_ORIGIN); 
 makevectors (self.owner.v_angle); 
 setorigin (self, self.owner.origin + v_forward * 10 - v_right*10); 
 self.velocity = v_forward*30 + crandom()*v_forward*30 + v_up*220 + crandom()*v_up*10 - v_right*50 + crandom()*v_right*20; 
 self.avelocity_x = crandom()*500; 
 self.avelocity_y = crandom()*500; 
 self.avelocity_z = crandom()*500; 
 self.touch = ShellHit; //what to do when it touches some'n 
 self.nextthink = time + 4; //when to do it 
 self.think = SUB_Remove; //what to do 
 self.ltime = time - 1; 
}; 

void() SpawnShell= 
{ 
 local entity shell; 

 shell = spawn (); 
 shell.owner = self; 
 shell.nextthink = time + 0.0; 
 shell.think = DropShell; //drop it, sucka! 
}; 

STEP 2)

        Okay, now that made ya some ejecting shells, definitely needed for this shotgun!!!!! 
        Now, below that code, insert this code: 

void(float damage, vector dir) R42TraceAttack = //very necessary 
{ 
 local vector vel, org; 

 vel = normalize(dir + v_up*crandom() + v_right*crandom()); 
 vel = vel + 2*trace_plane_normal; 
 vel = vel * 200; 

 org = trace_endpos - dir*4; 

 if (trace_ent.takedamage) 
 { 
  SpawnBlood (org, vel*0.2, damage); 
  particle (trace_endpos, '0 0 100', 73, 30); //red particles, makes it even cooler and bloodier! 
  AddMultiDamage (trace_ent, damage); 
  if (trace_endpos_z >= trace_ent.origin_z + 25) //if it's someone's head.. 
            { 
            damage = damage * 4;  //hurt them pretty damn bad!!! 
            } 
 } 
 else 
 { 
  WriteByte (MSG_BROADCAST, SVC_TEMPENTITY); 
  WriteByte (MSG_BROADCAST, TE_GUNSHOT); //hehe, change this to TE_EXPLOSION for exploding shells. hahahah! 
  WriteCoord (MSG_BROADCAST, org_x); 
  WriteCoord (MSG_BROADCAST, org_y); 
  WriteCoord (MSG_BROADCAST, org_z); 
  particle (trace_endpos, '0 0 100', 0, 30); //grey particles, smoky-looking. 
 } 
}; 

void(float shotcount, vector dir, vector spread) R42FireBullets = //fire ya bullets 
{ 
 local vector direction; 
 local vector src; 

 makevectors(self.v_angle); 

 src = self.origin + v_forward*10; 
 src_z = self.absmin_z + self.size_z * 0.7; 

 ClearMultiDamage (); 
 while (shotcount > 0) //while the amount of bullets fired is above 0... 
 { 
  direction = dir + crandom()*spread_x*v_right + crandom()*spread_y*v_up; 

  traceline (src, src + direction*2048, FALSE, self); 
  if (trace_fraction != 1.0) 
   R42TraceAttack (8, direction); // 8 damage per bullet (trust me, don't change that 8. It's powerful enough already!!!!! 

  shotcount = shotcount - 1; //reduce the amount of pellets fired... 
 } 
 ApplyMultiDamage (); 
}; 

void() W_FireR42 = 
{ 
 local vector dir; 

 sound (self, CHAN_WEAPON, "weapons/shotgf1.wav", 1, ATTN_NORM); //another one of our new files.... 

 self.punchangle_x = -2; 

 self.currentammo = self.ammo_shells = self.ammo_shells - 1; //take yer ammo 
 dir = aim (self, 100000); 
 R42FireBullets (13, dir, '0.06 0.07 0'); //13 R-42 bullets. Very sexy!!!! 
}; 

STEP 3)


        Okay! Now, find W_SetCurrentAmmo, or whatever. It's the one where you define 
        what V_ model to use. 
Change: 

 else if (self.weapon == IT_SUPER_SHOTGUN) 
 { 
  self.currentammo = self.ammo_shells; 
  self.weaponmodel = "progs/v_shot2.mdl"; 
  self.weaponframe = 0; 
  self.items = self.items | IT_SHELLS; 
 } 

to... 

 else if (self.weapon == IT_SUPER_SHOTGUN) 
 { 
  self.currentammo = self.ammo_shells; 
  self.weaponmodel = "progs/v_r42.mdl"; 
  self.weaponframe = 0; 
  self.items = self.items | IT_SHELLS; 
 } 

okay, now right below this function, find W_Attack, and add this right above, so that... 

void() player_axe1; 
void() player_axeb1; 
void() player_axec1; 
void() player_axed1; 
void() player_shot1; 
void() player_nail1; 
void() player_light1; 
void() player_rocket1; 

will look like 

void() player_axe1; 
void() player_axeb1; 
void() player_axec1; 
void() player_axed1; 
void() player_shot1; 
void() player_nail1; 
void() player_light1; 
void() player_rocket1; 
void() player_r421; 

Now, actually IN W_Attack, change: 

 else if (self.weapon == IT_SUPER_SHOTGUN) 
 { 
  player_shot1 (); 
  W_FireSuperShotgun (); 
  self.attack_finished = time + 0.7; 
 } 

to 

 else if (self.weapon == IT_SUPER_SHOTGUN) 
 { 
  player_r421 (); 
  self.attack_finished = time + 1; 
 } 

STEP 4)

        Now, go into player.qc, and add these lines to the bottom: 

void() player_r421 = [$shotatt1, player_r422 ] 
{ 
self.weaponframe=1;self.effects = self.effects | EF_MUZZLEFLASH;W_FireR42(); 
}; 
void() player_r422 = [$shotatt2, player_r423 ] {self.weaponframe=2;}; 
void() player_r423 = [$shotatt3, player_r424 ] {self.weaponframe=3;}; 
void() player_r424 = [$shotatt4, player_r425 ] 
{ 
self.weaponframe=4;sound (self, CHAN_VOICE, "weapons/shotgr1.wav", 1, ATTN_NORM); 
}; 
void() player_r425 = [$shotatt5, player_r426 ] {self.weaponframe=5;}; 
void() player_r426 = [$shotatt6, player_r427 ] {self.weaponframe=6;SpawnShell ();}; 
void() player_r427 = [$shotatt3, player_r428 ] {self.weaponframe=7;}; 
void() player_r428 = [$shotatt4, player_r429 ] {self.weaponframe=8;}; 
void() player_r429 = [$shotatt5, player_r4210 ] {self.weaponframe=9;}; 
void() player_r4210 = [$shotatt5, player_r4211 ] {self.weaponframe=10;}; 
void() player_r4211 = [$shotatt6, player_run ] {self.weaponframe=11;}; 

Ok, that actually tells the game what to fire, what to make the animations look like, and that sound, and SpawnShell in there, help make the R-42 more cinematic, and THAT MUCH cooler!!! :-) 

STEP 5)

        Ok, almost done!! Ok, assuming you've gotten those new files that this gun NEEDS(!),
        open up weapons.qc again, and add this above W_Precache: 

void() R42Precache = 
{ 
 precache_model ("progs/shelcase.mdl"); //a shell casing 
 precache_model ("progs/v_r42.mdl"); //view model 
 precache_sound ("weapons/shellhit.wav"); //the sounds! 
 precache_sound ("weapons/shotgf1.wav"); 
 precache_sound ("weapons/shotgr1.wav"); 
}; 

And in W_Precache, add this line: 

R42Precache (); 
  
STEP 6)

        Okie! yer done now! Now go get #3 and yer done! ROCK!! SHIAT! 