What I want to accomplish:
So basically, I use CMDR for my admin panel needs and I was wanting to make it so when I type in player names, I don’t have to input my whole roblox username and I could just input me. However I don’t know how I could accomplish that and how to script that in. Here are the scripts I want to rewrite to accomplish that:
Players Module Script:
local Util = require(script.Parent.Parent.Shared.Util)
local Players = game:GetService("Players")
local playerType = {
Transform = function (text)
local findPlayer = Util.MakeFuzzyFinder(Players:GetPlayers())
return findPlayer(text)
end;
Validate = function (players)
return #players > 0, "No player with that name could be found."
end;
Autocomplete = function (players)
return Util.GetNames(players)
end;
Parse = function (players)
return players[1]
end;
Default = function(player)
return player.Name
end;
}
return function (cmdr)
cmdr:RegisterType("player", playerType)
cmdr:RegisterType("players", Util.MakeListableType(playerType))
end
The “Util” function:
function Util.MakeFuzzyFinder(setOrContainer)
local names
local instances = {}
if typeof(setOrContainer) == "Enum" then
setOrContainer = setOrContainer:GetEnumItems()
end
if typeof(setOrContainer) == "Instance" then
names, instances = transformInstanceSet(setOrContainer:GetChildren())
elseif typeof(setOrContainer) == "table" then
if
typeof(setOrContainer[1]) == "Instance" or typeof(setOrContainer[1]) == "Enum" or
(typeof(setOrContainer[1]) == "table" and typeof(setOrContainer[1].Name) == "string")
then
names, instances = transformInstanceSet(setOrContainer)
elseif type(setOrContainer[1]) == "string" then
names = setOrContainer
elseif setOrContainer[1] ~= nil then
error("MakeFuzzyFinder only accepts tables of instances or strings.")
else
names = {}
end
else
error("MakeFuzzyFinder only accepts a table, Enum, or Instance.")
end
-- Searches the set (checking exact matches first)
return function(text, returnFirst)
local results = {}
for i, name in pairs(names) do
local value = instances and instances[i] or name
-- Continue on checking for non-exact matches...
-- Still need to loop through everything, even on returnFirst, because possibility of an exact match.
if name:lower() == text:lower() then
if returnFirst then
return value
else
table.insert(results, 1, value)
end
elseif name:lower():sub(1, #text) == text:lower() then
results[#results + 1] = value
end
end
if returnFirst then
return results[1]
end
return results
end
end
--- Takes an array of instances and returns an array of those instances' names.
function Util.GetNames(instances)
local names = {}
for i = 1, #instances do
names[i] = instances[i].Name or tostring(instances[i])
end
return names
end