Admin Command [ASK]

I have admin command and right now I can only run one command per chat, how to make we can run more than one command in just one chat like !kill abc !announce Hello or !kill abc;!announce hey, I think like in Adonis or BasicAdminEssentials, I forget.

1 Like

So this can be easily done especially with a command separator like the ; can we see your current code?

1 Like
Player.Chatted:Connect(function(Chat)
			if Chat:sub(1, 1) == "!" then
				Chat = Chat:sub(2)
				local Args = Chat:split(" ")
				for i, Command in pairs(Commands) do
					for i, Usage in pairs(Command.Usage) do
						if Args[1]:lower() == Usage then
							local args = {}
							for i = 2, #Args, 1 do
								table.insert(args, Args[i])
							end
							if Admins[Player.UserId]["ID"] >= Command.MinimumRank[1] then
								print(Admins[Player.UserId]["ID"])
								if Command.MinimumRank == 1 then
									LogCommand(Player, "!"..table.concat(Args, " "), "Easy")
								elseif Command.MinimumRank == 2 then
									LogCommand(Player, "!"..table.concat(Args, " "), "Medium")
								end
								local Call = Command.Callback(Player, args)
							else
								LogCommand(Player, "!"..table.concat(Args, " "), "Forbidden")
							end
						end
					end
				end 
			end
		end)

How you’d do that is by having a divider key that your message looks for.

Here’s an example;

local Command = string.split(CommandHere," | ")

Expected Outcome;
Whatever your command is, then it will split to the next command.

To continue this, you simply send what the command is like this;

local Command = string.split(CommandHere," | ")
for i,command in pairs (Command) do
	command()
end

1 Like

Wait, where should I put this in my code? Because I execute command on the part Command.Callback

1 Like

Before for i, Command in pairs (Commands)? Because Commands is lists of all my commands.

1 Like

I mean should I put this after Args = string.split and before for i, Command in pairs Commands or where should I put it.

1 Like

Or i should put before chat sub 1,1

1 Like

I suppose it’s before chat sub 1,1, in my idea it’s gonna be local cmds = string.split(“|”) from the chat
Then for i, cmd in pairs cmds do
If cmd sub 1,1 blablabla , same like my command now. Is it like this?

1 Like
Player.Chatted:Connect(function(Chat)
local cmds = chat:split(“|”)
for i, cmd in pairs cmds do
			if cmds:sub(1, 1) == "!" then
				cmds:sub(2)
				local Args = cmds:split(" ")
				for i, Command in pairs(Commands) do
					for i, Usage in pairs(Command.Usage) do
						if Args[1]:lower() == Usage then
							local args = {}
							for i = 2, #Args, 1 do
								table.insert(args, Args[i])
							end
							if Admins[Player.UserId]["ID"] >= Command.MinimumRank[1] then
								print(Admins[Player.UserId]["ID"])
								if Command.MinimumRank == 1 then
									LogCommand(Player, "!"..table.concat(Args, " "), "Easy")
								elseif Command.MinimumRank == 2 then
									LogCommand(Player, "!"..table.concat(Args, " "), "Medium")
								end
								local Call = Command.Callback(Player, args)
							else
								LogCommand(Player, "!"..table.concat(Args, " "), "Forbidden")
							end
						end
					end
				end 
			end
		end)

Something like this, sorry if the code isn’t proper i write this with phone.

1 Like

Ah it doesn’t work, so where should I put this.

1 Like

The hard thing I have announcement which keep detecting | too…

1 Like

Note

Real quick; there’s an edit button; image, please use this from now on instead of spamming your Forum post; that is technically against the rules to do.


Answer

I would recommend having the whole command finder/runner in a separate Function to make it more organized and then in your player.Chatted function; have a string separator that gets the message and detects whether there’s a | to separate commands, here’s an example of it;

Player Chatted Function

game.Players.PlayerAdded:Connect(function(plr)
	plr.Chatted:Connect(function(message)
		local noEmessage = string.split(message,"/e ")[2] or message
		local commandMessage = string.split(noEmessage, " ".. "Divider Key Here" .." ") or noEmessage
		for ind,command in ipairs (commandMessage) do
			--Run Command Function here.
		end
	end)
end)

I even added a the solution to make it so you can use /e with a command as well.

Your Replies

Use my code as an example, but to answer; you do the entire string.split variables before you run a check with your commands.

You have to have spaces between the " and the separator key, it would look like this;
" | ". This helps separate it from other forms of this key being used. It currently doesn’t work because you’re value is not in the right area at all. I don’t manipulate strings as you do, so my way will be different from your style so just go through and change things as you see fit.

Roblox just recently updated to a new Developer Hub site! Here’s where you learn all about strings and what to do with them; click me to view strings and how to manipulate them.


I have found the solution, yeah stupid me I don’t put space in between | lol

1 Like

What does /e for in your context. Well this is for bonus, your previous solution already be my solution.

1 Like

So, /e is what Roblox uses for default emotes; you can manipulate that feature to run commands in secret. i.e; i want to health someone 500 without anyone knowing, or send a server message without anyone knowing who sent the said message; you’d do: /e command here | command here

Okay, okay, but mine is work now, with your old solution, but may I ask I think the divider need to be with space right? like " ; " or " | ", it can’t without space like “;” or “|”?

1 Like

I recommend always having a space, as quoted here;

Oh yes so I think this is better, because if we don’t use like space, maybe in announcement command, people like to use helloguys; how are you the system gonna think it’s another command. Okay okay I see your point

1 Like