generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Finding a name

Previous Thread :: Next Thread 
chimmmihc is not online. 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
BothAngles is not online. BothAngles
Joined: 01 Dec 2011
Total Posts: 9604
06 Sep 2015 06:21 PM
Split string by space and loop through Players for each word
Report Abuse
morashsPeasant is not online. morashsPeasant
Joined: 06 Jan 2011
Total Posts: 4944
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 is not online. 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
BothAngles is not online. BothAngles
Joined: 01 Dec 2011
Total Posts: 9604
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
morashsPeasant is not online. morashsPeasant
Joined: 06 Jan 2011
Total Posts: 4944
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 is not online. 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
BothAngles is not online. BothAngles
Joined: 01 Dec 2011
Total Posts: 9604
06 Sep 2015 06:32 PM
http://wiki.roblox.com/index.php?title=String_patterns
Report Abuse
BothAngles is not online. BothAngles
Joined: 01 Dec 2011
Total Posts: 9604
06 Sep 2015 06:33 PM
Oh and change %a+ to %w+
:P
Report Abuse
morashsPeasant is not online. morashsPeasant
Joined: 06 Jan 2011
Total Posts: 4944
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 is not online. 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
BothAngles is not online. BothAngles
Joined: 01 Dec 2011
Total Posts: 9604
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
morashsPeasant is not online. morashsPeasant
Joined: 06 Jan 2011
Total Posts: 4944
06 Sep 2015 06:42 PM
Yeah, but return the players unformatted name. Instead of return Name:lower() just return Name
Report Abuse
morashsPeasant is not online. morashsPeasant
Joined: 06 Jan 2011
Total Posts: 4944
06 Sep 2015 06:43 PM
BothAngles, ninja'in since 1921
Report Abuse
chimmmihc is not online. 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
BothAngles is not online. BothAngles
Joined: 01 Dec 2011
Total Posts: 9604
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image