Jump to content

Help with custom chat commands


DREFTHUN

Recommended Posts

I made a custom chat, and I made it to recognize commands by using

if string.sub(guiGetText(chatGUI),1,1) == "/" then

It's all good, but then I can't get the arguments server side.

Like when I type /mute Player12 30, I don't know how to seperate them, in 2 arguments.

I just need a little help to get started with.

Link to comment

Try something like this.
 

-- NOTE This code is not tested and may need to be edited to work properly.

local symbol = '/'
local commands = {
    'help',
    'commands'
}

addEventHandler('onPlayerChat',root,function(message)
    local textTable = split(message,' ')
    for k=1,#textTable do
        for l=1,#commands do
            if textTable[1] == symbol..commands[l] then
                table.remove(textTable,1)
                triggerEvent(commands[l],root,source,textTable)
            end
        end
    end
end)

for i=1,#commands do
    addEvent(commands[i])
end

addEventHandler('help',root,function(source,payload)
    outputChatBox('Use /commands for a list of commands.',source)
end)

addEventHandler('commands',root,function(source,payload)
    outputChatBox('Commands: '..table.concat(commands,', '),source)
end)

 

  • Like 1
Link to comment
  • 3 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...