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

String manipulation for admin commands?

Hello,

I am trying to make some custom admin commands and I'm hoping to do it in such a way you can type sentences, but by using string manipulation it'd still be able to recognise the command.

For example, let's say I had a "shoot" command.

I'd want to say either: 'shoot at my friend bob123', 'aim at my friend bob123' or 'shoot at my enemy bob123' but would still get the words Shoot/Aim and his Username recognising it as a command and who to do it to.

I find it a lot more piratically than using the normal string.sub of 'shoot user'.

I've tried looking around with string.match/gmatch and string.find but I'm not entirely sure how they'd go hand in hand on making this.

Thanks in advanced.

1 comment

0

Practical*

1 answer

✓ Accepted answer

The idea is kind of simple! Basically what we wanna get from the command is a "task" of some sort and a player's name, so what we could do is have a table containing the tasks and game.Players:GetPlayers(), a table containing all players. We would loop through each of these two things, and each time we check if there is a valid task that exists, and check if there was a name in the command that corresponds with one of the players's name. So first we see the task we have, than find the player we want to effect.

local tasks = {"shoot", "aim", "kill"}

local task
local target
 
for __, v in pairs(tasks) do
	if message:match(v) then --remember :match will return nil if there was nothing matched
		task = v
		for _, p in(game.Players:GetPlayers()) do
			if message:match(p.Name) then
				target = p
				break --we stop the loop so it always picks just the first found name
			end
		end
	end
end
		

You can get so creative with string manipulation! Just open your mind Here is a nice article on some advanced string wizardry. (although wiki is currently down)

2 comments

0

Thanks so much, you may have just saved me a lot of time!

0

Np!

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