Rage through 32 single player levels and 6 deathmatch levels of sheer terror and fully immersive sound and lighting. Arm yourself against the cannibalistic Ogre, fiendish Vore and indestructible Schambler using lethal nails, fierce Thunderbolts and abominable Rocket and Grenade Launchers.

Post tutorial Report RSS Easy locational damage!

A tutorial brought to you by Miles Invictus, comes an awesome feature that makes your head shots true and beneficial to your gaming experience.

Posted by on - Basic Server Side Coding

Introduction

In most games these days, they have locational damage because it seems "realistic" to them, taking more damage from the head than other parts of the body. WELL LET'S PUT THAT IN QUAKE NO?

The real meat


Open WEAPONS.QC.

Replace the TraceAttack function with this:

// Now with locational damage
void(float damage, vector dir) TraceAttack =
{
	local	vector	vel, org;
	local float f_damage;
	
	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)
	{
                 if (trace_fraction >= 1)
                        return;
  	if (trace_endpos_z > (trace_ent.origin_z + 18))
		{
                f_damage = damage * 2; // This is a head shot
		}
	else if (trace_endpos_z < trace_ent.origin_z)
		{
                f_damage = damage * 0.5; // This is a leg shot
		}
	else
		{
                f_damage = damage; // Anywhere else (torso)
		}
                  SpawnBlood (org, vel*0.2, f_damage * 0.3);
                  AddMultiDamage (trace_ent, f_damage);
	}
	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);
	}
};


The final step
There is no final step. YOU ARE DONE! :D

Now, compile your code, run your mod, and kick some arse! Aim for the head if you can find it.

(This code is adopted from Miles Invictus' old locational damage code with permission, and heavily simplified by yours truly, to allow easy addition into mods. Tutorial written in October 2003.)

Post comment Comments
TwinBeast
TwinBeast - - 565 comments

This looks cool. I'm thinking of coding something similar for DooM if I can.

Reply Good karma Bad karma+1 vote
PsychoBrat
PsychoBrat - - 291 comments

This would only work against humans and other creatures with the same proportions, would it not?

Reply Good karma Bad karma+1 vote
Post a comment

Your comment will be anonymous unless you join the community. Or sign in with your social account: