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 Help

Previous Thread :: Next Thread 
YaYaBinks3 is not online. YaYaBinks3
Joined: 05 Jun 2009
Total Posts: 2631
23 Aug 2012 01:35 PM
Hi all, I have a 'computer' script, that when a player (if they are an admin) say something like 'computer lock spawndoor' it will change the value in spawndoor to locked.
I have added prints to my script, but it still has not worked.
I am having trouble when using the lock command.
When I say computer lock[SPACE], the output prints 'Player Player has used the lock command'.
If I add something onto the command, it comes up with 'Player Player used a computer command'.

admins = {"YaYaBinks3","pspjohn1","Player"}
locks = {"spawndoor"}

    function onPlayerAdded(p)
    print("Player "..p.Name.." has entered.")
    for _,v in pairs(admins) do
    print("Got admins.")
    if p.Name == v then
    print("Player "..p.Name.." is recognized as an admin.")
    p.Chatted:connect(function(msg2)
    msg = string.lower(msg2)
    print("Player "..p.Name.." has chatted.")
    if string.sub(msg,1,9) == "computer " then
    print("Computer command")
    if string.sub(msg,10,15) == "lock " then
    print("Lock.")
    for _,xz in pairs(locks) do
    print("Got locks:")
    print(xz)
    if string.sub(msg,16) == xz then
    print("Found lock.")
    game.Workspace.Doors:findFirstChild(xz).Locked.Value = true
    end
    end
    print("Locked "..string.sub(msg,16)..".")
    elseif string.sub(msg,10,17) == "unlock " then
    print("Unlock.")
    for _,zx in pairs(locks) do
    print("Got locks:")
    print(xz)
    if string.sub(msg,18) == zx then
    print("Found lock.")
    game.Workspace.Doors:findFirstChild(zx).Locked.Value = false
    end
    end
    print("Unlocked "..string.sub(msg,16)..".")
    end
    end
    end)
    end
    end
    end
    game.Players.PlayerAdded:connect(onPlayerAdded)

Please help! If you need any more information about the script, please ask.

>Much love, YaYaBinks3.
Report Abuse
Destroshun is not online. Destroshun
Joined: 12 Aug 2012
Total Posts: 764
23 Aug 2012 01:36 PM
dafuq

¤ ¤ † KMXD 2.0 † ¤ ¤
Report Abuse
YaYaBinks3 is not online. YaYaBinks3
Joined: 05 Jun 2009
Total Posts: 2631
23 Aug 2012 01:37 PM
Troll.

>Much love, YaYaBinks3.
Report Abuse
Destroshun is not online. Destroshun
Joined: 12 Aug 2012
Total Posts: 764
23 Aug 2012 01:38 PM
idot

¤ ¤ † KMXD 2.0 † ¤ ¤
Report Abuse
YaYaBinks3 is not online. YaYaBinks3
Joined: 05 Jun 2009
Total Posts: 2631
23 Aug 2012 01:39 PM
You spelt 'idiot' wrong.

>Much love, YaYaBinks3.
Report Abuse
Destroshun is not online. Destroshun
Joined: 12 Aug 2012
Total Posts: 764
23 Aug 2012 01:40 PM
Never tried to spell "idiot" I spelled idot

¤ ¤ † KMXD 2.0 † ¤ ¤
Report Abuse
KnightmareXD is not online. KnightmareXD
Joined: 14 Jul 2009
Total Posts: 11189
23 Aug 2012 01:44 PM
if string.sub(msg,1,5) == "lock " then


¤¤†KMXD†¤¤
Report Abuse
Destroshun is not online. Destroshun
Joined: 12 Aug 2012
Total Posts: 764
23 Aug 2012 01:45 PM
eww I'd do

if msg:find("lock ", 1, true) then

¤ ¤ † KMXD 2.0 † ¤ ¤
Report Abuse
Java3D is not online. Java3D
Joined: 29 Jul 2012
Total Posts: 1229
23 Aug 2012 01:45 PM
I maded a function for chatted commands since they're just that stubborn.


function GetCommand(Message,Words,Players)
if(Players==2)then Players = nil end
local len,brake,retPlay = 1,false,{}
for num,word in pairs(Words)do
if(string.sub(string.lower(Message),len,len-1+string.len(word))==string.lower(word))then
len=len+1+string.len(word)else brake=true break end end
if(not brake and Players)then
local loplay,pler = string.lower(string.sub(Message,len)),game.Players:GetPlayers()
for n,o in pairs(pler)do
if(string.find(string.lower(o.Name),string.sub(string.lower(Message),len))==1)then
table.insert(retPlay,o)
end end
return retPlay
elseif(not Players and not brake)then return string.sub(Message,len)end return false end


