Advertisement
Eddlm

Save/Load player stats (Drag Meets)

Oct 19th, 2017
436
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.85 KB | None | 0 0
  1.         public static void LoadPlayerStats(Racer racer)
  2.         {
  3.  
  4.             XmlDocument document = new XmlDocument();
  5.             document.Load(PlayerFile);
  6.             int pat = 0;
  7.             while (document == null && pat < 500)
  8.             {
  9.                 document.Load(PlayerFile);
  10.                 Script.Wait(0);
  11.             }
  12.             XmlElement root = document.DocumentElement;
  13.  
  14.             XmlNode list = root.SelectSingleNode("//Wins");
  15.             if (list != null) racer.Wins= int.Parse(list.InnerText);
  16.  
  17.             list = root.SelectSingleNode("//Loses");
  18.             if (list != null) racer.Loses = int.Parse(list.InnerText);
  19.         }
  20.  
  21.  
  22.  
  23.         public static void SavePlayerstats()
  24.         {
  25.  
  26.             if (!DragMeets.PersistentRacers) return;
  27.  
  28.             XmlDocument document = new XmlDocument();
  29.             document.Load(PlayerFile);
  30.             int pat = 0;
  31.             while (document == null && pat < 500)
  32.             {
  33.                 document.Load(PlayerFile);
  34.                 Script.Wait(0);
  35.             }
  36.             XmlElement root = document.DocumentElement;
  37.  
  38.  
  39.             XmlNode list = root.SelectSingleNode("//Wins");
  40.             if (list == null)
  41.             {
  42.                XmlNode wins= document.CreateNode(XmlNodeType.Element, "Wins", null);
  43.                 document.AppendChild(wins);
  44.                 list = wins;
  45.             }
  46.  
  47.             list.InnerText = GetPlayerRacer().Wins.ToString();
  48.  
  49.  
  50.             list = root.SelectSingleNode("//Loses");
  51.             if (list == null)
  52.             {
  53.                 XmlNode loses = document.CreateNode(XmlNodeType.Element, "Loses", null);
  54.                 document.AppendChild(loses);
  55.                 list = loses;
  56.             }
  57.  
  58.             list.InnerText = GetPlayerRacer().Loses.ToString();
  59.  
  60.  
  61.             document.Save(PlayerFile);
  62.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement