Naming a net.Recieve function

I want to name a net.Recieve function so I can remove the hook to it later. If you can do this without naming it, that would be helpful.



net.Receive("DisableChat", function DisableChat(len,ply)

	if text = "" or text != "" then
		return ""
	else
	end

end)
hook.Add( "PlayerSay", "DisableChat", DisableChat )


net.Receive("EnableChat", function(len,ply)

	hook.Remove("PlayerSay", DisableChat)

end)


You cannot remove net.Receive hooks. And you really shouldn’t have the need to do so.

But if you want, you can just stop them from doing whatever they do by doing something like this:




local MyHookEnabled = true
function SetMyHookEnabled( b )
	MyHookEnabled = tobool( b )
end

net.Receive("DisableChat", function DisableChat(len,ply) -- you dont need DisableChat here
	if ( !MyHookEnabled ) then return end -- Do not execute the rest of the code if we are set to be disabled

	if text = "" or text != "" then
		return ""
	else
	end

end)
hook.Add( "PlayerSay", "DisableChat", DisableChat ) -- the fucks this


net.Receive("EnableChat", function(len,ply)
	if ( !MyHookEnabled ) then return end -- Do not execute the rest of the code if we are set to be disabled

	hook.Remove("PlayerSay", DisableChat) -- This is not how you use hook.Remove

end)



Don’t put net recieves inside of functions.

Or this this what you are trying to do?




function DisableChat(ply,text, team)

	if text = "" or text != "" then
		return ""
	else
	end

end


net.Receive( "DisableChat", function(len,ply)

	hook.Add( "PlayerSay", "DisableChat", DisableChat )

end)

net.Receive( "EnableChat", function(len,ply)

	hook.Remove("PlayerSay", "DisableChat")

end)

[editline]14th May 2016[/editline]

And are you really trying to give ANY PLAYER ON THE SERVER ability to disable chat FOR EVERYBODY ON THE SERVER?

Yes I was tying to do that. Since it is my dev server, it doesn’t matter who uses it. I was going to add checks against the players running it once I got it to work in the first place.

-SNIP-