Enable / Disable Command

I found this Rainbow Physgun addon, and I’ve spent about 1 1/2 days trying to figure out how to make a enable and disable command for the addon.

Code:




if !ConVarExists("gzg_onlyGroup") then
	CreateConVar("gzg_onlyGroup",1) -- Set this to 1 if you only want certain groups to have rainbow
end

if !ConVarExists("gzg_ocilation") then
	CreateConVar("gzg_ocilation",10) -- This is how fast the rainbow changes color
end

if !ConVarExists("gzg_doplayer") then
	CreateConVar("gzg_doplayer",0) -- Set this to 0 if you don't want the player model rainbow effect
end

if !ConVarExists("gzg_usergroup") then
	CreateConVar("gzg_usergroup","superadmin admin owner coowner vip developer headadmin") -- If gzg_onlyGroup on the third line of code is set to 1, then these are the groups that will have rainbow. Seperate them by spaces, like this: "test test test"
end

if SERVER then return end
-- Don't mess with this stuff below!

isenabled = false

concommand.Add("rainbow_physgun_enable", function()
	isenabled = true
	if (isenabled == true) then
		local function canFlash(ply)

			if(GetConVarNumber("gzg_onlyGroup") == 0) then return true end
			
			local str = GetConVarString("gzg_usergroup")
			local gr = string.Explode(" ",str)

			return(table.HasValue(gr,ply:GetNWString("usergroup")))
		end

		hook.Add("PostDrawViewModel","RainbowPhysgun",function(v,p,w)
			
			if(canFlash(p)) then
				p:SetWeaponColor(Vector(math.abs(math.cos(RealTime()*GetConVarNumber("gzg_ocilation")/10)),math.abs(math.sin(RealTime()*GetConVarNumber("gzg_ocilation")/10)),math.sin(RealTime()*GetConVarNumber("gzg_ocilation")/10)))
			end

		end)

		hook.Add("PostPlayerDraw", "RainbowPhysgunOthers", function()
			
			for k,v in pairs(player.GetAll()) do
				
				if(IsValid(v:GetActiveWeapon()) && v:GetActiveWeapon():GetClass() == "weapon_physgun" && canFlash(v)) then
					v:SetWeaponColor(Vector(math.abs(math.cos(RealTime()*GetConVarNumber("gzg_ocilation")/10)),math.abs(math.sin(RealTime()*GetConVarNumber("gzg_ocilation")/10)),math.sin(RealTime()*GetConVarNumber("gzg_ocilation")/10)))
				end

				if(GetConVarNumber("gzg_doplayer") == 1 && canFlash(v)) then
					v:SetPlayerColor(Vector(math.abs(math.cos(RealTime()*GetConVarNumber("gzg_ocilation")/10)),math.abs(math.sin(RealTime()*GetConVarNumber("gzg_ocilation")/10)),math.sin(RealTime()*GetConVarNumber("gzg_ocilation")/10)))
				end

			end

		end)
	end
end)

concommand.Add("rainbow_physgun_disable", function()
	isenabled = false
end)


Change your disable concommand to something like:



concommand.Add("rainbow_physgun_disable", function()
	isenabled = false -- why?
	hook.Remove("PostDrawViewModel", "RainbowPhysgun")
	hook.Remove("PostPlayerDraw", "RainbowPhysgunOthers")
end)


Thank you!