【发布时间】:2020-05-14 01:35:11
【问题描述】:
我正在创建一个允许 Lua 脚本的游戏服务器。基本上,脚本获取服务器日期并根据该日期选择一个文本文件。每个文本文件都包含一个名称列表。脚本的重点是将玩家重命名为“有趣”的节日名称。
这是我填充表格并分配名称的初始代码:
-- Get Names from selected Holiday file
local holFile = io.open(filePath .. holiday .. ".txt", "r");
local holidayNames = {}
for line in holFile:lines() do
table.insert (holidayNames, line);
end
-- Set Name to a random item in the Holiday Names table
randomItem = math.random(0, #holidayNames - 1)
Name = (holidayNames[randomItem])
我还在上述代码之前添加了这部分,只是为了让一个表填充当前名称:
-- Get Current Players List
local currPlayers = io.open(filePath "players.txt", "r");
local currentPlayers = {}
for line in currPlayers:lines() do
table.insert (currentPlayers, line);
end
所以基本上,当我尝试将项目添加到 holidayNames 时,我想首先查看它们是否存在于 currentPlayers 中。
【问题讨论】:
标签: lua