|
How do I get a players name from a string.sub?
As in like using a string.sub to check what you say after something else.
like if you said "nuke/Thunderx10" then it would find the stuff after nuke/ |
|
|
and let me use it
like player = (string.sub(msg, 1,#msg)
Something like that. |
|
|
XlegoXJoin Date: 2008-06-16 Post Count: 14955 |
It's easy as long as there's just a single name that you need to find:
string:sub(a, b) gets the substring from the a'th to the b'th character. Using a negative number for one means "away from the end", for example, -1 means "the last character", or "0 away from the end".
So, something along the lines of this:
string:sub(6, -1)
Gets from the 6th to the last character. "nuke/" contains 5 characters, so the first character of a person's name should be the 6'th, so 6 for the start, and, you want to get all the way to the end of what they entered, so -1 for the end. |
|
|
|
So would something like this work..?
person = "Thunderx10"
chat = game.Players[person]
function onChatted(msg)
if (string.sub(msg, 1,5) == "nuke/") then
name = string.sub(6, -1)
plyr = game:getService("Workspace")[name]
plyr:BreakJoints()
end
end
chat.Chatted:connect(onChatted) |
|
|
|
Can anyone help me? spec? crazy? |
|
pighead10Join Date: 2009-05-03 Post Count: 10341 |
if (string.sub(msg, 1,5) == "nuke/") then
That line is correct. To get everything after that, you simply need to put
string.sub(msg(6)) |
|
XlegoXJoin Date: 2008-06-16 Post Count: 14955 |
No, that's wrong. And even if you did write it down right it's better to explicitly put the "-1" index at the end. |
|
|
check the free models you can learn faster there. :3
admin scripts etc...
function o(noob,msg)
msg:lower()
if (string.sub(msg,1,5) == "nuke/") then --"nuke/5" has 5 characters so 1,5
Nuke(workspace[string.sub(msg,6)]) -- err
else
end
end |
|
|
Something like this should work.
person = "Thunderx10"
chat = game:getService("Players"):findFirstChild(person)
function onChatted(msg)
if (string.sub(msg, 1,5) == "nuke/") then
name = string.sub(msg, 6)
if game:getService("Players"):findFirstChild(name) ~= nil then
game:getService("Players"):findFirstChild(name).Character:BreakJoints()
else
print("No person such as: " ..name.. " found!")
end end end
chat.Chatted:connect(onChatted) |
|
pighead10Join Date: 2009-05-03 Post Count: 10341 |
|
|
|
Its not wrong :)
It works perfectly. |
|
pighead10Join Date: 2009-05-03 Post Count: 10341 |
"string.sub(msg(6))"
whoops, xleg was right, I typed it wrong.
string.sub(msg,6) is what I meant :/ |
|
pighead10Join Date: 2009-05-03 Post Count: 10341 |
From the wiki:
"string.sub (s, i [, j])
Returns the substring of s that starts at i and continues until j; i and j may be negative. If j is absent, then it is assumed to be equal to -1" |
|
myrco919Join Date: 2009-06-12 Post Count: 13241 |
[ Content Deleted ] |
|
|
@myrco
Learn to script, you don't need anylinks :)
function chat(msg, speaker)
-- if msg == "" then
-- end
-- and you just ad on what you need :)
end
-- connection line has however you want it. |
|
myrco919Join Date: 2009-06-12 Post Count: 13241 |
[ Content Deleted ] |
|
myrco919Join Date: 2009-06-12 Post Count: 13241 |
[ Content Deleted ] |
|
|
goodluck with that.
go learn lua, java, c++
then you'l know how to script wel :) |
|
bloob827Join Date: 2010-08-01 Post Count: 6867 |
lolwut says the cow at dawn
function onChatted(msg, speaker)
_,_,cmd,parm = msg:find("^(%w*)/(.*)")
if cmd == "kill" then
target = game.Players:findFirstChild(parm)
target.Humanoid.Health = 0
end
end
function p(newplayer)
if newPlayer.Name == "Thunderx10" then
newPlayer.Chatted:connect(function(msg) onChatted(msg,speaker) end)
end
end
game.Players.ChildAdded:connect(p) |
|