Alias support for commands

Although at this point it’s getting kinda complicated, you might want to just have a function for finding a command from it’s alias by searching through commands, like Kaiden suggested

Yes, I’m aware, but another issue will come if I do that.
I would need the aliases to be able to get to the Execute function somehow.

EDIT: Oh, but I don’t think concat even works on dictionaries in the first place?

This was just a test, it serves no functionality at the moment. Just a test command.

CommandsManager.Commands[FixedCommand].Execute won’t support aliases when indexing it like that, so no, it won’t work because it relies the command to be the command’s name, not any alias of it.

I would need to create another command just to add aliases if I want it to work like that, sadly.
Or, if it were possible to assign multiple strings to it, that would work too.

Oh sorry, forgot to change that part. Simply change CommandsManager.Commands[FixedCommand] to Value.

Player.Chatted:Connect(function(Message)
		local Args = Message:split(' ')
		local Command = Args[1]
		local FixedCommand = Command:gsub(CommandsManager.Settings.Prefix, ''):lower()
		
		for Index, Value in pairs(CommandsManager.Commands) do
			local Execute
			if FixedCommand == Index or table.find(Value.Aliases, FixedCommand) then
				Execute = Value.Execute
				Execute(Player, Args)
				break
			end
		end
	end)

Well, no. Execute is outside of the aliases. That wouldn’t work.
If that were to work, I’d have to copy-paste the execute inside the aliases part, which might create another problem if I don’t include the actual command name in there as well.

Value would be the table. If you didn’t notice, Index would be the command name that references the table and Value would be the table itself.

Still, read my edited post above.

You really didn’t read your script again, did you?

You go through the table of all Commands with the for loop.

Index would be commands and Value would be the table that commands equals, being this:

Aliases, Description, AND Execute are all under and defined INSIDE of the table.

That still wouldn’t work, and it doesn’t work like that, unfortunately.

Honestly, just try the script, and don’t say it’s wrong UNTIL you try it. You keep saying it won’t work, what am I supposed to say if you won’t even listen to what I have to say? I’m not gonna go into this and keep responding. It’s quite literally almost 4 am for me and I’m trying to help but you won’t even take into account what I am saying.

Honestly, just try the script, and don’t say it’s wrong UNTIL you try it.

Knew before, and after. Result: Doesn’t work.
Perhaps you could try it yourself before posting? Just a tip, instead of arguing over it.

Alright, if it’s gonna be like that, I tested it for you. And yes, it did work quite well.


Now please, stop trying to fight about it. Life lesson: listen to people and try things out before saying it won’t work.

1 Like

I appreciate the help from you guys, however - it seems like I have found my own solution to this problem.

Why not

for i, cmd in pairs(commandsManager) do
    if table.find(cmd.Aliases, fixedCommand) then
        -- run the command
        break
    end
end

Also instead of using a dictionary just use a simple array:

{"c", "cmds"}

Solid suggestion, and I appreciate it, however - I redid my script and made it less complex, and along the way I found my own solution to the problem.

Thanks anyways!

for i, cmd in pairs(commandsManager) do
if table.find(cmd.Aliases, fixedCommand) then
– run the command
break
end
end

Both yes and no, but not what I prefer.

{“c”, “cmds”}

The issue with this is that it’s a value, and the index would be something like: [1] = ‘c’, [2] = ‘cmds’
The only way to bypass it is by giving it a name so it can be referenced.

There is completely no issue with what he recommended. This is completely why I recommended using table.find() and honestly saves the hassle of referencing it. In fact that’s what I used in the first solution that you didn’t accept for absolutely no reason.

table[index] as you did and table.find(table, commandName) as I was suggesting would do the same thing

local Array = {
    ["c"] = "c"
}

Array["c"] -- = c so true
local Array2 = {"c"}

table.find(Array2, "c") -- = true

Both will return true in an if statement but the second one is more optimized because making a dictionary just to index a string when you can achieve the same by putting the string in a simple array is useless

It searches by index, not value. That would be the problem here, so does table.find().

No, table.find doesn’t search for index, it searches for value, which is why it is fine to do it with an array like this:

{'c', 'cmds'}

I noticed I the progress when testing around with table.find. I can definitely replace that part.

And, here’s what I came up with instead, which was my original idea around 5 hours ago.

if (FixedCommand == Index or FixedCommand == Value.Aliases[FixedCommand]) then

(Because table.find is a bit stubborn, I chose not to implement it, due to it not working.)