【发布时间】:2016-10-12 23:10:45
【问题描述】:
我想用两条信息制作动态玩家表。以字符串形式提供的玩家 SteamID 将用作键,值应为数字。
应该看起来像table = { "ExampleSteamID" = 3, "ExampleSteamID2" = 4 }
我找到了类似table.insert(table, { key = x, value = z}) 的东西,但它不起作用。
gameevent.Listen("player_connect")
local function AdminBotOnJoinCheck(data)
local ply = data.networkid -- SteamID of joining player
local tableisempty = true -- some random stuff
for k, tableply in pairs(adminbot_players) do --checking for players already writed to table, maybe need fix
if not ply == tableply then
--need code here
MsgC("\nAdminBot: Player table updated | ", ply, "\n")
end
tableisempty = false --clear table = table break - just dont execute code.
end
if tableisempty == true then
--here same code
MsgC("\nAdminBot: Player table updated | ", ply, "\n")
end
if file.Exists("adminbotplayers.txt", "DATA") == true and adminbot_teamkills_use_file == true then -- Random stuff for file writing
local adminbot_players_json = util.TableToJSON(adminbot_players)
file.Write("adminbotplayers.txt", adminbot_players_json)
end
end
【问题讨论】:
-
我强烈建议您阅读Programming in Lua,从前到后 - 第 2.5 章对您非常有用。考虑阅读参考手册,尤其是tables 及其manipulation 上的部分。
-
我不能在 gmod 服务器的脚本中使用 "::=" :/
-
::=是BNF 的一部分,该符号用于描述 Lua 的语法,意思是“定义为”。=用于语言中的赋值。
标签: lua lua-table garrys-mod