Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I get multiple players from a string with , separating?

Asked by
trecept 367 Moderation Voter
6 years ago

I'm making an admin script similar to Kohl's admin, and I'm having trouble with this. Currently I have a find player function where I can put in something like "t" and it'll return a player who's name begins with t. As well as "all" returning all players. If something like john,it,ra is given (three names of players), how do I remove the , commas and then run the function with the three names given? I'm not sure if it's something to do with string.match since I've used it before but don't know how to do the function for all three names, or if more are given like y,y,y,y,y

0
Put your code in on what you tried. farrizbb 465 — 6y
0
And explain your question better. farrizbb 465 — 6y

1 answer

Log in to vote
2
Answered by 6 years ago
Edited 6 years ago

Here's a basic solution:

local str = "builderman, telamon, merely"
local Players = {}

for name,_ in str:gmatch("[^,]+") do
    Players[#Players+1] = name:gsub("%s", "")
end

Uses a mix of a few examples from the wiki. Including sets, anchors, and quantifiers.

You can run a function with the "Players" table like so:

-- If you have specified parameters.
function foo(a, b, c)
    print(a, b, c)
end
foo(unpack(Players))

-- If you want to send the table directly.
function foo(Players)
    for _,player in pairs(Players) do
        print(player)
    end
end
foo(Players)
Ad

Answer this question