Too use:

local CommandCorrect = GetCommand(msg,{"Stuff"},2) -- Setting the 2 to 1 will make it return players
if(CommandCorrect)then
print(CommandCorrect) -- Since we didn't return players, it will give you what you typed after the command
end

-- An example of returning players
local CC = GetCommand(msg,{"kill"},1)
if(CC)then
for num,player in pairs(CC)do
player.Character:BreakJoints()
end

-- Caps are removed automatically.
Report Abuse
KnightmareXD is not online. KnightmareXD
Joined: 14 Jul 2009
Total Posts: 11189
23 Aug 2012 01:48 PM
I'd personally use string.match.

¤¤†KMXD†¤¤
Report Abuse
YaYaBinks3 is not online. YaYaBinks3
Joined: 05 Jun 2009
Total Posts: 2631
23 Aug 2012 01:49 PM
That's extemely messy code. Ew. Too advanced, too. Add comments, I have no idea what you are talking about here.

>Much love, YaYaBinks3.
Report Abuse
YaYaBinks3 is not online. YaYaBinks3
Joined: 05 Jun 2009
Total Posts: 2631
23 Aug 2012 01:49 PM
Why? string.sub works the same. I'm not going to do things like kill/player or teleport/player/here etc.

>Much love, YaYaBinks3.
Report Abuse
Java3D is not online. Java3D
Joined: 29 Jul 2012
Total Posts: 1229
23 Aug 2012 01:49 PM
It's only messy cause roblox removed all my tabs .-.
Report Abuse
YaYaBinks3 is not online. YaYaBinks3
Joined: 05 Jun 2009
Total Posts: 2631
23 Aug 2012 01:54 PM
Use spaces then.

>Much love, YaYaBinks3.
Report Abuse
Java3D is not online. Java3D
Joined: 29 Jul 2012
Total Posts: 1229
23 Aug 2012 01:56 PM
:P



function GetCommand(Message,Words,Players)

if(Players==2)then Players = nil end

local len,brake,retPlay = 1,false,{}

for num,word in pairs(Words)do

if(string.sub(string.lower(Message),len,len-1+string.len(word))==string.lower(word))then

len=len+1+string.len(word)else brake=true break end end

if(not brake and Players)then

local loplay,pler = string.lower(string.sub(Message,len)),game.Players:GetPlayers()

for n,o in pairs(pler)do

if(string.find(string.lower(o.Name),string.sub(string.lower(Message),len))==1)then

table.insert(retPlay,o)

end end
return retPlay

elseif(not Players and not brake)then

return string.sub(Message,len)

end

return false end
Report Abuse
YaYaBinks3 is not online. YaYaBinks3
Joined: 05 Jun 2009
Total Posts: 2631
23 Aug 2012 01:57 PM
Can you explain what that crap does? Still looks messy, and it doesn't even change a Value anywhere.

>Much love, YaYaBinks3.
Report Abuse
Java3D is not online. Java3D
Joined: 29 Jul 2012
Total Posts: 1229
23 Aug 2012 02:03 PM
You lucky I'm just waiting on a reply for my script, so I got time :P


function GetCommand(Message,Words,Players) -- Creates function

if(Players==2)then Players = nil end -- Checks if Players is 2 (so it returns no players if it is)

local len,brake,retPlay = 1,false,{} -- Creates the variables we'll need

for num,word in pairs(Words)do -- Loops through the command words you want

if(string.sub(string.lower(Message),len,len-1+string.len(word))==string.lower(word))then
-- Removes caps from the message (just to check), then compares the word to what we've checked so far

len=len+1+string.len(word)else brake=true break end end -- If it matches, we move on, if it doesn't, we break

if(not brake and Players)then -- If we didn't have to break, and we're collecting players

local loplay,pler = string.lower(string.sub(Message,len)),game.Players:GetPlayers()
-- loplay is what is after the command, pler is the players

for n,o in pairs(pler)do -- loops through the players

if(string.find(string.lower(o.Name),string.sub(string.lower(Message),len))==1)then
-- Checks the player if they're name is partly mentioned after the command

table.insert(retPlay,o) -- We insert the player

end end -- end the loop, and the check
return retPlay -- Return the players

elseif(not Players and not brake)then -- If we don't return the players, and we didn't break

return string.sub(Message,len) -- Return the message after the command

end -- End the statements

return false end -- Return false if we had to break, and end the function
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