Madified
|
  |
| Joined: 19 Apr 2011 |
| Total Posts: 5292 |
|
| |
|
|
| 03 Dec 2013 09:41 AM |
basically search for patterns.
Example:
function locate(sub) pla = {} for i, v in next, game.Players:GetPlayers() do for x in string.gmatch(sub, "%w+") do if v:Find(x) then table.insert(pla, v) end end end |
|
|
| Report Abuse |
|
|
|
| 03 Dec 2013 09:43 AM |
I don't know, but this is how I would do it:
Let's say 'name' is the variable that contains the current fragment of a name. For this example, let's say it is 'cra' and I happen to be in the game:
-- Assuming variable 'name' equals 'cra' (name = "cra")
local player = nil for _,p in pairs(game.Players:GetPlayers()) do local nameFragment = p.Name:sub(1, #name):lower() if (nameFragment == name:lower()) then if (player) then player = nil print("Ambiguous") break end player = p end end
Put into english: - Scan through all players - For each name, get the substring based on the length of the name fragment to test - Compare the player's name with the name fragment - If a match is made, set variable 'player' to that player - CONDITION: If a match is made, but 'player' was already set, this means that there is MORE than 1 match, meaning the command should not go through since more than 1 player could apply to the name fragment. |
|
|
| Report Abuse |
|
|
koen500
|
  |
| Joined: 23 Feb 2011 |
| Total Posts: 2277 |
|
|
| 03 Dec 2013 09:49 AM |
They do it like this:
Get the max lenght of the string. Make any possible number combination between 1 and the max lenght. Take a part of the string with :sub() Check if that is what the player entered. |
|
|
| Report Abuse |
|
|