1. Hi Everyone,
    I was wondering if someone could help out in creating a data file, I already looked in the docs as well as other plugins to see if I could find something to suit my needs but I couldn't.

    I want to know how I could create a data file looking something like the following and also maybe how to read it:
    Code:
    {
      "steamid": {
          "item.shortname":  0,
          "item.shortname":  0
        }
      "steamid": {
          "item.shortname": 0,
          "item.shortname": 0
        }
    }
    Thanks in advance :)
     
  2. The docs are a bit weird I can agree(for data files at least).
    Code:
                StoredData storedData;
                class StoredData{
                    Dictionary<ulong, ItemClass> data = new Dictionary<ulong, ItemClass>();
                }            class ItemClass{
                    Dictionary<string, int> items = new Dictionary<string, int>();
                }
    Should work for your needs. Just a short walk through of it. StoredData is what you will save and load from a data file/.json. The dictionary inside StoredData is where you will save all of your steamids, (which you can change from ulong if you wish to save in a string format for ID's). Within the Dictionary is ItemClass which stores a dictionary with a string and a int. Which is of course the "item.shortname": 0, thing. And you can always take a look at any of my plugins, or some other plugins that use datafiles for an example ;)
     
  3. Thanks for all your help, they should update the docs for data files with something like that along with an explanation.
    Wait one more thing now how would I read that information from the file, if say I wanted to find the value of rifle.ak in the following datafile below?
    Code:
    {
      "7656xxxxxx": {
          "rifle.ak":  5,
          "item.shortname":  0
        }
      "steamid": {
          "item.shortname": 0,
          "item.shortname": 0
        }
    }
     
  4. storedData.data[player.userID].items["rifle.ak"]; //returns 5
    or if your using string userid
    storedData.data[player.UserIDString].items["rifle.ak"]; //returns 5
     
  5. How do I add the steamIDs in the ulong?
    i have tried doing something like;
    Code:
    [ChatCommand("Test")]
            void Test(BasePlayer player, string command, string[] args)
            {
                ulong userid = player.userID;
                if (storedData.data.Contains(player.userID)) return;
                PrintToChat(player, "Saving your data to the file");
                storedData.data.Add(userid);
                Interface.Oxide.DataFileSystem.WriteObject("Datafile", storedData);
                }
    but no success
     
    Last edited by a moderator: Feb 19, 2017
  6. I get this error error CS1501: No overload for method `Add' takes `1' arguments
     
  7. storedData.data.Add(userid, new ItemClass());
     
  8. Now I get this error;
    error CS0122: `Oxide.Plugins.MyPlugin.StoredData.data' is inaccessible due to its protection level
     
  9. Set your class to public, along with its inner variables.
     
  10. Sorry to keep bugging you but, how would I say add rifle.ak to someone and also how do I check whether the steamid already exist inside the data file
    EDIT
    I got how to check for the steamID already exist but what about adding the rifle.ak with value
    Code:
    if (storedData.data.ContainsKey(userid)) return;
    EDIT 2
    I got that too for adding
    Code:
    if (!storedData.data.ContainsKey(userid))
                    storedData.data.Add(userid, new ItemClass());            storedData.data[userid].items.Add("rifle.ak", num);
     
    Last edited by a moderator: Feb 20, 2017