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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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 |
|
|
|
| 19 Jul 2012 09:05 AM |
~ if string.find(msg:lower(), "walkspeed/" == 1 then local command, player, value = string.match(msg, "(.+)/(.+)/(.+)") ~ |
|
|
| Report Abuse |
|
|
|
| 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
|
  |
| Joined: 05 Nov 2009 |
| Total Posts: 15444 |
|
| |
|
su8
|
  |
| Joined: 06 Mar 2009 |
| Total Posts: 6334 |
|
| |
|
oxcool1
|
  |
| Joined: 05 Nov 2009 |
| Total Posts: 15444 |
|
| |
|
|
| 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 |
|
|
|
| 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 |
|
|