• Help on a script to make the server answer to strings
    4 replies, posted
I want to make the server reply so a player says something like server and it will run the command say Yes playername, how can I help so the output is Console:Yes Banhammer, how can I help and everyone can see it. Also I will want to add commands that god the player like (ulx god ply) If you know how I can do this please let me know. This is what I have so far [CODE] if (SERVER) then hook.Add( "PlayerSay", "Suicidehook", function( ply, text, team ) if ( string.sub( text, 1, 4 ) == "kill" ) then ply:Kill() end end ) end if (CLIENT) then hook.Add( 'OnPlayerChat', 'Test', function( ply, txt, team, dead ) txt = string.lower( txt ) -- Make the chat message entirely lowercase if txt == 'server' and ply == LocalPlayer() then -- You have to check the player chatting is LocalPlayer() since this hook gets called whenever anyone chats for k, ply in pairs( player.GetAll() ) do ply:ChatPrint( 'Yes ', ply:Nick(), ', how can I help you?' ) end return true -- cancel your text end end [/CODE]
If you want to send the text to everyone, you shouldn't be using a clientside hook. Here's a simple framework you could use. Store a table of possible commands on the server, then all you need to do search the table when a player talks, and call the function if one exists: [lua]local commands = { ['!kill'] = function( ply ) ply:Kill() end, ['!hello'] = function( ply ) for k, p in pairs( player.GetAll() ) do p:ChatPrint( 'Hello, '.. ply:Nick() ..', how can I help?') end end, } hook.Add( 'PlayerSay', 'CommandHook', function( ply, text ) if commands[ text ] then commands[ text ]( ply ) return '' end end )[/lua]
No I meant so it runs the command on the server console so it runs "say Hello Banhammer" Output: (Console):Hello Banhammer
[QUOTE=Banhammer01;50721348]No I meant so it runs the command on the server console so it runs "say Hello Banhammer" Output: (Console):Hello Banhammer[/QUOTE] [CODE] hook.Add("PlayerSay","djehegsj",function(ply, text) if string.sub(0,6, text) === "!server" then RunConsoleCommand("say","Hello "..ply:Nick()) end end) [/CODE] Untested
Thanks danker pepers after I fixed a few errors I managed to get it to work now I just need suggestions for commands to include
Sorry, you need to Log In to post a reply to this thread.