I am trying to create a mod for a game server that i am playing, the idea is to give flag permissions to people based on being a mod or admin. The flags can be assigned by the server owner in a config file.
What i am trying to create, is a for loop that reads a section of the config file and passes the index and value to a function that then sends the information to the server.
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
The problem that i am having is when the variables key and value are sent to the addflags functions, key shows up as true and value is nil. but if i just do print(key,value) in the for loop they come out as expected. I only just started coding in Lua so I'm not too sure what the rules all are just yet. Any help would be appreciated.
Oh and sorry if the code isnt formatted correctly on the site, not sure how to get it to paste with the correct formatting.