Hitgroup

From GMod Wiki

Jump to: navigation, search

Hitgroups

HitGroups are constants for hitboxes on NPCs and Players. They can be used to Determine where the entity has been hit.

Here are the current HitGroups and their values:

 
HITGROUP_GENERIC = 0
HITGROUP_HEAD = 1
HITGROUP_CHEST = 2
HITGROUP_STOMACH = 3
HITGROUP_LEFTARM = 4
HITGROUP_RIGHTARM = 5
HITGROUP_LEFTLEG = 6
HITGROUP_RIGHTLEG = 7
HITGROUP_GEAR = 10
 

Examples

DescriptionCripples a player's movement after significant damage to the legs.
Used onNewerServer.png
CodeAdd both the Gamemode.PlayerLoadout and Gamemode.ScalePlayerDamage functions, or add the code anywhere inside them if they already exist.
function GM:PlayerLoadout( ply ) --Weapon/ammo/item function
	ply.hitgroups = {}
	for group = 0,10 do
		if group ~= HITGROUP_GENERIC and group ~= HITGROUP_GEAR then
			ply.hitgroups[group] = 50
		end
	end
end
 
groupNames = {"head","chest","stomach","left arm","right arm","left leg","right leg"}
function GM:ScalePlayerDamage( ply, hitgroup, dmginfo )
	if (ply.hitgroups and ply.hitgroups[hitgroup]) then
		local groupName = groupNames[hitgroup]
 
		--ply:PrintMessage( HUD_PRINTTALK, "Your "..groupName.." is down to "..ply.hitgroups[hitgroup])
		ply.hitgroups[hitgroup] = ply.hitgroups[hitgroup] - dmginfo:GetBaseDamage()
 
 
		--Now set the player's speed dependant on the state of his/her legs.
		local speed = 20
		if ply.hitgroups[HITGROUP_RIGHTLEG] > 0 then
			speed = speed + 90
		end
		if ply.hitgroups[HITGROUP_LEFTLEG] > 0 then
			speed = speed + 90
		end
 
		GAMEMODE:SetPlayerSpeed( ply, speed, speed*1.75 )
	end
end
OutputAim for the legs. If your target doesn't die, they'll wish they had!
Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox