Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.75 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Reflection;
  5. using System.Text;
  6.  
  7. using Newtonsoft.Json;
  8. using Newtonsoft.Json.Converters;
  9. using UnityEngine;
  10. using Oxide.Core;
  11.  
  12. namespace Oxide.Plugins
  13. {
  14.     [Info("LootModifier", "Jojolepro & Mr. Blue/AltCom.io", "1.3.0")]
  15.     class LootModifier : HurtworldPlugin{
  16.         bool gen = false;
  17.         Dictionary<string, Dictionary<string, object>> s;
  18.         void OnServerInitialized()
  19.         {
  20.             timer.Once (1f, () => {
  21.                 if(!gen)
  22.                     Apply();
  23.                 else
  24.                     GenData();
  25.             });
  26.         }
  27.         void Loaded()
  28.         {
  29.             s = Interface.Oxide.DataFileSystem.ReadObject<Dictionary<string, Dictionary<string, object>>>("LootModifier");
  30.             if(s == null || s.Count == 0) gen = true;
  31.         }
  32.         void GenData(){
  33.             Dictionary<string, Dictionary<string, object>> o = new Dictionary<string, Dictionary<string, object>>();
  34.             foreach(var l in RuntimeHurtDB.Instance.GetAll<LootTree>()){
  35.                 l.OnBeforeSerialize();
  36.                 Dictionary<string, object> json =  JsonConvert.DeserializeObject<Dictionary<string, object>>(l.TreeJsonData.JsonText);
  37.                 o.Add(RuntimeHurtDB.Instance.GetGuid(l), json);
  38.             }
  39.             Interface.Oxide.DataFileSystem.WriteObject("LootModifier",o);
  40.         }
  41.         void Apply(){
  42.             foreach(var e in s){
  43.                 var l = RuntimeHurtDB.Instance.GetObjectByGuid<LootTree>(e.Key);
  44.                 l.OnBeforeSerialize();
  45.                 l.TreeJsonData.JsonText = JsonConvert.SerializeObject(e.Value);
  46.                 l.OnAfterDeserialize();
  47.             }
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement