1

我想做一个命令来杀死你指定的玩家。假设我输入: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/”之后指定玩家的名字来杀死不同的玩家呢?

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

那么有什么想法吗?

4

1 回答 1

2

你可以这样做:

本地玩家 = ...

game.Players.PlayerAdded:connect(function(player) --获取连接的玩家
    player.Chatted:connect(function(message) -- 这个函数在玩家输入聊天时执行
    --命令在这里
    if string.sub(message,1,string.len("kill/"))=="kill/" then --检查消息是否以命令“kill/”开头
        if string.sub(message,string.len("kill/"))==player.Name then --kill同名玩家
            player.Character.Head:remove()
            结尾
    结尾)
结尾)

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

于 2015-08-01T03:10:46.803 回答