No Damage God Mode

Hello Facepunch. Recently, I’ve been looking around to try and find some manner script that would prevent players in god mode from being able to damage other players. I was given the following script a few weeks back, but it didn’t seem to function properly for me.


local PMETA = FindMetaTable("Player")

function PMETA:IsGod()
	return self:GetNWBool("GodMode")
end

function PMETA:SetGod()
	if SERVER then
		if !self:IsGod() then
			self:GodEnable()
			self:SetNWBool("GodMode",true)
		else
			self:GodDisable()
			self:SetNWBool("GodMode",false)
		end
	end
end

hook.Add("PlayerShouldTakeDamage","DisableDamageFromGod",function(vic,atk)
	if atk:IsGod() then return false end
end)

Since I possess only a basic understanding of how Lua works in Garry’s Mod, I was hoping that one of you might be able to help me diagnose the problem. Thanks in advance.

Bump?

[lua]
local plyMeta = FindMetaTable(“Player”)

function plyMeta:IsGod()
return self._godMode – the function is probably only used on the server
end – no point in networking a boolean value

plyMeta.oldGodEnable = plyMeta.oldGodEnable or plyMeta.GodEnable
plyMeta.oldGodDisable = plyMeta.oldGodDisable or plyMeta.GodDisable

function plyMeta:GodEnable()
self._godMode = true
self:oldGodEnable()
end

function plyMeta:GodDisable()
self._godMode = false
self:oldGodDisable()
end

hook.Add(“PlayerShouldTakeDamage”,“disable_damage_from_god”,function(_,p)
if IsValid§ and p:IsPlayer() and p:IsGod() then – players can take damage from non-player entities too
return false
end
end)
[/lua]

It works exactly as I need it to! A million thanks!