1. Shadow 8

    Shadow 8 Plugin Developer

    Code (C#):
    private Dictionary<Player,Collection<string[]>> inventorySaveList = new Dictionary<Player,Collection<string[]>>();
    void Log(string msg) => Puts($"{Title} : {msg}");

      private void LoadInventoryData()
      {
      inventorySaveList = Interface.GetMod().DataFileSystem.ReadObject<Dictionary<Player,Collection<string[]>>>("InventoryInformationSave");
      }

      private void SaveInventoryData()
      {
      Log("Saving data for Player Inventory");
      Interface.GetMod().DataFileSystem.WriteObject("InventoryInformationSave", inventorySaveList);
      }

      void Loaded()
      {
      inventorySaveList = new Dictionary<Player,Collection<string[]>>();
      LoadInventoryData();
      }
    after reloading plugins its make error if saved files not empty.
    if i remove line.
    inventorySaveList = Interface.GetMod().DataFileSystem.ReadObject<Dictionary<Player,Collection<string[]>>>("InventoryInformationSave");
    its works but ofg not load saved data.

    log for error :(
    Code (Text):
    23:30 [Debug] ExType: JsonSerializationException
    23:30 [Error] Failed to initialize plugin 'InventoryProtection v1.0.1' (ArgumentException: Could not cast or convert from System.String to CodeHatch.Engine.Networking.Player.)
    23:30 [Debug]  at Newtonsoft.Json.Utilities.ConvertUtils.EnsureTypeAssignable (System.Object value, System.Type initialType, System.Type targetType) [0x00000] in <filename unknown>:0
      at Newtonsoft.Json.Utilities.ConvertUtils.ConvertOrCast (System.Object initialValue, System.Globalization.CultureInfo culture, System.Type targetType) [0x00000] in <filename unknown>:0
      at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureType (Newtonsoft.Json.JsonReader reader, System.Object value, System.Globalization.CultureInfo culture, Newtonsoft.Json.Serialization.JsonContract contract, System.Type targetType) [0x00000] in <filename unknown>:0
    23:30 [Info] Unloaded plugin InventoryProtection
    23:30 [Info] No previous version to rollback plugin: InventoryProtection
     
    Last edited by a moderator: Sep 8, 2016
  2. D-Kay

    D-Kay Plugin Developer

    The problem is that you can't save the class Player to a .json file and get it back as Player. Loading will always read that data as a string and then in your program try to cast it to Player.

    Look at my level system for how to work with saving a player.
     
  3. Shadow 8

    Shadow 8 Plugin Developer

    thx.i look that:)
     
  4. Shadow 8

    Shadow 8 Plugin Developer

    Code (Text):
    00:09 [Error] Failed to call hook 'OnPlayerConnected' on plugin 'InventoryProtection v1.0.1' (NullReferenceException: Object reference not set to an instance of an object)
    00:09 [Debug]  at Oxide.Plugins.InventoryProtection.GetInventoryContents (CodeHatch.Engine.Networking.Player player) [0x00000] in <filename unknown>:0
      at Oxide.Plugins.InventoryProtection.OnPlayerConnected (CodeHatch.Engine.Networking.Player player) [0x00000] in <filename unknown>:0
      at Oxide.Plugins.InventoryProtection.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
    00:10 [Info] InventoryProtection was compiled successfully in 3967ms
    need help this error
     
  5. Wulf

    Wulf Community Admin Community Admin Oxide Developer

    The player may not have an inventory at that point, which is what it looks like from the error.
     
  6. Shadow 8

    Shadow 8 Plugin Developer

    thx for reply:)
    same error with another hook:(
    00:40 [Error] Failed to call hook 'OnPlayerSpawn' on plugin 'InventoryProtection v1.0.1' (NullReferenceException: Object reference not set to an instance of an object)
    its mayby inventory tha point?
    or not.so i need to find another hook?
    i try to solve that tomorrow.its so close to ready that one:)
     
  7. Shadow 8

    Shadow 8 Plugin Developer

    [SERVER v1.0.23] Console: InventoryProtection.cs(158,27): error CS1929: Type `ulong' does not contain a member `GetInventory' and the best extension method overload `CodeHatch.Common.PlayerExtensions.GetInventory(this CodeHatch.Engine.Networking.Player)' requires an instance of type `CodeHatch.Engine.Networking.Player'

    what i should use?
    User not use player.Id
    and ulong not use GetInventory,and that make Error

    00:18 [Error] Failed to call hook 'OnPlayerConnected' on plugin 'InventoryProtection v1.0.1' (NullReferenceException: Object reference not set to an instance of an object)
    00:18 [Debug] at Oxide.Plugins.InventoryProtection.GetInventoryContents (CodeHatch.Engine.Networking.Player player) [0x00000] in <filename unknown>:0
     
  8. D-Kay

    D-Kay Plugin Developer

    The best way to do it is by letting the player use a command to get his/her inventory back. So far I haven't been able to modify the inventory of a player when he/she joins the server (for my level system, modifying the inventory amount) and tried to find a workaround.
     
  9. Shadow 8

    Shadow 8 Plugin Developer

    Hmm.its lookslike i need To do that.thx