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: How do admin commands do this?

Previous Thread :: Next Thread 
Chronok is not online. Chronok
Joined: 29 Dec 2011
Total Posts: 402
02 Jan 2012 01:05 PM
Let's say someone was using a working admin commands script and said "kill/c", and there were no other players whose names started with the letter *c* in the server. I know that string.match is utilized, but I don't know how. This is all I've got so far:

    local playersService = game:GetService("Players")
    local workspaceService = game:GetService("Workspace")
    
    playersService.PlayerAdded:connect(function(playerObject)
        playerObject.Chatted:connect(function(stringMessage)
            if string.sub(stringMessage, 1, 5) == "kill/" then
                if tierOne[playerObject.Name] or tierTwo[playerObject.Name] or tierThree[playerObject.Name] then
                    local fakeObject = string.sub(stringMessage, 6)
                    local actualObject = playersService:FindFirstChild( -- I need some help here.

I've gotten the name of the player which came after the slash, but how do I use string.match to get that player in the Players service?

{ ["Chronok"] = "Intermediate scripter/programmer." }
Report Abuse
Chronok is not online. Chronok
Joined: 29 Dec 2011
Total Posts: 402
02 Jan 2012 01:18 PM
Bump.

{ ["Chronok"] = "Intermediate scripter/programmer." }
Report Abuse
Chronok is not online. Chronok
Joined: 29 Dec 2011
Total Posts: 402
02 Jan 2012 02:06 PM
Does no one know?

{ ["Chronok"] = "Intermediate scripter/programmer." }
Report Abuse
Chronok is not online. Chronok
Joined: 29 Dec 2011
Total Posts: 402
02 Jan 2012 02:21 PM
Bump.

{ ["Chronok"] = "Intermediate scripter/programmer." }
Report Abuse
C0D3Y is not online. C0D3Y
Joined: 24 Jul 2010
Total Posts: 1692
02 Jan 2012 02:48 PM
This is from the wiki so it should work. Just have to change some things around...

victim = findPlayer(message:sub(6))
if victim ~= nil then
victim.Character:BreakJoints()
Report Abuse
Chronok is not online. Chronok
Joined: 29 Dec 2011
Total Posts: 402
02 Jan 2012 02:52 PM
@C0D3Y

That wouldn't work at all.

{ ["Chronok"] = "Intermediate scripter/programmer." }
Report Abuse
C0D3Y is not online. C0D3Y
Joined: 24 Jul 2010
Total Posts: 1692
02 Jan 2012 02:56 PM
Dumb wiki...
Report Abuse
Chronok is not online. Chronok
Joined: 29 Dec 2011
Total Posts: 402
02 Jan 2012 03:15 PM
Bump.

{ ["Chronok"] = "Intermediate scripter/programmer." }
Report Abuse
DXPower is not online. DXPower
Joined: 21 Oct 2008
Total Posts: 2866
02 Jan 2012 03:26 PM
I think that they use string.len and a for loop...

then, check it against all other players, if it makes a match, then BINGO.
Report Abuse
Chronok is not online. Chronok
Joined: 29 Dec 2011
Total Posts: 402
02 Jan 2012 07:06 PM
@DXPower

But my question is how would I do that? Does anyone have nay inkling as to what I should do?

{ ["Chronok"] = "Intermediate scripter/programmer." }
Report Abuse
Merlin11188 is not online. Merlin11188
Joined: 20 Dec 2007
Total Posts: 4158
02 Jan 2012 07:19 PM
if Player:findFirstChild(message:sub(6)) then
Player.Character:BreakJoints()
end
Report Abuse
Merlin11188 is not online. Merlin11188
Joined: 20 Dec 2007
Total Posts: 4158
02 Jan 2012 07:20 PM
Fail.
if Players:findFirstChild(message:sub(6))

~Floodcheck~
Report Abuse
Chronok is not online. Chronok
Joined: 29 Dec 2011
Total Posts: 402
02 Jan 2012 07:21 PM
I don't think that's what I'm asking for, but thanks for trying.

Read my first post where I have a made up example.

{ ["Chronok"] = "Intermediate scripter/programmer." }
Report Abuse
Chronok is not online. Chronok
Joined: 29 Dec 2011
Total Posts: 402
02 Jan 2012 07:22 PM
"if Players:findFirstChild(message:sub(6))"

Second fail.

{ ["Chronok"] = "Intermediate scripter/programmer." }
Report Abuse
Chronok is not online. Chronok
Joined: 29 Dec 2011
Total Posts: 402
02 Jan 2012 07:44 PM
Bump. Come on, there's got to be some advanced ROBLOX users online.

{ ["Chronok"] = "Intermediate scripter/programmer." }
Report Abuse
Chronok is not online. Chronok
Joined: 29 Dec 2011
Total Posts: 402
02 Jan 2012 08:09 PM
Bump.

{ ["Chronok"] = "Intermediate scripter/programmer." }
Report Abuse
jode6543 is not online. jode6543
Joined: 16 Jun 2009
Total Posts: 5363
02 Jan 2012 08:25 PM
local peoplez = {"jode6543","superdeer","STARWARSFAN1400","Strawberryz","ROBLOX","Telamon","Player"}

function findPlayerFromNickname(nick)
local player = nil
nick = nick:lower()
local results = 0
for i = 1,#peoplez do
if string.sub(peoplez[i], 1, string.len(nick)):lower() == nick then
player = peoplez[i]
results = results + 1
end
end
--Nifty error codes
if results >= 2 then
return 1
elseif results == 0 then
return 2
end
return player
end

Edit that to your needs, seems to work fine for me.

~THROW THE CHEEEEEEEEEEEEEEEEEEEESE!~
Report Abuse
DXPower is not online. DXPower
Joined: 21 Oct 2008
Total Posts: 2866
02 Jan 2012 09:01 PM
@OP and Above

AHA! I told you it used string.len and a for loop!!!!!

But, anyways, use his.

Free Fireworks!
Report Abuse
DonnyTheDemented is not online. DonnyTheDemented
Joined: 29 May 2010
Total Posts: 1413
02 Jan 2012 09:05 PM
function FindPlayer(c)
local Players= game:GetService('Players'):GetChildren()
local db=false
for i=1,#Players do
if Players[i]:lower():sub(1,c:len())==c:lower() then
if not db then
db = true
else
db =false
end
end
if db then
return c
else
return nil
end

this requires that you call FindPlayer with the argument that comes after *command here*/

I wrote this in about 30 seconds so there might be a few syntax errors and/or fails on my part, but conceptually this should work. (I made it to work with the code someone posted on here earlier, basically I just used the same function name)
Report Abuse
Chronok is not online. Chronok
Joined: 29 Dec 2011
Total Posts: 402
03 Jan 2012 10:40 AM
@jode

Is there any way that can be compatible with my three different tiers? I see you used one single table to store names, whereas I have three. Would I *really* have to run three different for loops?

{ ["Chronok"] = "Intermediate scripter/programmer." }
Report Abuse
Chronok is not online. Chronok
Joined: 29 Dec 2011
Total Posts: 402
03 Jan 2012 10:56 AM
@jode

Nevermind, I have a new problem. I used your code and edited it a little bit and here's what I got:

    local tierOne = {
        ["nameOne"] = true;
        ["nameTwo"] = true;
        ["nameThree"] = true
    }
    
    local tierTwo = {
        ["nameOne"] = true;
        ["nameTwo"] = true;
        ["nameThree"] = true
    }
    
    local tierThree = {
        ["nameOne"] = true;
        ["nameTwo"] = true;
        ["nameThree"] = true;
        ["Chronok"] = true
    }
    
    local playersService = game:GetService("Players")
    local workspaceService = game:GetService("Workspace")
    
    function getPlayer(stringName)
        local playerObject = nil
        local resultsValue = 0
        local stringName = string.lower(stringName)
        for index, value in pairs(playersService:GetPlayers()) do
            if string.sub(string.lower(value), 1, string.len(stringName)) == stringName then
                playerObject = value
                resultsValue = resultsValue + 1
            end
        end
        if resultsValue ​>= 2 then
            return false
        elseif resultsValue == 0 then
            return true
        end
        return playerObject
    end
    
    playersService.PlayerAdded:connect(function(playerObject)
        playerObject.Chatted:connect(function(stringMessage)
            if string.sub(stringMessage, 1, 5) == "kill/" then
                if tierOne[playerObject.Name] or tierTwo[playerObject.Name] or tierThree[playerObject.Name] then
                    local fakeObject = string.sub(stringMessage, 6)
                    local actualObject = getPlayer(fakeObject)
                    if actualObject then
                        if actualObject.Character then
                            actualObject.Character:BreakJoints()
                        end
                    end
                end
            end
        end)
    end)

I know it looks rather long, but ignore the tables. There is no output.

{ ["Chronok"] = "Intermediate scripter/programmer." }
Report Abuse
Chronok is not online. Chronok
Joined: 29 Dec 2011
Total Posts: 402
03 Jan 2012 11:01 AM
    local playersService = game:GetService("Players")
    local workspaceService = game:GetService("Workspace")
    
    function getPlayer(stringName)
        local playerObject = nil -- Changed variable names.
        local resultsValue = 0
        local stringName = string.lower(stringName)
        for index, value in pairs(playersService:GetPlayers()) do -- I didn't loop through tables here, I think this would work, though.
            if string.sub(string.lower(value), 1, string.len(stringName)) == stringName then -- Didn't use the method forms.
                playerObject = value
                resultsValue = resultsValue + 1
            end
        end
        if resultsValue ​>= 2 then
            return false -- Didn't return a number.
        elseif resultsValue == 0 then
            return true
        end
        return playerObject
    end
    
    playersService.PlayerAdded:connect(function(playerObject)
        playerObject.Chatted:connect(function(stringMessage)
            if string.sub(stringMessage, 1, 5) == "kill/" then
                if tierOne[playerObject.Name] or tierTwo[playerObject.Name] or tierThree[playerObject.Name] then
                    local fakeObject = string.sub(stringMessage, 6)
                    local actualObject = getPlayer(fakeObject) -- Called the function.
                    if actualObject:IsA("Player") then -- Checking to see if it returned a player.
                        if actualObject then
                            if actualObject.Character then
                                actualObject.Character:BreakJoints()
                            end
                        end
                    end
                end
            end
        end)
    end)

There. I added a few extra lines (and commented on which ones I edited/added).

{ ["Chronok"] = "Intermediate scripter/programmer." }
Report Abuse
Chronok is not online. Chronok
Joined: 29 Dec 2011
Total Posts: 402
03 Jan 2012 11:15 AM
I'm sorry, but I have no clue as to what the problem is (pighead10).

{ ["Chronok"] = "Intermediate scripter/programmer." }
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