Created By: Christian "CeeJay" Jensen
eMail d96411@delfi.lyngbyes.dk
Difficulty Scale Easy



Step 1
When playing Quake , you might have noticed that when you shoot a trigger ( like a shootable button , or a secret door ) it bleeds. This is particularly irritating to people trying to create an explodable wall or glass. It looks very fake when you shoot glass and it bleeds !
But in this tutorial I will show you , just how to fix that.

Step 2
First open weapons.qc and find the function W_FireAxe. This function controls the damage and bleeding caused by the axe.
You will notice that the function SpawnBlood is called every time we hit something that is damageable (including shootable buttons and glass).
To remedy this we will use the fact the QuakeC distinguishes between three different damage types :

DAMAGE_NOT - For entities that cannot be damaged

DAMAGE_YES - For entities that can be damaged , but grenades will bounce off ( ie: shootable buttons - See where i'm getting at ? )

DAMAGE_AIM - For entities that can be damaged , and grenades will explode on impact with ( monsters and players - ie: Things that bleed )

Now it would be simple just to make nonflesh entities stop bleeding by changing :

if (trace_ent.takedamage)
to
if (trace_ent.takedamage=DAMAGE_AIM)

But that would be foolish since damage is also dealt in this function. The result would be nonbleeding,NONSHOOTABLE shootable buttons and we would'nt want that!
Instead, insert a check for DAMAGE_AIM , but only for SpawnBlood not for the damagefunction T_Damage.
Now you have stopped the axe from causing nonflesh entities to bleed - Now for the finishing touch

Change the else to if (trace_ent.takedamage!=DAMAGE_AIM) to make those grey particles appear , when you hit a button/glasswall too, just like when you hit a normal wall.

The resulting function should look like this :

/*
================
W_FireAxe
================
*/
void() W_FireAxe =
{
	local	vector	source;
	local	vector	org;

	makevectors (self.v_angle);
	source = self.origin + '0 0 16';
	traceline (source, source + v_forward*64, FALSE, self);
	if (trace_fraction == 1.0)
		return;
	
	org = trace_endpos - v_forward*4;

	if (trace_ent.takedamage)  //If damageable - Monsters,players and triggers
	{
		trace_ent.axhitme = 1;

		if (trace_ent.takedamage==DAMAGE_AIM) //If monster or player - Note : Not Triggers!
		{
			SpawnBlood (org, '0 0 0', 20);   //Bleed!
		}
		T_Damage (trace_ent, self, self, 20); //Damage monster/player/trigger
	}
	if (trace_ent.takedamage!=DAMAGE_AIM) //If not monster or player  
	{	// hit wall
		sound (self, CHAN_WEAPON, "player/axhit2.wav", 1, ATTN_NORM);
		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);
	}
};



Step 3
Now that we've fixed the axe, proceed to do the same for the function TraceAttack. This function traces the bullets from the shotgun and the doublebarreled shotgun and subsequently causes them to bleed.

The changed bit should look like this :


if (trace_ent.takedamage)  // If Damageable - Monsters,players or triggers
	{
		if (trace_ent.takedamage==DAMAGE_AIM) // If Monsters or players
		{
			SpawnBlood (org, vel*0.2, damage); // Bleed!
		}
		AddMultiDamage (trace_ent, damage); //Take damage
	}
if (trace_ent.takedamage!=DAMAGE_AIM)  // If not Monster or player


Step 4
Now skip down to spike_touch, don't worry about rockets and grenades - they don't cause bleeding. And we will take lightning last because it differs a little bit from the other bleed functions.

Change the bleeding bit it to look like this :

// hit something that bleeds
	if (other.takedamage) // If damageable
	{
		if (other.takedamage==DAMAGE_AIM) //If monster or player
		{
			spawn_touchblood (9); // Bleed!
		}
		T_Damage (other, self, self.owner, 9);
	}
if (other.takedamage!=DAMAGE_AIM) // If not monster or player 
Do the same thing for superspike_touch , just remember that the damage dealt is 18 not 9 as with spike_touch.
BTW : spike_touch also control the wizards and the hellknights "spikes" so those spikes won't cause unrealistic bleeding either!


Step 5
Now all that's missing is for us to fix lightning, so scroll back up again and find it. More specifically the function is called : LightningDamage
In LightningDamage there are three subsections, one for each beam that comes from the Lightninggun (Thunderbolt) : traceline, e1 and e2.
Now for each of them change :

		if (trace_ent.takedamage) //If damageable
		{
			particle (trace_endpos, '0 0 100', 225, damage*4); // Bleed!
			T_Damage (trace_ent, from, from, damage); //cause damage

		to :

		if (trace_ent.takedamage) //damageable
		{
			if (trace_ent.takedamage==DAMAGE_AIM) //If monster or player
			{
				particle (trace_endpos, '0 0 100', 225, damage*4); // Bleed!
			}
			T_Damage (trace_ent, from, from, damage); //cause damage


Step 6
That's it! - Compile and play.

Thanks to :
Inside.QC for starting me off.
Ferrara Francesco for QuakeC Manual 1.0.
Lee Smith for ProQCC
And iD for including bugs for me to fix J