1. I followed the docs on storing and retrieving data, and it isn't working 100%. The data is stored everytime a player respawns. (It's set to respawn for easy testing)

    This leaves me to thing that the playTimeData.Players.Contains(info) isn't being checked properly.

    Could someone provide me with an idea as to what is wrong?

    Code:
    using System.Collections.Generic;
    using Oxide.Core;namespace Oxide.Plugins
    {
        [Info("PlayTime", "AnExiledGod", 1.0)]
        [Description("Logs players play time and allows you to view the players play time with a command.")]
        public class PlayTime : RustPlugin
        {
            class PlayTimeData
            {
                public HashSet<PlayerInfo> Players = new HashSet<PlayerInfo>();            public PlayTimeData()
                {
                }
            }        class PlayerInfo
            {
                public string SteamID;
                public string Name;            public PlayerInfo()
                {
                }            public PlayerInfo(BasePlayer player)
                {
                    SteamID = player.userID.ToString();
                    Name = player.displayName;
                }
            }        PlayTimeData playTimeData;        private void Loaded()
            {
                playTimeData = Interface.GetMod().DataFileSystem.ReadObject<PlayTimeData>("PlayTime");
            }        void OnPlayerRespawned(BasePlayer player)
            {
                var info = new PlayerInfo(player);
                if (playTimeData.Players.Contains(info))
                {
                    PrintToChat(player, "Your data has already been added to the file.");
                }
                else
                {
                    PrintToChat(player, "Saving your data to the file.");
                    playTimeData.Players.Add(info);
                    Interface.GetMod().DataFileSystem.WriteObject("PlayTime", playTimeData);
                }
            }        void OnPlayerDisconnected(BasePlayer player)
            {
                Puts("OnPlayerDisconnected works!");
            }
        }
    }
    
     
  2. the PlayTimeData uses a HashSet<PlayerInfo> and contains checks against an object hash, so when you create a new instance of PlayerInfo the Contains method will never return true since the new object has a new hash...you can try it this way:
    Code:
    using System.Collections.Generic;
    using Oxide.Core;namespace Oxide.Plugins
    {
        [Info("PlayTime", "AnExiledGod", 1.0)]
        [Description("Logs players play time and allows you to view the players play time with a command.")]
        public class PlayTime : RustPlugin
        {
            class PlayTimeData
            {
                public Dictionary<string, PlayerInfo> Players = new Dictionary<string, PlayerInfo>();            public PlayTimeData()
                {
                }
            }        class PlayerInfo
            {
                public string SteamID;
                public string Name;            public PlayerInfo()
                {
                }            public PlayerInfo(BasePlayer player)
                {
                    SteamID = player.userID.ToString();
                    Name = player.displayName;
                }
            }        PlayTimeData playTimeData;        private void Loaded()
            {
                playTimeData = Interface.GetMod().DataFileSystem.ReadObject<PlayTimeData>("PlayTime");
            }        void OnPlayerRespawned(BasePlayer player)
            {
                var info = new PlayerInfo(player);
                if (playTimeData.Players.ContainsKey(info.SteamID))
                {
                    PrintToChat(player, "Your data has already been added to the file.");
                }
                else
                {
                    PrintToChat(player, "Saving your data to the file.");
                    playTimeData.Players.Add(info.SteamID, info);
                    Interface.GetMod().DataFileSystem.WriteObject("PlayTime", playTimeData);
                }
            }        void OnPlayerDisconnected(BasePlayer player)
            {
                Puts("OnPlayerDisconnected works!");
            }
        }
    }
     
  3. That's exactly what I was looking for! Thank you very much! Still new to C# :)
    [DOUBLEPOST=1434849481,1434831538][/DOUBLEPOST]I know I marked this as solved, but could you help me again?

    The data that is stored is like this:

    Code:
    {
      "Players": {
        "76561198051290806": {
          "SteamID": "76561198051290806",
          "Name": "AnExiledGod",
          "LastLoginTime": 1434844747,
          "Played": 0
        }
      }
    }
    My code is

    Code:
    using System.Collections.Generic;
    using Oxide.Core;
    using System;
    using System.Globalization;namespace Oxide.Plugins
    {
        [Info("PlayTime", "AnExiledGod", 1.0)]
        [Description("Logs players play time and allows you to view the players play time with a command.")]
        public class PlayTime : RustPlugin
        {
            class PlayTimeData
            {
                public Dictionary<string, PlayerInfo> Players = new Dictionary<string, PlayerInfo>();            public PlayTimeData()
                {
                }
            }        class PlayerInfo
            {
                public string SteamID;
                public string Name;
                public long LastLoginTime;
                public int Played;            public PlayerInfo()
                {
                }            public PlayerInfo(BasePlayer player)
                {
                    SteamID = player.userID.ToString();
                    Name = player.displayName;
                    LastLoginTime = GrabCurrentTimestamp();
                    Played = 0;
                }
            }        PlayTimeData playTimeData;        private void Loaded()
            {
                playTimeData = Interface.GetMod().DataFileSystem.ReadObject<PlayTimeData>("PlayTime");
            }        void OnPlayerRespawned(BasePlayer player)
            {
                var info = new PlayerInfo(player);            if (playTimeData.Players.ContainsKey(info.SteamID))
                {
                    Puts("Player already has a PlayTime log.");                long lastLogin = playTimeData.Players[info.SteamID]["LastLoginTime"];                long totalPlayed = GrabCurrentTimestamp() - lastLogin;
                    Puts("Total Played: " + totalPlayed);
                }
                else
                {
                    Puts("Saving new player to PlayTime log.");
                    playTimeData.Players.Add(info.SteamID, info);
                    Interface.GetMod().DataFileSystem.WriteObject("PlayTime", playTimeData);
                }
            }        void OnPlayerDisconnected(BasePlayer player)
            {
                Puts("OnPlayerDisconnected works!");
            }        private static long GrabCurrentTimestamp()
            {
                long timestamp = 0;
                long ticks = DateTime.UtcNow.Ticks - DateTime.Parse("01/01/1970 00:00:00").Ticks;
                ticks /= 10000000;
                timestamp = ticks;            return timestamp;
            }
        }
    }
    
    I am attempting on line 56 to grab the LastLoginTime from the field, but this doesn't work. I realized after a lot of playing around that it's stored as a type of PlayerInfo, do you know how I can access that information individually?
     
  4. Try:
    long lastLogin = playTimeData.Players[info.SteamID].LastLoginTime;
     
  5. Wow, I could have sworn I'd tried that, but I apparently didn't, because now it's working. Again, I appreciate it. I hate running into these tiny little mistakes :(