我不熟悉 Garry's Mod,但如果您只需要检查玩家的昵称是否在表中,您可以这样做:
local Table = { "Player1", "Player2", "Player3" }
hook.Add( "PlayerConect", "Connect", function(ply)
local notfound = true
-- iterate through all elements in the table
for index, nick in ipairs(Table) do
if ply:Nick() == nick then
notfound = false
break
end
end
if notfound then ply:Kick( "Reason here" ) end
end)
如果您使用稍微不同的表来保存球员的昵称,那么检查将变得更简单(Table
现在用作哈希表):
local Table = { Player1 = true, Player2 = true, Player3 = true }
hook.Add( "PlayerConect", "Connect", function(ply)
-- check if the nick is present in the table
if not Table[ply:Nick()] then ply:Kick( "Reason here" ) end
end)