|
| 17 Oct 2013 05:32 PM |
Whats the shortest best way to find a player for admin commands? Like
function FindPlayer(String) --Blah blah return {true/false, player object, number of players with that name} end
Later in the chat command
if string.sub(string.lower(Text),1,4) == "kill" then if FindPlayer(string.sub(Text,6)[1]) end --(Because we returned a table) if FindPlayer(string.sub(Text,6)[3] )== 1 then FindPlayer(string.sub(Text,6)[2].Character:BreakJoints() end end end |
|
|
| Report Abuse |
|
|
|
| 17 Oct 2013 05:33 PM |
| Oh and I know I could use some for loops and stuff for this but I heard one time there was like string.match to make it easier or something |
|
|
| Report Abuse |
|
|
wazap
|
  |
| Joined: 29 Jun 2007 |
| Total Posts: 23234 |
|
|
| 17 Oct 2013 05:44 PM |
game.Players:findFirstChild(nameHere)
Only way i can think of, assuming you dont just type in the first part of the name, otherwise you have to use for loops, no matter what. |
|
|
| Report Abuse |
|
|
wazap
|
  |
| Joined: 29 Jun 2007 |
| Total Posts: 23234 |
|
|
| 17 Oct 2013 05:47 PM |
as in candidates = {} for _, plyr in ipairs(game.Players:GetChildren()) do if (plyr.Name:match(theStuffYouChatted)) then table.insert(candidates, plyr) end if #candidates == 1 then return candidates[1] else return end end
|
|
|
| Report Abuse |
|
|
qrrrq
|
  |
| Joined: 27 Jan 2013 |
| Total Posts: 1252 |
|
| |
|
wazap
|
  |
| Joined: 29 Jun 2007 |
| Total Posts: 23234 |
|
|
| 17 Oct 2013 05:50 PM |
| ^Wouldnt work. Only works in LocalScript, and only returns the player that the LocalScript is in anyways. Not very helpful in admin commands. |
|
|
| Report Abuse |
|
|
qrrrq
|
  |
| Joined: 27 Jan 2013 |
| Total Posts: 1252 |
|
| |
|
|
| 17 Oct 2013 06:14 PM |
| It needs to work for shortened names, someone told me last time to use string.match but that was like a year ago and I don't know how |
|
|
| Report Abuse |
|
|
|
| 17 Oct 2013 06:42 PM |
Never mind, it was easier than I thought
FindPlayer = function(NameString) for PlayerIndex,Player in pairs (Game:GetService("Players"):GetChildren()) do if string.sub(string.lower(Player.Name),1,#NameString) == string.lower(NameString) then return {true, Player} end end return false end
Anyone see problems with this? |
|
|
| Report Abuse |
|
|