chimmmihc
|
  |
| Joined: 24 Jul 2014 |
| Total Posts: 2420 |
|
|
| 06 Sep 2015 06:19 PM |
How can I find a players name in a string? Need this for propmting players in game
ex: Players = {"dingy", "Doog", "Chimmihc", "chimmmihc"}
findname("dingy is dumb") == true, dingy
findname("doooog is dumb") == false, nil
|
|
|
| Report Abuse |
|
|
|
| 06 Sep 2015 06:21 PM |
| Split string by space and loop through Players for each word |
|
|
| Report Abuse |
|
|
|
| 06 Sep 2015 06:21 PM |
Players = {"dingy", "Doog", "Chimmihc", "chimmmihc"} local findThisString = "Doog"
for i,v in pairs(Players) do if v == findThisString then print("AAAAAAAAAH") end end
Like that? |
|
|
| Report Abuse |
|
|
chimmmihc
|
  |
| Joined: 24 Jul 2014 |
| Total Posts: 2420 |
|
|
| 06 Sep 2015 06:22 PM |
| Angles got it right, drop me that block angles? or tell me the procedure? |
|
|
| Report Abuse |
|
|
|
| 06 Sep 2015 06:29 PM |
local Players = {"dingy", "Doog", "Chimmihc", "chimmmihc"}
function findname(msg) for w in msg:gmatch("%a+") do for i,v in pairs(Players) do if w == v then return true end end end return false end
print(findname("dingy is dumb")) print(findname("doooog is dumb")) |
|
|
| Report Abuse |
|
|
|
| 06 Sep 2015 06:29 PM |
Players = {"dingy", "Doog", "Chimmihc", "chimmmihc"} local str = "Doog is cool!"
for s in str:gmatch("%w+") do for i,v in pairs(Players) do if string.lower(v) == string.lower(s) then print(v.. " is swag") end end end |
|
|
| Report Abuse |
|
|
chimmmihc
|
  |
| Joined: 24 Jul 2014 |
| Total Posts: 2420 |
|
|
| 06 Sep 2015 06:31 PM |
| Walk me through that, what is the funny % doohike your using. |
|
|
| Report Abuse |
|
|
|
| 06 Sep 2015 06:32 PM |
| http://wiki.roblox.com/index.php?title=String_patterns |
|
|
| Report Abuse |
|
|
|
| 06 Sep 2015 06:33 PM |
Oh and change %a+ to %w+ :P |
|
|
| Report Abuse |
|
|
|
| 06 Sep 2015 06:33 PM |
% is a magic character. There are a list of patterns that can be matched so %w+ means match any letters that come after one another and gmatch does that for the whole sentence. That was bad, here is a wiki page: http://wiki.roblox.com/index.php?title=String_pattern |
|
|
| Report Abuse |
|
|
chimmmihc
|
  |
| Joined: 24 Jul 2014 |
| Total Posts: 2420 |
|
|
| 06 Sep 2015 06:39 PM |
This look right?
function FindNameInString(Message) for String in Message:gmatch("%w+") do for Iteration, Name in pairs(game:GetService("Players") do if String:lower() == Name:lower() then return Name:lower() end end end return false end |
|
|
| Report Abuse |
|
|
|
| 06 Sep 2015 06:42 PM |
Missing closing parenthesis for pairs Not sure if you want to return a lowercase name instead of the original? |
|
|
| Report Abuse |
|
|
|
| 06 Sep 2015 06:42 PM |
| Yeah, but return the players unformatted name. Instead of return Name:lower() just return Name |
|
|
| Report Abuse |
|
|
|
| 06 Sep 2015 06:43 PM |
| BothAngles, ninja'in since 1921 |
|
|
| Report Abuse |
|
|
chimmmihc
|
  |
| Joined: 24 Jul 2014 |
| Total Posts: 2420 |
|
|
| 06 Sep 2015 06:47 PM |
Would this give me the right values? function FindNameInString(Message) for String in Message:gmatch("%w+") do for Iteration, Name in pairs(game:GetService("Players")) do if String:lower() == Name:lower() then return Name:lower() end end end return false end
function FindCmdInString(Message) for String in Message:gmatch("%w+") do for Iteration, Cmd in pairs(Commands) do if String:lower() == Cmd:lower() then return Cmd end end end return false end
function ChatCmdHandle(Message) local Cmd = FindCmdInString(Message); if Cmd then else return end local Name = FindNameInString(Message); if Name then else return end end
Im 88 lines in and I dont want a hiccup, havent pressed run yet |
|
|
| Report Abuse |
|
|
|
| 06 Sep 2015 06:49 PM |
for Iteration, Name in pairs(game:GetService("Players"):GetPlayers()) do
Also, be careful because you could run commands by accident Just something to keep in mind |
|
|
| Report Abuse |
|
|