【发布时间】:2014-06-04 20:11:15
【问题描述】:
我正在尝试为我正在玩的游戏服务器创建一个 mod,其想法是基于作为 mod 或管理员的人授予标志权限。这些标志可以由服务器所有者在配置文件中分配。
我要创建的是一个 for 循环,它读取配置文件的一部分并将索引和值传递给一个函数,然后将信息发送到服务器。
function PLUGIN:cmdgiveflags ( netuser , cmd, args )
if (netuser:CanAdmin()) then
local a, targetuser = rust.FindNetUsersByName( args[1] )
if (not a) then
if (targetuser == 0) then
rust.Notice( netuser , "No Players by that name!" )
else
rust.Notice( netuser , "Multiple Players by the name!" )
end
return
end
if ( args[2] == "admin" ) then
**for key,value in pairs(self.Config.admin) do self.addflag(targetuser,key,value) end**
elseif ( args[2] == "mod") then
**for key,value in pairs(self.Config.mod) do self.addflag(targetuser,key,value) end**
else
rust.Notice( netuser , "Invalid Option, must be mod or admin" )
end
else
rust.Notice( netuser , "Only and Admin can use this command" )
end
end
function PLUGIN:addflag (targetuser, key, value)
print ("targetuser is "..targetuser)
**print ("key is "..key)**
**print ("value is "..value)**
if (value == true) then
if (key == "cangod" ) or (key == "canban") or (key == "cankick") or (key == "all") then
rust.RunServerCommand( "oxmin.giveflag " .. targetuser .. " " .. key )
print (targetuser .. " has been given the flag: " .. key )
else
rust.RunServerCommand( "flags.addflag " .. targetuser .. " " .. key )
print (targetuser .. " has been given the flag: " .. key )
end
end
end
我遇到的问题是,当变量 key 和 value 被发送到 addflags 函数时,key 显示为 true 而 value 为 nil。但如果我只是在 for 循环中执行 print(key,value),它们会按预期出现。我才刚刚开始在 Lua 中编码,所以我不太确定所有规则都是什么。任何帮助,将不胜感激。
抱歉,如果网站上的代码格式不正确,不知道如何以正确的格式粘贴。
【问题讨论】:
-
"Lua (/ˈluːə/ loo-ə,来自葡萄牙语:lua [ˈlu.(w)ɐ] 意思是月亮;明确地不是 "LUA"[1])" - 忘记这些大写。
-
对不起。除了大小写不正确,你还有什么 cmets 吗?