NPC fall damage?

Yes, I have another request for Garry’s Mod :v:

Can anyone make NPC falling damage? It’d be a nice touch for a little more realism.

Well… considering npcs dont really “fall” at any point in the game… Except from fastzombies/headcrabs

wich are alien life forms so… i dont know if they would take fall damage is par say “real life” :3:

But i guess i would go via Velocity and Onground for this.

I can take my physgun and drop them off cliffs…

I can dream :saddowns:

Check for velocity, and map out a delta using a Think function. Wizey’s right, you could use an IsOnGround with it, but a trace mapped using a normalized velocity would also prove somewhat reliable.

I don’t code. So I have no idea what you’re talking about. Lol

Why am I being rated dumb? I have no fucking clue how to code, that’s why this is in the requests section.

QUICK MAke the fast zombie jump at you then dodge it off a cliff! gets dissapointed as it survived the 9999 foot droff off mount rushmore map Ok… now i think we need this…


NPC_FALL_MINIMUM_HEIGHT = 12 * 16	--Minimum velocity in inches to take damage

local function Think( )
	local k, v

	for k, v in ipairs( ents.GetAll( ) ) do
		if ValidEntity( v ) and v:IsNPC( ) then
			if not v:IsOnGround( ) then
				--We are in the air
				v.m_fLastFallVelocity = v:GetVelocity( ):Length( )
			elseif ( v.m_fLastFallVelocity or 0 ) > NPC_FALL_MINIMUM_HEIGHT then
				local info

				info = DamageInfo( )
					info:SetDamageType( DMG_FALL )
					info:SetDamage( gamemode.Call( "GetNPCFallDamage", v, v.m_fLastFallVelocity ) or math.max( ( v.m_fLastFallVelocity / 16 ) - 12, 1 ) )
					info:SetDamagePosition( v:GetPos( ) )
					info:SetAttacker( v )
				v:TakeDamageInfo( info )
				
				v.m_fLastFallVelocity = 0
			end
		end
	end
end

hook.Add( "Think", "NPC Fall Damage Think", Think )

Pretty much how it is done by Valve for the players. Adds a hook, GetNPCFallDamage.

To scale, it takes three drops from the top of flatgrass to kill an antguard.

Could probably be moved to Tick rather than Think, but I haven’t tried that.

Where do I save this and what do I name it and when do I give you my babies?

Goes in autorun/server.
Name it anything. I named it npc_falldamage.lua for myself.
You can keep the children, but I appreciate the offer.

Alright. Thank you though. Very appreciated :smiley:

Bugs: Not sure, but it might not work if the npc is at negative height, I’m assuming this because if i lift an npc high enough and touch it to a roof or something, it will die (because it’s over the death zone and it hit ground) (low health npc’s only)

does it get the npc’s height from the ground or absolute height?

Not sure if this can be fixed or not

Yea, Fast zombies, When they jump at me, they die. And headcrabs jump and die.

See the little number 12 to the left of * 16?

Change that 12 to about… 40 or 45… or maybe 30. Just make sure its above 25 then it will fix your little “jump 2 cm above ground and die” glitch.

Looks cool I’m going to try it.

-snip