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 » Scripting Helpers
Home Search
 

Re: string.sub/chatted

Previous Thread :: Next Thread 
Techwiz19 is not online. Techwiz19
Joined: 30 Jan 2011
Total Posts: 462
19 Jul 2012 08:20 AM
I was reading through person299's admin script, and i figured "Ok, well this is easy." However could someone explain to me how he detects things like
walkspeed/player/100
I understand the "walkspeed/" part, but how does he know the length of the player name, with the "100" after it? Here is a portion of the script.

if string.sub(msg,1,10) == "walkspeed/" then
danumber = nil
for i =11,100 do
if string.sub(msg,i,i) == "/" then
danumber = i
break
end end
if danumber == nil then
return
end
local player = findplayer(string.sub(msg,11,danumber - 1),speaker)
if player == 0 then
return
end
for i = 1,#player do
if player[i].Character ~= nil then
humanoid = player[i].Character:FindFirstChild("Humanoid")
if humanoid ~= nil then
humanoid.WalkSpeed = string.sub(msg,danumber + 1)
end end end end
Report Abuse
C0D3Y is not online. C0D3Y
Joined: 24 Jul 2010
Total Posts: 1692
19 Jul 2012 08:41 AM
What he's doing is continually checking to see if there is another "/". Then he sets the position of the "/" to a variable and continues with the string.sub from the position after the "/". Make sense? I think there's a more efficient way, but I never really looked into string patterns too much.
Report Abuse
Techwiz19 is not online. Techwiz19
Joined: 30 Jan 2011
Total Posts: 462
19 Jul 2012 08:47 AM
That helps, this mainly confuses me;

if string.sub(msg,i,i) == "/" then
danumber = i

wouldnt i just be the same number? (string.sub(msg, 7, 7))
then danumber would be the "/"?
Report Abuse
C0D3Y is not online. C0D3Y
Joined: 24 Jul 2010
Total Posts: 1692
19 Jul 2012 08:51 AM
Yeah, if you did msg = "abcdefghijklmnop" and then print(msg:sub(1,1)) It would print just "a" because it starts and ends at 1.
Report Abuse
velibor is not online. velibor
Joined: 24 Nov 2009
Total Posts: 1003
19 Jul 2012 08:51 AM
I would use learn string patterns first.

http://wiki.roblox.com/index.php/String_patterns

Velibor

Report Abuse
Techwiz19 is not online. Techwiz19
Joined: 30 Jan 2011
Total Posts: 462
19 Jul 2012 09:03 AM
I know string patterns, I was just confused about the script...
Report Abuse
MasterOfDeathOnes is not online. MasterOfDeathOnes
Joined: 21 Mar 2009
Total Posts: 6975
19 Jul 2012 09:05 AM
~
if string.find(msg:lower(), "walkspeed/" == 1 then
local command, player, value = string.match(msg, "(.+)/(.+)/(.+)")
~
Report Abuse
triston220 is not online. triston220
Joined: 08 Mar 2010
Total Posts: 1861
19 Jul 2012 09:12 AM
function split(str, delim, maxNb)
if string.find(str, delim) == nil then
return { str }
end
if maxNb == nil or maxNb < 1 then
maxNb = 0 -- No limit
end
local result = {}
local pat = "(.-)" .. delim .. "()"
local nb = 0
local lastPos
for part, pos in string.gmatch(str, pat) do
nb = nb + 1
result[nb] = part
lastPos = pos
if nb == maxNb then break end
end
if nb ~= maxNb then
result[nb + 1] = string.sub(str, lastPos)
end
return result
end

You could use a function like this instead.

It returns a table of strings.
Report Abuse
oxcool1 is not online. oxcool1
Joined: 05 Nov 2009
Total Posts: 15444
19 Jul 2012 09:15 AM
[ Content Deleted ]
Report Abuse
su8 is not online. su8
Joined: 06 Mar 2009
Total Posts: 6334
19 Jul 2012 09:18 AM
hehe mofo
Report Abuse
oxcool1 is not online. oxcool1
Joined: 05 Nov 2009
Total Posts: 15444
19 Jul 2012 09:24 AM
[ Content Deleted ]
Report Abuse
MasterOfDeathOnes is not online. MasterOfDeathOnes
Joined: 21 Mar 2009
Total Posts: 6975
19 Jul 2012 04:40 PM
@oxcool
that's how my father told me to do it, and he made his own programming language. I'm pretty sure it's a good way.
Report Abuse
MasterOfDeathOnes is not online. MasterOfDeathOnes
Joined: 21 Mar 2009
Total Posts: 6975
19 Jul 2012 04:43 PM
Though I did miss a bracket.

~
if string.find(msg:lower(), "walkspeed/") == 1 then
local command, player, value = string.match(msg, "(.+)/(.+)/(.+)")
~
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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