检测 ROBLOX 播放器消息中的参数? (LUA)
Detect parameters in a ROBLOX player's message? (LUA)
我正在尝试在 Roblox Studio 中制作一个简单的 'kill command',您可以在其中输入“;kill player”,它会杀死他们。
我纠结的部分是到底如何将space前后的单词分开,并将它们存储为变量?
我的代码中需要的步骤:
- 检查消息传递者的 name 是否等于 'Owner'
的值
- 检查邮件是否包含“;”开头(前缀)
- 检查邮件 是否包含 space
- 如果以上都为真,则在之前设置单词,将space设置为变量,'cmd'并设置单词after space 到变量,'username'.
剩下的我自己想办法
这是我目前的代码:
local Owner = "Djraco"
local Prefix = ";"
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(msg)
--<code goes here>
end)
end)
提前致谢!
local Owner = "Djraco"
local Prefix = ";"
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(msg)
local msg = msg:split(" ") -- Seperate your message every space
if player.Name == Owner and msg[1] == "kill" and msg[2] ~= nil then game:GetService("Players")[msg[2]].Character.Humanoid.Health = 0 end
end)
end)
以上应该有效。如果您需要更多帮助,请告诉我。
我正在尝试在 Roblox Studio 中制作一个简单的 'kill command',您可以在其中输入“;kill player”,它会杀死他们。
我纠结的部分是到底如何将space前后的单词分开,并将它们存储为变量?
我的代码中需要的步骤:
- 检查消息传递者的 name 是否等于 'Owner' 的值
- 检查邮件是否包含“;”开头(前缀)
- 检查邮件 是否包含 space
- 如果以上都为真,则在之前设置单词,将space设置为变量,'cmd'并设置单词after space 到变量,'username'.
剩下的我自己想办法
这是我目前的代码:
local Owner = "Djraco"
local Prefix = ";"
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(msg)
--<code goes here>
end)
end)
提前致谢!
local Owner = "Djraco"
local Prefix = ";"
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(msg)
local msg = msg:split(" ") -- Seperate your message every space
if player.Name == Owner and msg[1] == "kill" and msg[2] ~= nil then game:GetService("Players")[msg[2]].Character.Humanoid.Health = 0 end
end)
end)
以上应该有效。如果您需要更多帮助,请告诉我。