NPC's Godded

How can i make the NPC’s godded when my server starts, this is not the NPCs you can interact with, im referring to the Hl2 Ones etc.

You should probably hook onto this and filter to the NPCs you want invulnerable:



hook.Add( 'EntityTakeDamage', 'GodNPCs', function(target,info)
if target:IsNPC() then
info:SetDamage(0)
end
end)


Tested. Note this would affect ALL NPC’s. Do you want it to be just for half-life ones?

I think he wants only the Half-Life 2 ones


HL2NPCs = {
	-- Zombies --
	"npc_fastzombie",
	"npc_headcrab",
	"npc_headcrab_black",
	"npc_headcrab_fast",
	"npc_headcrab_poison",
	"npc_poisonzombie",
	"npc_zombie",

	-- Resistance -- 
	"npc_alyx",
	"npc_barney",
	"npc_citizen",
	"npc_dog",
	"npc_eli",
	"npc_kleiner",
	"npc_magnusson",
	"npc_mossman",
	"npc_vortigaunt",

	-- Combine --
	"npc_advisor",
	"npc_breen",
	"npc_cscanner",
	"npc_clawscanner",
	"npc_combinedropship",
	"npc_combinegunship",
	"npc_combine_s",
	"npc_stalker",
	"npc_strider",
	"npc_sniper",
	"npc_metropolice",
	"npc_hunter",
}

hook.Add( 'EntityTakeDamage', 'GodNPCs', function( target, info )
	if target:IsPlayer() and table.HasValue( HL2NPCs, target:GetClass() ) then
		info:SetDamage(0)
	end
end)