Hi Guys,
I wanted to upgrade my vipname.lua plugin to allow admins to add users from the command line (CHAT), is there a way to do this? Can you guys show me how?
I would like to add / delete SteamIDs to eg.: Vips list that's one thing, and another, I would like to modify any Setting values for eg.: AddOther3Tag": "false" change to "true", how do I go about it? Thanks.
My config file looks like this:
-TheDocCode:{ "Settings": { "AddAdminTag": "true", "Other2Tag": " ]Other2[", "AddOther2Tag": "false", "VipTag": " -ViP-", "AdminTag": "[Admin] ", "AddVipTag": "true", "AddOther3Tag": "false", "Other1Tag": " ]Other1[", "AddOther1Tag": "false", "Other3Tag": " ]Other3[" }, "Other1": [], "Other2": [], "Other3": [], "Admins": [ "12312312312312333", "12312312312312333", "12312312312312333" ], "Vips": [ "12312312312312333", "12312312312312333", "12312312312312333", "12312312312312333", "12312312312312333" ] }
Solved Add/delete/modify config file from chat command (Lua)
Discussion in 'Rust Development' started by TheDoc, Mar 10, 2015.
-
Wulf Community Admin
Just set the config value in your chat command function, then save the config.
Code:self.Config.Settings.AddOther3Tag = "true" self:SaveConfig()
-
Cool, how about adding an item to the list?
-
The user would have to then reboot your plugin in order to use the new data anyway, when they can just change it or add it into the config manually and then reboot the plugin. -
Wulf Community Admin
Code:self.Config.Admins = { "12312312312312333", "12312312312312333", "12312312312312333" } self:SaveConfig()
-
-
or can I do something like self.Config.Admins = self.Config.Admins .. ",\"" .. args[1] .. "\"" and then write it...
I'll try and see...
Thanks. -
It's a lua table you can do pretty much anything you want to it.
-
Well I can't get it to work....
I wrote the following function and it blows up on me....
Code:function PLUGIN:cmdAddVip(player, cmd, args) local newVipList = "" local i = 1 for _, value in pairs(self.Config.Vips) do print("*** Value = " .. value ) if i == 1 then newVipList = newVipList .. "\"" .. value .. "\"" i = 0 else newVipList = newVipList .. ",\"" .. value .. "\"" end end -- now let's add our new SteamID to it newVipList = newVipList .. ",\"" .. args[1] .. "\"" print("*** newVipList = " .. newVipList ) self.Config.Vips = { newVipList } self:SaveConfig() rust.SendChatMessage(player, "<color=#01DF3A>VIP Added!</color>") end
Code:[Oxide] 12:05 AM [Debug] ExType: IndexOutOfRangeException [Oxide] 12:05 AM [Error] Failed to call hook 'cmdAddVip' on plugin 'ViP / Admin / Other - Auto Name Changer' (IndexOutOfRangeException: Array index is out of ra nge.) [Oxide] 12:05 AM [Debug] at NLua.MetaFunctions.GetMethodInternal (LuaState lua State) [0x00000] in <filename unknown>:0 at NLua.MetaFunctions.GetMethod (LuaState luaState) [0x00000] in <filename unk nown>:0 nts, 0 slprs 3kb/s in, 3kb/s out at (wrapper native-to-managed) NLua.MetaFunctions:GetMethod (KeraLua.LuaState) at (wrapper managed-to-native) KeraLua.NativeMethods:LuaNetPCall (intptr,int,i nt,int) at KeraLua.Lua.LuaNetPCall (IntPtr luaState, Int32 nArgs, Int32 nResults, Int3 2 errfunc) [0x00000] in <filename unknown>:0 at NLua.LuaLib.LuaPCall (LuaState luaState, Int32 nArgs, Int32 nResults, Int32 errfunc) [0x00000] in <filename unknown>:0 at NLua.Lua.CallFunction (System.Object function, System.Object[] args, System .Type[] returnTypes) [0x00000] in <filename unknown>:0 at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (ob ject,object[],System.Exception&) at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invoke Attr, System.Reflection.Binder binder, System.Object[] parameters, System.Global
-
Like Hatemail said you just had to google "lua tables".
table.insert() is what you're looking for.