-2

我目前正在尝试制作一个新的管理命令脚本;到目前为止,我所拥有的只是 kill 命令……除非我使用“:* me”参数(“*”是任何命令,“:”是识别字符,否则我尝试过的所有东西(到目前为止)都有效。我不'不太明白为什么这不起作用。

我已经尝试了一些疯狂的事情来尝试使这项工作正常进行,因此代码可能会从我最初拥有的代码中删除...

admins = {"FakeNameHereSoNoStalkers"}

function kill(target)
    for i=1,#target do
        game.Players.target[i].Character:BreakJoints()
    end
end

function isadmin(source)
    for i=1,#admins do
        if admins[i]:lower()==source:lower() then return true end
    end
end

function findplayer(msg, source)
    people = {}
    c = game.Players:GetChildren()
    if msg:lower()=="me" then
        table.insert(people, source)
        return people
    elseif msg:lower()=="all" then
        for i=1,#c do
            table.insert(people, c[i])
        end
        return people
    else
        local length = msg:len()
        for i=1,#c do
            if c[i].Name:lower():sub(1, length)==msg:lower() then
                table.insert(people, c[i])
            end
        end
        return people
    end
end

game.Players.PlayerAdded:connect(function(player)
    source = player.Name
    if isadmin(source) == true then
        player.Chatted:connect(function(msg, player)
            if msg:lower():sub(1,6)==":kill " then
                msg = msg:sub(7)
                target = findplayer(msg, source)
                kill(target)
            end
        end)
    end
end)
4

1 回答 1

0
for i=1,#target do
    game.Players.target[i].Character:BreakJoints()
end

不正确,如果“目标”包含“FakeNameHereSoNoStalkers”,则运行代码为:

game.Players.target.1.Character:BreakJoints()

这是完全不正确的。


c = game.Players:GetChildren()

永远不要使用"Players:GetChildren()",它不能保证只返回玩家。

而是使用:

c = Game.Players:GetPlayers()

if msg:lower()=="me" then
    table.insert(people, source)
    return people

在这里,您将播放器的名称添加到列表"people"中,您在其他地方添加播放器对象。


固定代码:

local Admins = {"FakeNameHereSoNoStalkers"}

function Kill(Players)
    for i,Player in ipairs(Players) do
        if Player.Character then
            Player.Character:BreakJoints()
        end
    end
end

function IsAdmin(Player)
    for i,AdminName in ipairs(Admins) do
        if Player.Name:lower() == AdminName:lower() then return true end
    end
    return false
end

function GetPlayers(Player,Msg)
    local Targets = {}
    local Players = Game.Players:GetPlayers()

    if Msg:lower() == "me" then
        Targets = { Player }
    elseif Msg:lower() == "all" then
        Targets = Players
    elseif Msg:lower() == "others" then
        for i,Plr in ipairs(Players) do
            if Plr ~= Player then
                table.insert(Targets,Plr)
            end
        end
    else
        for i,Plr in ipairs(Players) do
            if Plr.Name:lower():sub(1,Msg:len()) == Msg then
                table.insert(Targets,Plr)
            end
        end
    end
    return Targets
end

Game.Players.PlayerAdded:connect(function(Player)
    if IsAdmin(Player) then
        Player.Chatted:connect(function(Msg)
            if Msg:lower():sub(1,6) == ":kill " then
                Kill(GetPlayers(Player,Msg:sub(7)))
            end
        end)
    end
end)
于 2014-06-12T07:57:37.877 回答