1. Hello, right now my system stores the players time for completing a map, but it does not store the Steam64. Does anyone have any ideas for that?


    Code:
     private void LoadDataOne()
            {
              fastestTimesOne = Interface.Oxide.DataFileSystem.ReadObject<List<float>>(Name + "_TimesOne");
            }
            private void SaveDataOne()
            {
              Interface.Oxide.DataFileSystem.WriteObject<List<float>>(Name + "_TimesOne", fastestTimesOne);
            }
    Code:
                  fastestTimesOne.Add(time);
                  SaveDataOne();
    
     
  2. Wulf

    Wulf Community Admin

    Why would you store it as a float? A Steam ID is generally a ulong.
     
  3. with floats not as floats
     
  4. Wait so it stores a bunch of floats but doesn't connect them to userID of the players?

    Edit: If so, I suggest using a dictionary instead of list...
     
  5. OK, so what i want is a steam64 to be stored with the specific users float
     
  6. Create a custom class or use a dictionary.
     
  7. I don't believe you understand. I want the users float associated with a float in the data file. Sorry for the misunderstanding
     
  8. I believe I do understand, you want to map the Steam IDs to the times.
     
  9. Code:
            //Data class is what we use to access our data, simple enough.
            public Data storedData;
            public class Data
            {
                //A dictionary with the key of a ulong(user ID), and the value of a float(time). Used to store the player and link it to a float.
                public Dictionary<ulong, float> yourTimes = new Dictionary<ulong, float>();
            }
            //Load data
            public void LoadData()
            {
                storedData = Interface.Oxide.DataFileSystem.ReadObject<Data>(this.Title);
            }
            //Getting the users data, returns 0 and creates a new player if none exists.
            public float GetUserTime(ulong id)
            {
                float tryData = 0f;
                if(!storedData.yourTimes.TryGetValue(id, out tryData))
                    storedData.yourTimes.Add(id, 0);            return tryData;
            }
            //Sets a user time.
            public void SetUserTime(ulong id, float time)
            {
                if (!storedData.yourTimes.ContainsKey(id))
                {
                    storedData.yourTimes.Add(id, time);
                    return;
                }
                storedData.yourTimes[id] = time;
            }
            //Writes data to the file.
            public void WriteData()
            {
                Interface.Oxide.DataFileSystem.WriteObject<Data>(this.Title, storedData);
            }
    A basic example of what you want. As Kappasaurus said, you've gotta use a custom class/dictionary to store the data and link it to an object. In my example im using a dictionary with a ulong and float, this could easily be adapted to store a class and link that to a player.
    [DOUBLEPOST=1516991680][/DOUBLEPOST]Side note, you don't have to store it in the Data class, I think you can just write the dictionary to data if that's all you are going to be storing.