• Simple run command client LUA.
    21 replies, posted
Hello, Could someone make me a fast and small LUA which does when a client types " !console " it brings his console, and when he types " !kill " he runs the " kill " command ? Thanks in advance.
[lua]hook.Add("PlayerSay","RunCommands",function(ply,text,toall) if text == "!console" then ply:ConCommand("console") elsief text == "!kill" then ply:ConCommand("kill") end end)[/lua] Something like that. And alas, I can't remember the command to open the console, so if you could find it and substitute it in for the first part that'd be great.
[QUOTE=Entoros;16310626][lua]hook.Add("PlayerSay","RunCommands",function(ply,text,toall) if text == "!console" then ply:ConCommand("console") elsief text == "!kill" then ply:ConCommand("kill") end end)[/lua] Something like that. And alas, I can't remember the command to open the console, so if you could find it and substitute it in for the first part that'd be great.[/QUOTE] It's " toggleconsole ". Thanks. Also, where do I must put it ? I want to install it on a dedicated server.
It would go in your /lua/autorun/server folder.
[QUOTE=Entoros;16311989]It would go in your /lua/autorun/server folder.[/QUOTE] Thank you.
[lua] hook.Add("PlayerSay","RunCommands",function(ply,text,toall) if text == "!console" then ply:SendLua("LocalPlayer():ConCommand(\"toggleconsole\")") elseif text == "!kill" then ply:SendLua("LocalPlayer():ConCommand(\"kill\")") end end) [/lua] Garry's wonderful update :/
-snip- I'm an idiot
[lua]if text == "!console" then ply:SendLua("ConCommand(\"toggleconsole\")") [/lua] [lua] LocalPlayer():ConCommand ? [/lua]
ecabc it needs to have the player. hence the LocalPlayer() [url]http://wiki.garrysmod.com/?title=Player.ConCommand[/url] snip the above i see what you mean :P i made a typo fixed
[QUOTE=mcd1992;16316193][lua] hook.Add("PlayerSay","RunCommands",function(ply,text,toall) if text == "!console" then ply:SendLua("LocalPlayer():ConCommand(\"toggleconsole\")") elsief text == "!kill" then ply:SendLua("LocalPlayer():ConCommand(\"kill\")") end end) [/lua] Garry's wonderful update :/[/QUOTE] This one doesn't work. :/
It has a typo. Try this one.. [lua] local function PlayerSay( pl, text ) if( text:lower( ):find( "^!console" ) ) then pl:ConCommand( "toggleconsole" ); return ""; elseif( text:lower( ):find( "^!kill" ) ) then pl:ConCommand( "kill" ); return ""; end end hook.Add( "PlayerSay", "DoStuff", PlayerSay ); [/lua]
actually nevec I fixed the typo and !kill should work but toggleconsole is blocked by garry so it wont work, also your code wont work either because garry raped player:ConCommand() the last 2 updates :/ Solution? We wait for somone to make a example with usrmsg also in your code whats the purpose of [code]return "";[/code]is that just a C++ habit or somthing?
[QUOTE=mcd1992;16327538]actually nevec I fixed the typo and !kill should work but toggleconsole is blocked by garry so it wont work, also your code wont work either because garry raped player:ConCommand() the last 2 updates :/ Solution? We wait for somone to make a example with usrmsg also in your code whats the purpose of [code]return ""[/code]is that just a C++ habit or somthing?[/QUOTE] You didnt fix the typo. Elseif isnt spelt like you spelt it. And returning that, makes nobody hear what you said (Cant phrase it properly)
gotcha, also I need sleep I cant spell to save my life at the moment...
Bump, still not working. :(
[lua]hook.Add("ChatText"[/lua]
[QUOTE=ecabc;16392699][lua]hook.Add("ChatText"[/lua][/QUOTE] "Warning! This hook doesn't get called when a player talks anymore, but instead you can use Gamemode.OnPlayerChat. However, this does get called on other than player messages."
Please someone could post the finished LUA? I'm a pure noob I don't even know what are these commands etc... I just need a finished file to put on my server. :-(
Bump. I really need to know how to do that. I have so many addons that are console command only.
[code] if SERVER then AddCSLuafile("autorun/chatcmd.lua") else function ChatCommands(ply,text) if text:find("!console") then RunConsoleCommand("toggleconsole") -- will be blocked anyway, because there is 'toggle' in the cmd, thanks to garry :) elseif text:find("!kill") then RunConsoleCommand("kill") end end hook.Add("OnPlayerChat","Kill / Toggle Console",ChatCommands) end [/code] Place in lua/autorun/chatcmd.lua on your server.
Try the following. [LUA]RunConsoleCommand("con_enable 1") --Allows the console to be activated. RunConsoleCommand("showconsole") --Show the console.[/LUA]
Sorry for bumping, but I tried this : [LUA]if SERVER then AddCSLuafile("autorun/chatcmd.lua") else function ChatCommands(ply,text) if text:find("!console") then RunConsoleCommand("con_enable" "('1')"") RunConsoleCommand("showconsole") elseif text:find("!kill") then RunConsoleCommand("kill") elseif text:find("!stopsounds") then RunConsoleCommand("stopsounds") end end hook.Add("OnPlayerChat","Kill / Toggle Console / Stopsounds",ChatCommands) end[/LUA] Everything is ok, even the "showconsole", but there is a problem, I fail every time to set the parameter of "con_enable". Could you help me? [editline]04:44PM[/editline] Crap, I succeeded to correctly write the LUA. But I got this : RunConsoleCommand: Command is blocked! (con_enable) So, no way, we can't force the client to open the console...
Sorry, you need to Log In to post a reply to this thread.