1. 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:
    Code:
    {
      "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"
      ]
    }
    -TheDoc
     
    Last edited by a moderator: Mar 10, 2015
  2. Wulf

    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()
     
  3. Cool, how about adding an item to the list?
     
  4. Depends on how you have the config item you want to push stuff too, I wouldn't recommend sending things to the config as its only loaded once upon plugin initiation.

    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.
     
  5. Wulf

    Wulf Community Admin

    The same as you'd do with creating the default config. The SaveConfig is the magic maker.
    Code:
    self.Config.Admins = {
        "12312312312312333",
        "12312312312312333",
        "12312312312312333"
    }
    self:SaveConfig()
     
  6. Thats not true. You can easily change config values on the fly without restarting the plugin.
     
  7. This works, however it does not add to the list but overrides the list, is there a way to add it to it or do I need to iterate over the list and add all the items from current list and then add the new one?

    or can I do something like self.Config.Admins = self.Config.Admins .. ",\"" .. args[1] .. "\"" and then write it...

    I'll try and see...

    Thanks.
     
  8. It's a lua table you can do pretty much anything you want to it.
     
  9. 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
    
    This is the error I'm getting:

    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
    
    Please help....
     
  10. Like Hatemail said you just had to google "lua tables".
    table.insert() is what you're looking for.