1. Hey everybody,

    i cant get it working. I want to save some data in a config. But it runs in an exception.
    i think it is very easy :/

    Code:
    void savepluginconfig()
    {
        Config.Clear();
        Config["Autostart"] = false; //Bool
        Config["RoundTime"] = "300"; //String
        Config["SpawnPoints"] = SpawnPoints; //Vector3 List
        SaveConfig();
    }
    
    i get this exception:
    Code:
    [Oxide] 19:31 [Error] Failed to call hook 'createspawn' on plugin 'HungerGames v0.1.0' (NullReferenceException: Object reference not set to an instance of an object)
    [Oxide] 19:31 [Debug]   at Oxide.Plugins.HungerGames.savepluginconfig () [0x00000] in <filename unknown>:0
      at Oxide.Plugins.HungerGames.createspawn (.BasePlayer player, System.String command, System.String[] args) [0x00000] in <filename unknown>:0
      at Oxide.Plugins.HungerGames.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x00000] in <filename unknown>:0
      at Oxide.Plugins.CSharpPlugin.InvokeMethod (HookMethod method, System.Object[] args) [0x00000] in <filename unknown>:0
      at Oxide.Core.Plugins.CSPlugin.OnCallHook (System.String name, System.Object[] args) [0x00000] in <filename unknown>:0
      at Oxide.Core.Plugins.Plugin.CallHook (System.String name, System.Object[] args) [0x00000] in <filename unknown>:0 
     
  2. Wulf

    Wulf Community Admin

    Did you create the config file already? It should be created on startup. I'd comment out portions to see what is actually null as well.
     
  3. Mhh i thought the config file will created autoamticly if not exist with saveconfig(); ?
    i used the example from the oxide docs
    Code:
    namespace Oxide.Plugins
    {
        [Info("EpicPlugin", "Unknown", 1.0)]
        [Description("This example illustrates how to use a basic configuration file")]    class EpicPlugin : RustPlugin
        {
            protected override void LoadDefaultConfig()
            {
                PrintWarning("Creating a new configuration file");
                Config.Clear();
                Config["ShowJoinMessage"] = true;
                Config["ShowLeaveMessage"] = true;
                Config["JoinMessage"] = "Welcome to this server";
                Config["LeaveMessage"] = "Goodbye";
                SaveConfig();
            }
        }
    }
    
     
  4. Wulf

    Wulf Community Admin

    Using LoadDefaultConfig() creates a blank one, whatever you set and save with SaveConfig() just adds to it.
     
  5. Mhh i can't get it working

    Code:
    void Loaded()
    {
         Puts($"Plugin HungerGames has been loaded");
         if (Config.Exists("HungerGames.cfg"))
         {
              Puts($"Loading configfile");
              loadpluginconfig();
         }
         else
         {
              Puts($"No config found. Create default config");
              createpluginconfig();
         }
    }
    void createpluginconfig()
    {
         LoadDefaultConfig();
         Config["Autostart"] = false;
         Config["RoundTime"] = "300";
         Config.Save("HungerGames.cfg");
    }
    
     
  6. Wulf

    Wulf Community Admin

    Configs are .json files, not .cfg, and the name should not be specified. You also do not need to check if it exists, just check that it isn't empty if you need to check.
     
  7. Ok now it works. It create an empty configfile. But if i want to save the data it crashed at the vector3 list part. any idea how can i save and load the vector3 list of vetor3?
    Failed to save config file (does the config have illegal objects in it?) (Self referencing loop detected for property 'normalized' with type 'UnityEngine.Vector3'.

    Code:
    Config["SpawnPoints"] = SpawnPoints; //Vector3 List
     
  8. Wulf

    Wulf Community Admin

    You'd likely need to save it a string or something that JSON supports, not a Vector3
     
  9. thanks :) it works now :) can close :)