DREFTHUN

Help with custom chat commands

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.

Share this post


Link to post

function yourFunctionName (thePlayer,cmd,argument1,argument2)

-- Your Code

end

addCommandHandler ("mute",yourFunctionName)

Share this post


Link to post

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

Share this post


Link to post

Thank you IIYAMA! Your reply was helpful!

ShayF Yeah, it's good, but when I want to type like /mute DREFTHUN 34 that script won't seperate the arguments.

Anyway, thanks! I'm all good now.

Share this post


Link to post

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.