Creating Admin Commands?

Hello, am working on my own Admin commands script - I’ve no issues other than when it comes to initiate the command;

Currently it uses a :FindFirstChild, but because of this the Players name has to be in-full and spelled EXACT. Was wondering how I would go about setting it up to ignore capital letters, and to also shortening it so that if I used something like “/Kill Kos” instead of “/Kill KossmoZ” the same effect would apply.
Thank you.

3 Likes

You can use string.lower() before comparing usernames to ignore capitalization.
For fuzzy name matching, you might want to look at the Levenshtein distance algorithm. In a nutshell, it will return a number that basically represents how different two strings are. An implementation in Lua can be found here.

I’d use string.match(), see if it matches with a players username in “Players”.

https://developer.roblox.com/articles/string-patterns-reference

1 Like

Whyyy would you use some levenshtein algorithm for such a simple thing?!
Why not just do something like

local plrs = game:GetService("Players")

local function GetPlayers(arg, plr)
    local t = {}
    if arg == "me" then
        return {plr}
    elseif arg == "all" then
        return plrs:GetPlayers()
    elseif arg == "others" then
        for i,v in pairs(plrs:GetPlayers()) do
            if v ~= plr then
                table.insert(t, v)
            end
        end
        return t
    else
        for i,v in pairs(plrs:GetPlayers()) do
            if v.Name:lower():sub(1, #arg) == arg:lower() then
                table.insert(t, v)
            end
        end
        return t
    end
end

--then in the kill command
for i,v in pairs(GetPlayers(args[1], plr)) do
    if v.Character then
        v.Character:BreakJoints()
    end
end
1 Like

One way to make it ignore caps is by using

string.lower(StRIng)

output: string

soo you can also use string:sub() to get a section of your string

Here’s a forum on string: Forum

There is a topic on it that may help you.
If you want a pre-made framework for admin commands I suggest you use Sceleratis’s Open Admin project.

Levenshtein allows you to make typos and approximate usernames. Do you really want to try and type out “jsfg5fhgaaaaaaaaaaa” when you could instead just type “aaaaaaaaa”? Or retype a long command on a player because you made a typo in their name? Setting an appropriate distance threshold allows you to get the username partially correct.

Levenshtein is not appropriate for processing a submitted command because it may select a player that the user did not intend. The proper use-case is for providing suggestions (e.g. valid usernames) within the command input context rather than the command processing stage.

8 Likes