Chat commands

How would I make something like !help run a command in console?

Use this.

Sorry I need more then that… How would I get what a player has said…

PlayerSay hook.

[lua]local chatcmd = “!slay”

function FindPlayer(name)
local ret = {}
for k , v in pairs(player.GetAll()) do
if string.find(string.lower(v:Nick()) , string.lower(name)) then
table.insert(ret , v)
return ret

function SlayPeople(pl , text , team , dead)
if pl:IsAdmin() then
if string.sub(string.lower(text) , 0 , string.len(chatcmd)) == chatcmd then
local players = {}
for k , v in pairs(string.Explode("," , string.sub(text , string.len(chatcmd)))) do
if FindPlayer(name) then
table.insert(players , FindPlayer(name))

		local pls = {}
		for a , b in pairs(players) do
			if type(b) == "table" then
				for c , d in pairs(b) do
					table.insert(pls , d)
		local names = {}
		for k , v in pairs(pls) do
			table.insert(names , v:Nick())
		for k , v in pairs(player.GetAll()) do
			v:ChatPrint("Admin "" slayed "..table.concat("," , names))

hook.Add(“PlayerSay” , “Slay” , SlayPeople)[/lua]

Untested messy example.

You need to hook into **[Gamemode.PlayerSay](** to get what a player has said. Then you need to check if the text contains the chatcommand and, if so, call the function.



Should be less messy example:

[lua]local function Stuff(ply, text)
local cmd = string.Explode(" ", text)[1]
if cmd == “!stuff” then – If the player said !slay <anything> then:
ply:Slay() – Kill him
ply:ChatPrint(string.sub(string.len(cmd) + 2, string.len(text))) – Print what he said after !slay, like if i did !slay minge then it would print minge
ply:ConCommand(“say”, “hello! i just said !stuff”)
return “” – What it should replace text with, in this case if we say !stuff it will hide it, if this was: return “foo” then it would be Minge: foo instead of Minge: !stuff, returning an empty string means it hides the message
hook.Add(“PlayerSay” , “Stuff” , Stuff) – Hook it[/lua]

Basic chatcommand stuff, i hope the comments didnt get too messy


holy shit they got too messy

You’re attempting to compare a table (cmd) o a string on line 3.
It also wouldn’t slay anyone but yourself. You didn’t do anything to check who the second argument was.

Basically just use the first example. It works perfectly.

Fixed mine, first example works but its very messy

There’s a reason I made this.