Mimic Half-Life 2 behaviour, in the context of a gamemode.
Running this code from an addon is not advised, as you'd have to stop all other hooks from running, potentially breaking other addons or the gamemode,
or be applying the damage on top of the gamemode's scaling, resulting in unwanted issues like 4x or 6x headshot damage in Sandbox.
function GetNPCDamageMultiplier( npc, iHitGroup, dmginfo )
if ( iHitGroup
== HITGROUP_GEAR )
then
return 0.01
elseif ( iHitGroup
== HITGROUP_HEAD )
then
if (
npc:
GetClass()
== "npc_combine_s" )
then
return 2
elseif (
npc:
GetClass()
== "npc_zombie" || npc:
GetClass()
== "npc_zombine" || npc:
GetClass()
== "npc_fastzombie" ||
npc:
GetClass()
== "npc_poisonzombie" || npc:
GetClass()
== "npc_zombie_torso" || npc:
GetClass()
== "npc_fastzombie_torso" )
then
if (
bit.
band(
dmginfo:
GetDamageType(), DMG_BUCKSHOT )
!= 0 )
then
if (
IsValid(
dmginfo:
GetAttacker() ) )
then
local flDist
= (
npc:
GetPos()
- dmginfo:
GetAttacker():
GetPos() ):
Length()
if ( flDist
<= 96 )
then
return 3
end
end
else
return 2
end
end
return GetConVarNumber(
"sk_npc_head" )
elseif ( iHitGroup
== HITGROUP_CHEST )
then
return GetConVarNumber(
"sk_npc_chest" )
elseif ( iHitGroup
== HITGROUP_STOMACH )
then
return GetConVarNumber(
"sk_npc_stomach" )
elseif ( iHitGroup
== HITGROUP_LEFTARM
|| iHitGroup
== HITGROUP_RIGHTARM )
then
return GetConVarNumber(
"sk_npc_arm" )
elseif ( iHitGroup
== HITGROUP_LEFTLEG
|| iHitGroup
== HITGROUP_RIGHTLEG )
then
return GetConVarNumber(
"sk_npc_leg" )
end
end
function GM:
ScaleNPCDamage( npc, hitgroup, dmginfo )
local damageScale
= GetNPCDamageMultiplier( npc, hitgroup, dmginfo )
if ( damageScale )
then
dmginfo:
ScaleDamage( damageScale )
end
end