Command Help


hook.Add( "OnPlayerChat", "Test", function( ply, text )
   local Text = string.lower( text )
     if ( Text == "!test" or Text == "/test" ) then
       LocalPlayer():ConCommand( 'say "This is a test!"' )
      return true
   end
end )

When someone does !test it makes someone say it and not you why is this?

OnPlayerChat is called whenever another player chats. Check to make sure the player is the local player.

So I don’t use OnPlayerChat?

That’s not what I said; make sure you’re checking if you are the person who said the cmd.

bump

Don’t understand

What he means is, add a check to see if it is the local player who types the command.


if !LocalPlayer() then return end

Ehm. Wut? I believe you meant this:



if ply ~= LocalPlayer() then return end


Yeah sorry, brainfucked.

Why even do it like that? You can just do


if ply == LocalPlayer() then

Both can have their place under the right circumstances, to be fair.


hook.Add( "OnPlayerChat", "Test", function( ply, text )
 if ply ~= LocalPlayer() then return end
   local Text = string.lower( text )
     if ( Text == "!test" or Text == "/test" ) then
       LocalPlayer():ConCommand( 'say "This is a test!"' )
		return true
	end
end )

Even with it, it dose not work. :\

Why not code your own commandsystem, or use the one from Acecool/Author(Dont remember which name it was, sorry), its very useful.

Don’t use OnPlayerChat for stuff like this. PlayerSay is a better choice

Just to simplify…


hook.Add( "PlayerSay", "Test", function( ply, text, public )
	local Text = string.lower( text )
	if ( Text == "!test" or Text == "/test" ) then
		ply:Say( "This is a test!" )
		return( "" )
	end
end )

[editline][/editline]
Thanks code_gs for ply:Say

Or just use ply:Say. No need to really use a Concommand there.