I’m making a console for executing commands, and this is the part that checks if the correct string is there:
for i, v in rc do
if not table.find(rc, string.match(cmd, v)) then game.ReplicatedStorage.Remotes.Console.MainEvent:FireClient(plr, true) sentCommand = nil else sentCommand = string.match(cmd, v) game.ReplicatedStorage.Remotes.Console.MainEvent:FireClient(plr, false) end
print(i)
end
It gets the values plr, and cmd from a remote event, the cmd value contains the full command as a string.
There is a table called “rc” which contains all the available commands. (rc is registered commands).
I only want it to detect if the string, like “exec” is at the beginning of the string, and if it doesnt contain any random words, like “armexec”. I want it to only detect if that only word is at the beginning of the string and it is the only word, with no additional things.
Might be confusing, but thats what im aiming for.
PS: Heres the “rc” table.
local rc = {
"setrolls";
"kickusr";
"shutdownsv";
"exec";
}
The following function returns true/false if it finds the small string inside the big one
function has_string(big_string, small_string)
local pattern = small_string
local range = string.find(big_string, pattern)
return range and true or false
end
I tested it with your case like this:
local rc = {
"setrolls";
"kickusr";
"shutdownsv";
"exec";
}
for _, str in pairs(rc) do
print(has_string("Lorem ipsum dolor sit amet, shutdownsv consectetur adipiscing elit. Nullam eget.", str))
end
I meant it like, if the user types for example “exec (parameters)”, it’ll execute, but if they type like “aexec (parameters)” it wont work. And also if its like “hello exec (parameters)” it also shouldnt work. It should only work if the string is at the beginning, and is the only word at the beginning.
I meant it like, if the user types for example “exec (parameters)”, it’ll execute, but if they type like “aexec (parameters)” it wont work. And also if its like “hello exec (parameters)” it also shouldnt work. It should only work if the string is at the beginning, and is the only word at the beginning.