[CODE]function GM:PlayerSay(ply,text,p)
if(string.lower(text) == "!rules" || string.lower(text) == "!rules") then
concommand.Run( "motd" )
return ""
end
return self.BaseClass:PlayerSay(ply,text,p)
end[/CODE]
Is this how I go about doing it? !rules isn't working no errors too.
[code]hook.Add( "OnPlayerChat", "Rules", function( ply, text )
local Text = string.lower( text )
if ( Text == "!rules" or Text == "/rules" ) then
RunConsoleCommand( "motd" )
-- return true -- Uncomment if you want the message to be hidden
end
end )[/code]
Make sure you use hooks instead of overriding default functions then calling the baseclass. That should only be used in the case that you are making your own gamemode. Also, OnPlayerChat is the clientside equivalent of PlayerSay, and is more suitable for clientside chat commands.
Why even use or if both of your expressions are identical? concommand.Run is not what you need to use either, instead consider using [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Player/ConCommand]Player:ConCommand[/url]. Also, don't overwrite the GM:X functions unless this is in the code of the gamemode. Instead, use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/hook/Add]hook.Add[/url]. Finally, don't bother returning anything unless you found the command in the text, as it can cause problems with other hooks.
Edit: Ninja city
Sorry, you need to Log In to post a reply to this thread.