Chat Commands

If I want to add a chat command would I do something like…

chatcommand.Add

Or

AddChatCommand

It would be great if someone could help me with this.

Here, http://www.garrysmod.org/img/?t=dll&id=94917 that’s my chat command’s, feel free to remove or edit some.

But what you wanna do is make a Autorun server file, then at the top put


local function ISaid( ply, text, team, death )

/* and at the bottum of coarse */

end

Then to add something if they say you do:


       /* the 7 is how much letters there are in the command */
    if (string.sub(text, 1, 7) == "@delall") then
        ply:ConCommand("gmod_cleanup")
    end

So yea, if you need any help or have trouble add me on steam bro!

Here’s a semi easy way to do it.

[lua]
local Prefix = “/”
local Commands = {}

function ChatParse(pl, Text)
if (string.sub(Text, 1, 1) == Prefix) then
local exploded = string.Explode(" ", Text)
local cmd = string.sub(exploded[1], 2):lower()

    if (Commands[cmd]) then
        local Args = {}
        for k, v in pairs(exploded) do
            if (k > 1) then
                Args[k-1] = v
                end
            end
        Commands[cmd](pl, Args))
    else
        pl:ChatPrint("No such command")
        end
    return false
else
    return Text
    end    
end

hook.Add(“PlayerSay”, “ChatParsing”, ChatParse)

Commands[“kick”] = function(pl, Args)
– Command junk.
end
[/lua]

To make a command, look at how the kick command is made. Just a function placed inside the Commands table. Also, if you use this, make sure that the command’s name is lowercase, or else it wouldn’t be recognized.

EDIT: You could also make a function there that adds a command by, say, doing AddCommand(name, table) so that you can make commands from outside that file.