Making an entity invincible

Hello. I currently have two entites spawned in my gamemode that are shopkeepers.
Here is the code I used to spawn them.


local merchant = ents.Create("npc_monk")
merchant:SetPos(Vector( -2174, -10167, 419) )
merchant:SetHealth(9999999) -- This line didn't seem to do anything for me! :/
merchant:Give("weapon_shotgun")
merchant:Spawn()
merchant:DropToFloor()

local merchant2 = ents.Create("npc_eli")
merchant2:SetPos(Vector( -2206, -9914, 395) )
merchant2:SetAngles(Angle(4, -134, 0))
merchant2:SetHealth(9999999) -- The same thing applies here.
merchant2:Give("weapon_smg1")
merchant2:Spawn()
merchant2:DropToFloor()

Despite apparently having 999999 health, they are still easily killed with a few shots to any part of their body. The head is a one hit kill.
I would only like to make these NPCs invincible, but after looking on Google and Facepunch for quite a while, the only solution I have been able to find is making them a scripted entity,
which, to be honest, I don’t really think I need, considering they do their job perfectly well as they are.

Therefore, is there a way to make an entity invincible (maybe by using a hook for when NPCs take damage? Not sure) without making them a scripted entity?

Any help would be most appreciated. Thanks.


local merchant = ents.Create("npc_monk")
merchant:SetPos(Vector( -2174, -10167, 419) )
merchant:SetHealth(9999999) -- This line didn't seem to do anything for me! :/
merchant:Give("weapon_shotgun")
merchant:Spawn()
merchant:DropToFloor()
merchant.IsNPCMerchant = true

local merchant2 = ents.Create("npc_eli")
merchant2:SetPos(Vector( -2206, -9914, 395) )
merchant2:SetAngles(Angle(4, -134, 0))
merchant2:SetHealth(9999999) -- The same thing applies here.
merchant2:Give("weapon_smg1")
merchant2:Spawn()
merchant2:DropToFloor()
merchant2.IsNPCMerchant = true


local function EntityTakeDamage( ent, inf, atk, amt, info )
  if ent.IsNPCMerchant then
    info:SetDamage( 0 )
  end
end

hook.Add( "EntityTakeDamage", "NPCMerchant EntityTakeDamage", EntityTakeDamage )

Things that remove or outright kill them via Kill will still get rid of them, though.

Thank you. I shall try the code now.

I’m receiving an error:


[ERROR] gamemodes/survivalrp/gamemode/init.lua:501: attempt to index local 'info' (a nil value)


local function EntityTakeDamage( ent, inf, atk, amt, info )
  if ent.IsNPCMerchant then
    **info:SetDamage( 0 ) -- <-- Line 501**
  end
end


Still need help, guys!

I know its a bit late … but

Change info:SetDamage( 0 ) to inf:SetDamage( 0 )

or

local function EntityTakeDamage( ent, inf, atk, amt, info ) to local function EntityTakeDamage( ent, info, atk, amt, info )