ROTT Firebomb
Created By: Plumb
eMail: plumbjit@tinyonline.co.uk
Difficulty Scale: Medium


This tutorial will teach you how to turn the rocket launcher into something similar to the firebomb off ROTT. ;>

I'll explain the theory before I start with the code. When a rocket hits something it fires four invisible objects (similar to the rocket) out, one in each direction. Those invisible rocket things are constantly exploding creating a cool (and deadly) effect. Follow that? Neither did I. Let's just do it.

Step 1.

Open weapons.qc and find...

void() W_FireRocket =
Most of our code is going to be based around these functions. The line we're after is:

missile.touch = T_MissileTouch;
Find it and change it to

missile.touch = T_FireBombTouch;

Step 2.

Scroll up a bit and you'll find T_MissileTouch. We still want to use this procedure, just not now. Our firebomb missile is going to use a modified version so copy it, paste it underneath and change it's name to:

void() T_FireBombTouch =
{
	local float	damg;


Step 3.

Change the last part of this procedure to read:

	// don't do radius damage to the other, because all the damage
	// was done in the impact
//	T_RadiusDamage (self, self.owner, 120, other);		// No need for it to hurt people

//	sound (self, CHAN_WEAPON, "weapons/r_exp3.wav", 1, ATTN_NORM);
	self.origin = self.origin - 8*normalize(self.velocity);

	WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);		// Leave the pretty explosion in
	WriteByte (MSG_BROADCAST, TE_EXPLOSION);
	WriteCoord (MSG_BROADCAST, self.origin_x);
	WriteCoord (MSG_BROADCAST, self.origin_y);
	WriteCoord (MSG_BROADCAST, self.origin_z);

//	BecomeExplosion ();					// We don't want this happening either

	LaunchFirebomb ('1 0 0', self.origin, self.owner);	// THE NASTY BIT
	LaunchFirebomb ('0 1 0', self.origin, self.owner);
	LaunchFirebomb ('-1 0 0', self.origin, self.owner);
	LaunchFirebomb ('0 -1 0', self.origin, self.owner);

	remove(self);
};
You can always remove the lines I've commented out but I've left them in here for clarity. T_RadiusDamage is removed because it's not really needed. If you shot someone with the missile, what happens after is sure to kill them anyway. BecomeExplosion you won't really notice either as it just creates the little sprite in the middle of an explosion. If you can notice this you're about to be gibbed. :P

Step 4.

Now we must write LaunchFirebomb. This is the function which creates our firebally thingies. The four missiles I mentioned right at the start. Put it between T_FirebombTouch and T_MissileTouch.

//
// Plumb's firebomb tutorial
//
void(vector dir, vector org, entity e) LaunchFirebomb =
{
	local entity fb;
	fb = spawn();
	
	org_z = org_z + 10;	// Incase u shoot it at the floor

	fb.classname = "firebomb";
	fb.owner = e;
	fb.movetype = MOVETYPE_FLYMISSILE;
	fb.solid = SOLID_BBOX;
	fb.velocity = dir * 600;		
	fb.angles = vectoangles(fb.velocity);
	fb.touch = T_MissileTouch;		// Told you we'd need this

	fb.nextthink = time + 0.1;		// Explosions :>
	fb.think = FirebombKaboom;
	setsize (fb, '0 0 0', '0 0 0');		
	setorigin (fb, org);
};
It's a modified version of W_FireRocket. There's no setmodel line so it's invisible and there's a few small changes to the way that it works.

Step 5.

Paste in FirebombKaboom before LaunchFirebomb.

void() FirebombKaboom =
{
	self.nextthink = time + 0.1;
	self.think = FirebombKaboom;

	T_RadiusDamage (self, self.owner, 120, world);

	WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
	WriteByte (MSG_BROADCAST, TE_EXPLOSION);
	WriteCoord (MSG_BROADCAST, self.origin_x);
	WriteCoord (MSG_BROADCAST, self.origin_y);
	WriteCoord (MSG_BROADCAST, self.origin_z);
};
I stole most of that code from GrenadeExplode. If it's already written, borrow it! Feel free to adjust the value in T_RadiusDamage if you think it's all a bit too meaty.

Step 6.

Compile, get a rocket launcher, climb somewhere high and shoot down at the floor below.