我正在尝试创建一个新的管理命令脚本;我到目前为止所有的一切都是杀戮命令......除非我使用“:* 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)
答案 0 :(得分:0)
for i=1,#target do
game.Players.target[i].Character:BreakJoints()
end
不正确,如果" target" 包含" FakeNameHereSoNoStalkers" ,则运行代码将为:
game.Players.target.1.Character:BreakJoints()
哪个是完全错误的。
c = game.Players:GetChildren()
永远不要使用"玩家: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)