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();
Storing Steam64 with floats
Discussion in 'Rust Development' started by Sonny-Boi, Jan 26, 2018.
-
Wulf Community Admin
Why would you store it as a float? A Steam ID is generally a ulong.
-
with floats not as floats
-
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... -
OK, so what i want is a steam64 to be stored with the specific users float
-
-
I don't believe you understand. I want the users float associated with a float in the data file. Sorry for the misunderstanding
-
-
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); }
[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.