1. On my C# learning for Plugins I built a data file with player data and under the player steam ID I want to store alerts (messages) that will be sent to him when he connects to the server. Unfurtunately I've issues with the code when trying to add new alerts to the list Alerts inside the data file.

    This is the code that I use to add the alerts:
    Code:
    if (!(data.ContainsKey("Alerts")))
                        data.Add("Alerts", new List<string>());
                   
                    var offAlert = amountAlert.ToString()+"x "+sale.itemName;
                    var alerts = data["Alerts"] as List<string>;
     
                    alerts.Add(offAlert);
    
    This is how I want the data to be saved:
    {
    "76561198030425042": {
    "Alerts": [
    "2x Wood",
    "4x Stones"
    ],
    "AlreadySent": "no"
    }
     
  2. perhaps something like this:
    Code:
    Dictionary<string, PlayerData> players;
    try
    {
        players = Interface.GetMod().DataFileSystem.ReadObject<Dictionary<string, PlayerData>>("PluginNamePlayers");
    }
    catch (Exception)
    {
        players = new Dictionary<string, PlayerData>();
    }
    PlayerData player;
    if (!players.TryGetValue("steamid1232435435", out player))
    {
        players.Add("steamid1232435435", player = new PlayerData());
    }
    player.Alerts.Add("alert" + new Random().Next());
    Interface.GetMod().DataFileSystem.WriteObject("PluginNamePlayers", players);
    and:
    Code:
    class PlayerData
    {
        public List<string> Alerts;
        public bool AlreadySent;    public PlayerData()
        {
            Alerts = new List<string>();
            AlreadySent = false;
        }
    }