SN0X
|
  |
| Joined: 24 Oct 2011 |
| Total Posts: 7277 |
|
|
| 03 Feb 2012 12:01 PM |
if string.lower(string.sub(c,0,7)) == "health/" and string.len(c) > 7 then for l = 1, string.len(c) - 8 do if string.sub(c,l,l+1) == "/" then local it = l end
end local gch = game.Players:GetChildren() for i = 1, #gch do if string.lower(string.sub(gch[i].Name,0,string.len(c)-it)) == string.lower(string.sub(c,it+1,string.len(c))) then gch[i].Character.Humanoid.MaxHealth = string.sub(c,l,string.len(c)) gch[i].Character.Humanoid.Health = string.sub(c,l,string.len(c)) end end end
c is chat, it is in a chatted script.
I want it so that you could say "health/s/1000" and who ever's name begins with "s" gets 1000 health and maxhealth, but it won't work (I'm making an admin script).
Help please. |
|
|
| Report Abuse |
|
|
su8
|
  |
| Joined: 06 Mar 2009 |
| Total Posts: 6334 |
|
|
| 03 Feb 2012 12:05 PM |
| http://wiki.roblox.com/index.php/String_Patterns |
|
|
| Report Abuse |
|
|
SN0X
|
  |
| Joined: 24 Oct 2011 |
| Total Posts: 7277 |
|
|
| 03 Feb 2012 12:12 PM |
| I've read that before. I just get confused doing these sort of things, that's why I'm asking for help. |
|
|
| Report Abuse |
|
|
SN0X
|
  |
| Joined: 24 Oct 2011 |
| Total Posts: 7277 |
|
| |
|
|
| 03 Feb 2012 01:02 PM |
When I write commands, I use something like the following because I hate using string.sub too much:
local command = {} for chunk in c:gmatch("[^/]+") do table.insert(command, chunk) end
local name = command[2] or "" local amount = command[3] or 0
"It looks nice, but I sense a disturbing lack of Rainbow Dash and Fluttershy." |
|
|
| Report Abuse |
|
|
SN0X
|
  |
| Joined: 24 Oct 2011 |
| Total Posts: 7277 |
|
|
| 03 Feb 2012 03:56 PM |
Yeah, that would be great, but I don't understand it...it would b better for me if someone could just correct me.
Please?!?? |
|
|
| Report Abuse |
|
|
Mileshx3
|
  |
| Joined: 24 Dec 2011 |
| Total Posts: 412 |
|
|
| 03 Feb 2012 03:59 PM |
| agreed, i need the same thing as SN0X |
|
|
| Report Abuse |
|
|
SN0X
|
  |
| Joined: 24 Oct 2011 |
| Total Posts: 7277 |
|
| |
|
SN0X
|
  |
| Joined: 24 Oct 2011 |
| Total Posts: 7277 |
|
|
| 04 Feb 2012 02:34 AM |
I have recognized one problem, when finding the slash (/), string.sub(c,l,l+1) should be string.sub(c,l,l), but it still don't work.
|
|
|
| Report Abuse |
|
|
SN0X
|
  |
| Joined: 24 Oct 2011 |
| Total Posts: 7277 |
|
|
| 04 Feb 2012 03:16 AM |
Fixed all except this line:
if string.lower(string.sub(gch[i].Name,0,string.len(c)-(l-string.len(c)))) == string.lower(string.sub(c,8,it-1)) then
What should that be? |
|
|
| Report Abuse |
|
|
SN0X
|
  |
| Joined: 24 Oct 2011 |
| Total Posts: 7277 |
|
| |
|
DXPower
|
  |
| Joined: 21 Oct 2008 |
| Total Posts: 2866 |
|
|
| 04 Feb 2012 07:17 AM |
I'll give you my command I made a while ago:
if string.sub(string.lower(msg), 1,7) == "health/" then local q = string.gsub(string.lower(msg), "health/", "") --I removed the checkIfAdmin thing because you might want something custom there for who, much in string.gmatch(q, "(%w+)/(%w+)") do local found = find_Requested(who, speaker) if found ~= 0 then for i = 1, #found do local h = found[i].Character:FindFirstChild("Humanoid") if h~=nil then h.Health = much end end end end end
Please excuse me if there are any errors, I wrote it on the spot. I use that code for my Admin Commands, Person299 does these things so inefficiently.
Vote against SOPA! If we don't, then Ever ████ Will be Censored! So, let ████ vote ████ SOPA! [Free Fire ████!]
|
|
|
| Report Abuse |
|
|
DXPower
|
  |
| Joined: 21 Oct 2008 |
| Total Posts: 2866 |
|
| |
|
SN0X
|
  |
| Joined: 24 Oct 2011 |
| Total Posts: 7277 |
|
|
| 05 Feb 2012 02:34 AM |
Yes. It worked. But I'd rather do it myself...and I stopped posting here because I thought of how to fix it.
The annoying thing is though, I saved my admin commands with your health command, and now I have to either start from scratch or repair the one I posted on the forum with.
I'll start from scratch. It will only take about 3 or 4 mins. Thanks for help though. Also I normally accept help but only if I understand the script. As I do not, I am making my own. (I don't get string.gsub or chunks). |
|
|
| Report Abuse |
|
|
SN0X
|
  |
| Joined: 24 Oct 2011 |
| Total Posts: 7277 |
|
|
| 05 Feb 2012 02:37 AM |
| This is the bit I don't get about gmatch. It leaves me clueless, and from the article I read in the wiki, it explains everything but this: "(%w+)/(%w+)"). |
|
|
| Report Abuse |
|
|
DXPower
|
  |
| Joined: 21 Oct 2008 |
| Total Posts: 2866 |
|
|
| 05 Feb 2012 06:32 AM |
I will explain it. The (%w+)'s are captures. It will "capture" all the character's in that area. So, it does this:
-Looks for characters- -Passes over the /- -Looks for the rest-
I have a tutorial on captures in my models, it isn't mine, but I used it when I started to learn scripting:
Link: http://www.roblox.com/Learn-scripting-Advanced-item?id=43695776
If you open it up, then find the String Patterns tutorial, it will help you greatly. |
|
|
| Report Abuse |
|
|
SN0X
|
  |
| Joined: 24 Oct 2011 |
| Total Posts: 7277 |
|
|
| 05 Feb 2012 07:32 AM |
| Ok, thanks. For now I'll keep doing what I am currently doing in my admin commands, since I have about 15 so far, but if I am not satisfied or need to re-write all of them for some reason, I'll use that. |
|
|
| Report Abuse |
|
|
DXPower
|
  |
| Joined: 21 Oct 2008 |
| Total Posts: 2866 |
|
|
| 05 Feb 2012 12:23 PM |
| Well, you don't need to re-write anything at all, it's just my way of doing things. You CAN use Ctrl + H, which put's a Replace and a Replace With, that replaces things faster. |
|
|
| Report Abuse |
|
|
SN0X
|
  |
| Joined: 24 Oct 2011 |
| Total Posts: 7277 |
|
|
| 06 Feb 2012 01:54 AM |
Isn't that the same as Ctrl+V while somethings selected? I have tons of commands, and they all work differently, so I'd have to edit that script each time.
The way I'm doing it is fine by me...but thanks. |
|
|
| Report Abuse |
|
|