Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to make advanced chat commands? [SOLVED]

Asked by 8 years ago
Edited 8 years ago

I want to be able to make chat commands that work with multiple parameters. I can do single parameter commands, such as: /kick <plr> or /create <name>, but I want to be able to things such as: /add <plr> <name> or /ban <plr> <name>. I'm trying to accomplish this for my universe place, where each player can have their own place, but also be able to control who can come in it. Much like VIP servers, but more controlled in my honest opinion. :)

0
If IDidMakeThat answered your question, then why not hit the accept answer button below his name? M39a9am3R 3210 — 8y
0
It wasn't an option when I responded. :/ TestingPlace1337 51 — 8y

1 answer

Log in to vote
2
Answered by 8 years ago

You could write a function which separates the input into a table of values (so for example "/kick <plr>" would produce {"/kick", "<plr>"}) and then work on those values. An example of such a function (which is probably much less efficient than what it could be; there are probably better examples out there) is this:

function Split(input)
    local CurrentWord, ToReturn = "", {}
    for i = 1, #input do
        if input:sub(i, i) == " " and CurrentWord ~= "" then
            table.insert(ToReturn, CurrentWord)
            CurrentWord = ""
        else
            CurrentWord = CurrentWord .. input:sub(i, i)
        end
    end
    table.insert(ToReturn, CurrentWord)
    return ToReturn
end

I'm assuming you know how to make simple chat commands.

0
You are so helpful! :) I thank you very much as in my almost 7 years of scripting, I never thought to do it that way! :) TestingPlace1337 51 — 8y
Ad

Answer this question