It's not working :c

Why?


PvPModeChanger = {}

PvPModeChanger.ChatCommand = "!change"


if SERVER then
 hook.Add( "PlayerSay", "Chat Command", function(ply,text,public)
		if text == PvPModeChanger.ChatCommand then
			ply:ConCommand("change_pvpmode")
			return false
		end
 end)
end

if CLIENT then
        concommand.Add("change_pvpmode",function(ply)
		    ChangePvpMode()
	    end
	
		function ChangePvpMode()
            if ply:GodEnable() then
			    ply:GodDisable()
				print("Disable");
			return end
			end
			ply:GodEnable()
			print("Enable");
	    end
end

[editline]10th May 2014[/editline]

No errors, just not work


(User was banned for this post ("undescriptive thread title, crap thread" - postal))

What doesn’t work? All that code does it create a concommand and print Enable/Disable. There’s nothing else that it does.

You hurt me. Im noob in lua and im just trying write some code.

What the actual fuck? How does he hurt you? He didn’t insult you whatsoever…

You have an undescriptive title, no error and you just posted code telling us to fix it. Give us more and we can actually help, otherwise have fun.

Edit

He has if ply:GodEnable… That’s a function, not a return…

GodEnable and GodDisable are server functions.

The code formatting hurts my brain


 end)
end

This hurts.

Run this in a server side file or wrap it in

[LUA]
if (SERVER) then

end
[/LUA]

Untested

[LUA]
local change_command = “!change”

hook.Add(“PlayerSay”, “TogglePVPMode” , function(Player, Text, TeamChat)
if (string.sub( Text, 1, string.len(change_command)) == change_command) then
ChangePVPMode(Player)
return “”
end
end)

function ChangePVPMode(Player)
if (Player.IsGod) then
Player.IsGod = false
Player:GodDisable()
print(“Disable”)
else
Player.IsGod = true
Player:GodEnable()
print(“Enable”)
end
end
[/LUA]

A lot of people overcomplicate chat-comments. Here’s an easy way: https://dl.dropboxusercontent.com/u/26074909/tutoring/chat_commands/chat_commands.lua.html

Basically, just create a console command ( server-side if the server deals with it, or clientside for client-stuff; but the script is server-side ) that does what you need with the name of the !<text> or /<text>