xXGhostXx Posted August 25, 2020 Share Posted August 25, 2020 (edited) Hello, i want find player with similar names and print names in a list ! My find player function : function findPlayer( partofname ) local player = getPlayerFromName ( tostring(partofname) ) if player then return player end for _, player in pairs( getElementsByType 'player' ) do if tonumber(getElementData(player,"id")) == tonumber(partofname) then if getElementData(player, "loggedIn") == true then return player end end end for _, player in pairs( getElementsByType 'player' ) do if string.find ( string.gsub ( getPlayerName ( player ):lower( ), "#%x%x%x%x%x%x", "" ), partofname:lower( ), 1, true ) then if getElementData(player, "loggedIn") == true then return player end end end end Do you have an idea or opinion ? Edited August 25, 2020 by xXGhostXx Link to comment
nikitafloy Posted August 25, 2020 Share Posted August 25, 2020 Use regulars: string.match For example Link to comment
xXGhostXx Posted August 25, 2020 Author Share Posted August 25, 2020 1 minute ago, nikitafloy said: Use regulars: string.match For example No i want when use this function player name field if several similar names are found, they should be in the table. Link to comment
Moderators Patrick Posted August 25, 2020 Moderators Share Posted August 25, 2020 (edited) Just insert the player's element into a table instead of return it immediately. And return this table at the end. -- SHARED function findPlayers(part) local found = {} local players = getElementsByType("player") for i = 1, #players do local player = players[i] if tonumber(part) and getElementData(player, "id") == tonumber(part) and getElementData(player, "loggedIn") then table.insert(found, player) else local part = tostring(part):lower() local name = getPlayerName(player):lower():gsub("#%x%x%x%x%x%x", "") if name:find(part) then table.insert(found, player) end end end return found end Edited August 25, 2020 by Patrick 1 Link to comment
nikitafloy Posted August 25, 2020 Share Posted August 25, 2020 1 hour ago, Patrick said: Just insert the player's element into a table instead of return it immediately. And return this table at the end. -- SHARED function findPlayers(part) local found = {} local players = getElementsByType("player") for i = 1, #players do local player = players[i] if tonumber(part) and getElementData(player, "id") == tonumber(part) and getElementData(player, "loggedIn") then table.insert(found, player) else local part = tostring(part):lower() local name = getPlayerName(player):lower():gsub("#%x%x%x%x%x%x", "") if name:find(part) then table.insert(found, player) end end end return found end getElementData(player, 'id') can be nil Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now