[CODE]hook.Add( "OnPlayerChat", "SHUD", function( ply, text )
local Text = string.lower( text )
if ( Text == "!showhud" or Text == "/showhud" ) then
RunConsoleCommand( "cl_hidehud", "0" )
chat.AddText(Color(255,255,255),"[",Color(200,72,200),"Timer",Color(255,255,255),"] HUD enabled.")
return true
end
end )[/CODE]
When I do !showhud the command works for every player I want it to work just for the person who typed it any help?
use ply:ConCommand() instead of RunConsoleCommand.
[QUOTE=whitestar;48328842]use ply:ConCommand() instead of RunConsoleCommand.[/QUOTE]
Ah I tried that and nothing happens.
do you have hidehud set to 1?
[code]if ply == LocalPlayer() and ( Text == "!showhud" or Text == "/showhud" ) then[/code]
[QUOTE=edgarasf123;48329112][code]if ply == LocalPlayer() and ( Text == "!showhud" or Text == "/showhud" ) then[/code][/QUOTE]
I'll test that later does anyone know why this dosen't work?
[CODE]hook.Add( "OnPlayerChat", "Test", function( ply, text )
local Text = string.lower( text )
if ply == LocalPlayer() and ( Text == "!test" or Text == "/test" ) then
RunConsoleCommand( 'say', "This is a test!" )
return true
end
end )[/CODE]
[QUOTE=FiBzY;48329785]I'll test that later does anyone know why this dosen't work?
[CODE]hook.Add( "OnPlayerChat", "Test", function( ply, text )
local Text = string.lower( text )
if ply == LocalPlayer() and ( Text == "!test" or Text == "/test" ) then
RunConsoleCommand( 'say', "This is a test!" )
return true
end
end )[/CODE][/QUOTE]
Use printing to debug and see where its failing.
BTW where are you putting it?
[QUOTE=tzahush;48329856]Use printing to debug and see where its failing.
BTW where are you putting it?[/QUOTE]
In my gamemode, cl_init.lua
[QUOTE=FiBzY;48329914]In my gamemode, cl_init.lua[/QUOTE]
Don't do RunConsoleCommand on a LocalPlayer, just don't.
[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]
I tried that and it didn't work but it works for other things just not the say why is this?
[editline]30th July 2015[/editline]
It makes no sense because I tried this and this worked:
[CODE]local function Test()
LocalPlayer():ConCommand("say testestest")
end
timer.Create("Testing", 2, 0, Testing)[/CODE]
bump
if i'm correct it shouldn't work on every player because OnPlayerChat is a clientside hook and RunConsoleCommand would just be ran on that client?
[QUOTE=tyguy;48335153]if i'm correct it shouldn't work on every player because OnPlayerChat is a clientside hook and RunConsoleCommand would just be ran on that client?[/QUOTE]
LocalPlayer():ConCommand( 'say "This is a test!"' )
I mean this code doesn't work only in OnPlayerChat why is this?
Why dont you use the serverside hook instead, and then try "ply:ConCommand"?
[QUOTE=whitestar;48335517]Why dont you use the serverside hook instead, and then try "ply:ConCommand"?[/QUOTE]
What? I'm trying to get this to work:
[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]
[QUOTE=FiBzY;48336951]What? I'm trying to get this to work:
[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][/QUOTE]
I wouldn't even go like that. Why find !test anywhere in the text when you could check for if they actually wanted to say the command?
[CODE]hook.Add( "OnPlayerChat", "ThisCommandIsATest", function( ply, text, public )
if string.lower( text, 1, 5 ) == "!test" or string.lower( text, 1, 5 ) == "/test" then
LocalPlayer():ConCommand( "say This is a test!" )
return true
end
end )[/CODE]
Also this [QUOTE=whitestar;48335517]Why dont you use the serverside hook instead, and then try "ply:ConCommand"?[/QUOTE]
It's just simpler
It's actually not, plus it depends on what you need it for.
Here's a client side example
[lua]
hook.Add('OnPlayerChat', 'testcommands', function(ply, text)
if (ply == LocalPlayer() and string.match(string.lower(text), '^[!/#@]test')) then //make sure WE ran it. check if the command is !test /test #test or @test
RunConsoleCommand('say', 'this is a test') //do the stuff
end
end)
[/lua]
and a server side version
[lua]
hook.Add('PlayerSay', 'testcommands', function(ply, text)
if (string.match(string.lower(text), '^[!/#@]test')) then //check if the command is !test /test #test or @test
ply:ConCommand('say', 'this is a test') //do the stuff
end
end)
[/lua]
Serverside you don't need to check if it's you who ran it.
Sorry, you need to Log In to post a reply to this thread.