1. After having the plugin save the userID with some other data, how do I scan whether of not a BasePlayer uID is in the data? and if it is, how do I add another line of data into that uID section? I have tried to check other plugins as reference, but I can't figure it out.

    ex:
    Code:
    {
          "uID": "76561198015462577", //check for user
          "code": [
            "asdasdasd" //add more stuff after this
          ]
        }
     
  2. If its in storedData(class StoredData)
    Code:
    if(storedData.ClassName.ContainsKey(player.userID))
    {
          //Your code here if he is in the storedData
    }
    else
    {
          //Your code if he is not in the data,
    }
    If its not in storedData(just a dictionary, hash, list, etc)
    Code:
    if(Class.ContainsKey(player.userID))
    {
          //If it does contain player
    }
    else
    {
         //If it does not contain player.
    }
    [DOUBLEPOST=1457827673][/DOUBLEPOST]For example,
    Code:
    class StoredData
    {
        public Dictionary<ulong, PlayerStats> Stats  = new Dictionary<ulong, PlayerStats>();
        public StoredData()
        {
         }
    }class PlayerStats
    {
          public string Name;
          public PlayerStats()
          {
          }
    }StoredData storedData;//Add/Receive//        private void InitUserData(BasePlayer player)
            {
                if(!storedData.Stats.ContainsKey(player.userID))
                {
                    storedData.Stats.Add(player.userID, new PlayerStats());
                    storedData.Stats[player.userID].Name = player.displayName;
                    SaveData();
                }
                else
                {
              
                 }
           }void SaveData()
    {    Interface.Oxide.DataFileSystem.WriteObject(this.Title, storedData);
    }void Loaded()
    {
          storedData = Interface.GetMod().DataFileSystem.ReadObject<StoredData>(this.Title);
    }
     
    Last edited by a moderator: Mar 13, 2016
  3. I'm getting
    Code:
    `System.Collections.Generic.List<Oxide.Plugins.Promocodes.Redeemed>' does not contain a definition for `ContainsKey' and no extension method `ContainsKey' of type `System.Collections.Generic.List<Oxide.Plugins.Promocodes.Redeemed>

    IDK why it's saying that, I have the right namespace...

    also here's my save data
    Code:
    class Redeemed
            {
                public string uID = "";
                public List<String> code = new List<string>();
                public Redeemed()
                {
                }
                public Redeemed(BasePlayer Player, string codeRedeemed)
                {
                    uID = Player.UserIDString;
                    code.Add(codeRedeemed);
                }
            }
            class SaveData
            {
                public List<Redeemed> isRedeemed = new List<Redeemed>();
                public SaveData()
                {
                }
            }        SaveData data;
    and here's the checking
    Code:
    if (data.isRedeemed.ContainsKey(Player.UserIDString))
                {
                    SendReply(player, "Exist");
                }
     
  4. You can't search for a key in a list

    You would be better off using a dictionary and using the player id as the key for ease of reference to it
    Code:
    class Redeemed
            {
                public List<string> code = new List<string>();
                public Redeemed()
                {
                }
                public Redeemed(BasePlayer Player, string codeRedeemed)
                {
                    code.Add(codeRedeemed);
                }
            }
            class SaveData
            {
                public Dictionary<ulong, Redeemed> isRedeemed = new Dictionary<ulong, Redeemed>();
                public SaveData()
                {
                }
            }        SaveData data;
    Or if you aren't planning on saving any data other then the list of codes you can be rid of the class and have the list in the dictionary

    Code:
    SaveData data;
            public class SaveData
            {
                public Dictionary<ulong, List<string>> isRedeemed = new Dictionary<ulong, List<string>>();
                public SaveData()
                {
                }
            }
            void Function(BasePlayer player, string code)
            {
                if (!data.isRedeemed.ContainsKey(player.userID))
                    data.isRedeemed.Add(player.userID, new List<string>());
                data.isRedeemed[player.userID].Add(code);
            }
     
    Last edited by a moderator: Mar 13, 2016
  5. Oh, didn't realize he was using a list. Do [if(storedData.isRedeemed.Contains(player.userID))]
    [DOUBLEPOST=1457832048][/DOUBLEPOST]Of course replace "storedData" and "isRedeemed" with what your plugin needs.
     
  6. that works. Thanks man.