HyperionSniper

Project Zomboid Adjustment Generator Script (C#)

Aug 21st, 2022 (edited)
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.33 KB | Gaming | 0 0
  1. // 1) save https://pzwiki.com/wiki/Weapons as .html file
  2. // 2) save code below as .cs file
  3. // 3) rename .html file to input.html and put in same folder as .cs file
  4. // 4) run .cs file using VS code or something, include the NuGet package HtmlAgilityPack
  5. // 5) replace Durability_Overhaul.lua adjustments with console outputs
  6.  
  7. using HtmlAgilityPack;                 
  8.  
  9. var doc = new HtmlDocument();
  10. doc.Load(new StreamReader("input.html"));
  11.  
  12. var nodes = doc.DocumentNode.SelectNodes("//tbody/tr").ToArray();
  13.  
  14. for(int i = 0; i < nodes.Length; i++) {
  15.     var node = nodes[i];
  16.    
  17.     var conditionNode = node.SelectSingleNode("td[16]");
  18.     var conditionLowerChanceNode = node.SelectSingleNode("td[17]");
  19.  
  20.     if(node.SelectSingleNode("td[19]") != null){
  21.         var nameNodes = node.SelectSingleNode("td[19]").ChildNodes.ToArray();
  22.  
  23.         int condition = 0;
  24.         if(conditionNode != null && Int32.TryParse(conditionNode.InnerHtml, out condition)) {
  25.             for(int n = 0; n < nameNodes.Length; n++){
  26.                 var nameNode = nameNodes[n];
  27.  
  28.                 if(!string.IsNullOrWhiteSpace(nameNode.InnerHtml)){
  29.                     Console.WriteLine(@"Adjust(""{0}"", ""{1}"", {2})", nameNode.InnerHtml, "ConditionMax", condition * 2);
  30.                     Console.WriteLine(@"Adjust(""{0}"", ""{1}"", {2})", nameNode.InnerHtml, "ConditionLowerChanceOneIn", Int32.Parse(conditionLowerChanceNode.InnerHtml) * 2);
  31.                 }
  32.             }
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment