Quake Style - Quake 3 Tutorials
Game Enhancements - Locational Damage
Explains how to detect damage in different locations.

This tutorial draws heavily on the source code released by the AQ2 Team.
It is the basic code that I have develped to be used in the up and coming Urban Terror Mod.

It's as simple as this, open up g_combat.c, and add these to the top of the file under the include statements:

// added to facilitate damage algorithim
float	z_ratio;
float	z_rel;
int	height;
float	targ_maxs2;

Next, find these lines:

	Team_CheckHurtCarrier(targ, attacker);

	if (targ->client) {
		// set the last client who damaged the target
		targ->client->lasthurt_client = attacker->s.number;
		targ->client->lasthurt_mod = mod;

Insert after that code:

	if (targ->client && attacker->client && targ->health > 0) //had to add attacker because it was crashing

		targ_maxs2 = targ->r.maxs[2];
		//somehow we have to handle crouching, but not now

		height = abs(targ->r.mins[2]) + targ_maxs2;  
		//G_Printf("height is %d\n", height);

		//project the z component of point onto the z component of the model's origin
		// this results in the z component from the origin at 0
		z_rel = point[2] - targ->r.currentOrigin[2] + abs(targ->r.mins[2]);
		z_ratio = z_rel / height;

		if (z_ratio > 0.85)
			G_Printf("%s hit %s with a headshot\n", attacker->client->pers.netname, targ->client->pers.netname);
		else if (z_ratio > 0.73)
			G_Printf("%s hit %s in the torso\n", attacker->client->pers.netname, targ->client->pers.netname);
		else if (z_ratio > 0.50)
			G_Printf("%s hit %s in the stomach\n", attacker->client->pers.netname, targ->client->pers.netname);
			G_Printf("%s hit %s in the legs\n", attacker->client->pers.netname, targ->client->pers.netname);

This is enough to get you started.. If you want to scale the damage at this point just insert:

take *= 1.8;

next to one of the G_Printf statements, for say a headshot, or whatever you prefer.
This code was written to be used in the upcoming Urban Terror Mod.

-- Credits:
   Tutorial by wchar_t*
   Return to QS Tutorials

-- Important:
   If you do use something from QuakeStyle in your mod, please give us credit.
   Our code is copyrighted, but we give permission to everyone to use it in any way they see fit, as long as we are recognized.