While creating my own admin system, I have come across an issue that could decide whether or not this will actually be an (functioning) admin system. While attempting to make a parse function to separate a command into three separate parts. Command, player(s), and message/value. The part that I am seeming to have the issue with is the player(s) and message/value. Say that I try to parse the message “kick Arcental,ROBLOX, Player1 Kicked from the game!” The names being the players and “Kicked from the game!” as the message. I originally try to split those three ways using string.split(cmd," ") but I realized the players could put a space in between the commas and it would split the player(s) section into multiple parts instead of the one. It would also split the message into countless parts. Any suggestions in which string function/pattern I could use to fix this?
The output on parsing the message string.split("kick Arcental,ROBLOX,Player1 Kicked from the game! This would work but I know others may use spaces right next to commas. The being split apart is the other issue.
The output on parsing the message string.split("kick Arcental, ROBLOX, Player1 Kicked from the game! I could see this partially working but I would need some way to tell the difference in which string is a player versus a message.
If you only did comma separated values, you could most likely get the values between 2 and however many players there are in the string. You could also split using ", ", meaning you could do the same thing I mentioned at the start.
You could do something like this:
--untested
local SplitMessage = string.split("kick Arcental, ROBLOX, Player1", ", ")
local Players = {}
if #SplitMessage > 2 then
for i = 2, #SplitMessage - 1 do
table.insert(Players, SplitMessage[i])
end
end
warn(string.format("Kicked %s from the game", string.gsub(unpack(Players), "%s", ", ")))
I see a couple things wrong with this. One, I tried the code but only outputs “Kicked ROBLOX from the game” and none of the other players. Two, if someone were to use a space before or after a comma and another comma with no space at all, then neither of those ways would work.
Yes, I see. I apologize for the mistakes. If you also wanted to added two ways to type the kick list, it would require some more scripting for it to work two ways or more.
I have created a script which basically does what you want, except it only has one command splitter.
You could add another, but it would take some extra work (which nobody wants to do unless they want something better).
--tested
local SplitMessage = string.split("kick Arcental, ROBLOX, Player1", ",")
local Command = string.match(SplitMessage[1], "[%w]+")
local Players = {string.sub(SplitMessage[1], #Command + 2, #SplitMessage[1])}
if #SplitMessage > 1 then
for i,v in ipairs(SplitMessage) do
if i ~= 1 then
local SubbedPlayer = string.gsub(v, "%s", "")
table.insert(Players, SubbedPlayer)
end
end
end
warn(string.format([[Used command "%s" on players]], Command))
for _,v in ipairs(Players) do
warn(v)
end
This fixed the first part of the issue but the other is separating the players from the kick message.
For example, if you had used a comma inside the message then would the message be split because of that comma? Or would it remain intact and leave the message alone.
The message will more than likely be different every time being that the admin chooses the message. The issue I was having before was you couldn’t differentiate between a player and the message based on how it was split.
The message would indeed be split due to a comma being there, so you would be able to split players like john,zach,me. If you wanted to differentiate a player between a message and the players, you would do something like subbing the last message (like how i did on the command variable). It should be really simple for what you’re trying to pull off.