• Command Help
    15 replies, posted
[CODE]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 )[/CODE] 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.
[code]if !LocalPlayer() then return end[/code]
[QUOTE=whitestar;48359792][code]if !LocalPlayer() then return end[/code][/QUOTE] Ehm. Wut? I believe you meant this: [code] if ply ~= LocalPlayer() then return end [/code]
[QUOTE=mijyuoon;48360069]Ehm. Wut? I believe you meant this: [code] if ply ~= LocalPlayer() then return end [/code][/QUOTE] Yeah sorry, brainfucked.
[QUOTE=mijyuoon;48360069]Ehm. Wut? I believe you meant this: [code] if ply ~= LocalPlayer() then return end [/code][/QUOTE] Why even do it like that? You can just do [CODE]if ply == LocalPlayer() then[/CODE]
[QUOTE=JasonMan34;48362957]Why even do it like that? You can just do [CODE]if ply == LocalPlayer() then[/CODE][/QUOTE] Both can have their place under the right circumstances, to be fair.
[CODE]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 )[/CODE] Even with it, it dose not work. :\
[QUOTE=FiBzY;48368561][CODE]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 )[/CODE] Even with it, it dose not work. :\[/QUOTE] Why not code your own commandsystem, or use the one from Acecool/Author(Dont remember which name it was, sorry), its very useful.
[QUOTE=FiBzY;48368561][CODE]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 )[/CODE] Even with it, it dose not work. :\[/QUOTE] Don't use OnPlayerChat for stuff like this. PlayerSay is a better choice
[QUOTE=code_gs;48369718]Don't use OnPlayerChat for stuff like this. PlayerSay is a better choice[/QUOTE] Just to simplify... [CODE]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 )[/CODE] [editline][/editline] Thanks code_gs for ply:Say
[QUOTE=JasonMan34;48369799]Just to simplify... [CODE]hook.Add( "PlayerSay", "Test", function( ply, text, public ) local Text = string.lower( text ) if ( Text == "!test" or Text == "/test" ) then ply:ConCommand( "say This is a test!" ) return( "" ) end end )[/CODE][/QUOTE] Or just use ply:Say. No need to really use a Concommand there.
Sorry, you need to Log In to post a reply to this thread.