Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

I'm having trouble how to make "intelligent admin commands"?

So I was making my own admin commands and I just figured out a new problem was that what if a command needed more information to execute it?

e.g: If a player executes a music command, the scripts are gonna need to know what the SoundId is and where to play it and even when to stop all inside a player's chat message. Some commands need different amounts of information to fully execute the command.

Take a kick command for example. It needs two pieces of information, the player to kick and what to say in the "you got kicked" message, while the music command above needs three pieces of information.

The problem is how do I know when certain commands needs more information? My code splices the chat message sent by a player by spacing using a string pattern.

What my system basically does:

  • If it compares a string command with part of the player's chat message
  • Grabs the index of that string command that is inside of a table
  • Executes the index inside a table full of running the actual commands

I have functions that execute based on commands like as shown:

local RunFunctions = {

	function(Player, KickMessage) -- kick function

	end,
	
	function(SoundId, StopTime, Part) -- sound command, index: 2
		
	end

}

local Commands = {
	"/kick"
	"/playsound" -- index: 2

}

for i,v in pairs(Commands)
	if FirstWordOfChatMessage == v then
		RunFunctions[i]()
		return
	end
end

My system looks like its challenging to add in those extra bits of information. I don't know what an actual admin command pack actually works by but I'm creating this without prior knowledge to challenge myself. I just need some help on the way. Sorry if this is all too confusing I'm not sure how to explain it properly.

1 answer

✓ Accepted answer

I remember making something like this a while ago. I don't think i have the script left, but i can roughly explain how i did it.

  • I first created a table containing all of my commands.
local commands = {
	kick = function(username,message)
		-- do something..
	end,
	
	playSound = function(soundId)
		-- do something..
	end
}
  • I then created a event which would trigger whenever the player said something in the "chatted".

  • Once the player chatted i would take their message and split it using "string.split". The function "string.split" has two parameters, the string, and what character it would split the string. So if i did the following: string.split("hello world !"," ") it would return a table looking like this: {"hello","world","!"}

  • I would then take the first string from the split table and check if that exists as a command.

  • And lastly, if it the first string turned out to exist in our "commands" table i would pass the rest of strings.

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(msg)
		local strings = msg:split(" ")
		local command = commands[strings[1]]
		
		if (command) then
			table.remove(strings,1)
			command(unpack(strings))
		end
	end)
end)

I haven't tested if this would work, so let me know if you get any errors.

1 comment

0

Your system is good and I now use it but what if I want to include "player objections" like "/kick me" or "/kick others". How should I make sure that a command doesn't require one of those player objections?

This discussion is preserved as it was. New answers, comments, and votes are closed.