ROBLOX杀死指定玩家

时间:2015-08-01 02:21:43

标签: lua command kill roblox

我想制作一个可以杀死你指定玩家的命令。 让我们说我输入:kill / Paul。现在我想杀死名为Paul的球员。

这是我的命令脚本:

local player = ...

game.Players.PlayerAdded:connect(function(player) --this gets the player that connected
    player.Chatted:connect(function(message) --this function executes when the player type into chat
    --commands are here
    if player.Name == "TominoCZ" or player.Name == "nathancain" or player.Name == "block100000" then
        if message == "kill/me" then
            player.Character.Head:remove()
            end

        if message == "ff/me" then
            if player.Character:findFirstChild("ForceField") then
                player.Character.ForceField:Destroy()
            end

            Instance.new("ForceField").Parent = player.Character
            end

        if message == "unff/me" then 
            if player.Character:findFirstChild("ForceField") then
                player.Character.ForceField:Destroy()
                end
            end
        end
    end)
end)

现在你可以看到我已经有一个命令可以杀死执行它的游戏。

但是如何通过在" kill /"之后指定玩家的名字来杀死其他玩家?

这个命令脚本可能看起来太长或太过专业,但至少我知道并了解它的作用。

所有想法?

1 个答案:

答案 0 :(得分:1)

您可以这样做:

local player = ...

game.Players.PlayerAdded:connect(function(player) --this gets the player that connected
    player.Chatted:connect(function(message) --this function executes when the player type into chat
    --commands are here
    if string.sub(message,1,string.len("kill/"))=="kill/" then --check the message if it starts with command "kill/"
        if string.sub(message,string.len("kill/"))==player.Name then --kill the player with the name
            player.Character.Head:remove()
            end
    end)
end)

我不知道Lua因此可能存在语法错误,但总体思路是您使用string.sub方法将消息分为两部分:命令部分和信息部分。如果命令部分等于"kill/",则找到信息部分中指定名称的玩家,并杀死他! (或者斩首他......我不玩ROBLOX:D)

相关问题