|
| 18 Mar 2014 11:51 PM |
You're welcome.
function findPlayer(search) for _,v in pairs(game.Players:GetPlayers()) do if v.Name:lower() == search:lower() then return v
elseif string.sub(v.Name:lower(), 1,#search) == search:lower() then return v end end end |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 18 Mar 2014 11:53 PM |
Here, because shorter
function findPlayer(search) for _, v in pairs(game.Players:GetPlayers()) do if v.Name:sub(1, #search):lower() == search:lower() then return v end end end |
|
|
| Report Abuse |
|
|
jakej78b
|
  |
| Joined: 09 Mar 2011 |
| Total Posts: 813 |
|
| |
|
| |
|
|
| 19 Mar 2014 09:33 AM |
@cnt But you didn't check to see if there is a player whose name is search. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 19 Mar 2014 09:38 AM |
| why would that matter? Either way if they put in the full name they still get the player and you can enter search just fine |
|
|
| Report Abuse |
|
|
|
| 19 Mar 2014 09:42 AM |
| What if there is a player named Player1 and a player named Player12. If you searched for "Player1", it would be ambiguous and may return the wrong player. Therefor, you check if the player's name IS search first. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
| |
|
|
| 19 Mar 2014 09:55 AM |
| Yes. That particular part of the script is very important for the admin commands I'm working on. |
|
|
| Report Abuse |
|
|
|
| 19 Mar 2014 10:13 AM |
So all you have to do is call findPlayer()? So like,
findPlayer("Aesthetical")
|
|
|
| Report Abuse |
|
|
|
| 19 Mar 2014 10:14 AM |
findPlayer("Aesthetical"):Kick()
Yep. That would kick you. |
|
|
| Report Abuse |
|
|
| |
|
|
| 19 Mar 2014 10:15 AM |
Let me post the EXACT function from my admin commands script.
function findPlayer(search) for _,v in pairs(game.Players:GetPlayers()) do if v.Name == search then return v else if string.sub(v.Name, 1,#search):lower() == search:lower() then return v end end return nil end |
|
|
| Report Abuse |
|
|
|
| 19 Mar 2014 10:16 AM |
| Okay. Well this will be useful in he future. |
|
|
| Report Abuse |
|
|
|
| 19 Mar 2014 03:53 PM |
umg a script.. that finds the player.. this was easier than i thought. can i copy plox? |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 19 Mar 2014 05:35 PM |
| You should make it more consistent though, like you are using methods and functions instead of just either one or both (string.sub(blah:lower())) just seems weird to me. |
|
|
| Report Abuse |
|
|