Advertisement
Xyberviri

StackSizes.cs

Mar 29th, 2015
449
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.54 KB | None | 0 0
  1. // Reference: Oxide.Ext.Rust
  2. // Reference: Newtonsoft.Json
  3.  
  4. /*
  5.  * The MIT License (MIT)
  6.  *
  7.  * Copyright (c) 2015 Looking For Gamers, Inc. <support@lfgame.rs>
  8.  *
  9.  * Permission is hereby granted, free of charge, to any person obtaining a copy
  10.  * of this software and associated documentation files (the "Software"), to deal
  11.  * in the Software without restriction, including without limitation the rights
  12.  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13.  * copies of the Software, and to permit persons to whom the Software is
  14.  * furnished to do so, subject to the following conditions:
  15.  
  16.  * The above copyright notice and this permission notice shall be included in
  17.  * all copies or substantial portions of the Software.
  18.  
  19.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20.  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22.  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23.  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24.  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25.  * THE SOFTWARE.
  26.  */
  27.  
  28. //Microsoft NameSpaces
  29. using System;
  30. using System.IO;
  31. using System.Collections.Generic;
  32. using System.Linq;
  33. using System.Reflection;
  34.  
  35. // Rust Unity Namespaces
  36. using Rust;
  37. using UnityEngine;
  38.  
  39. //Oxide NameSpaces
  40. using Oxide.Core;
  41. using Oxide.Core.Logging;
  42. using Oxide.Core.Plugins;
  43.  
  44. //External NameSpaces
  45. using Newtonsoft.Json;
  46. using Newtonsoft.Json.Converters;
  47.  
  48. namespace Oxide.Plugins
  49. {
  50.     [Info("Stack Sizes", "Looking For Gamers <support@lfgame.rs>", "1.1.3", ResourceId = 812)]
  51.     public class StackSizes : RustPlugin
  52.     {
  53.         #region Other Classes
  54.         public class configObj
  55.         {
  56.             public List<itemMeta> items { set; get; }
  57.             public configObj() { items = new List<itemMeta>(); }
  58.         }
  59.  
  60.         public class itemMeta
  61.         {
  62.             public string name { set; get; }
  63.             public int stackSize { set; get; }
  64.             public itemMeta() { stackSize = 1; }
  65.         }
  66.         #endregion
  67.  
  68.         public configObj config;
  69.         private string configPath;
  70.         private bool loaded = false;
  71.  
  72.         #region hook methods
  73.         void SetupConfig()
  74.         {
  75.             if (this.loaded)
  76.             {
  77.                 return;
  78.             }
  79.  
  80.             LoadConfig();
  81.             this.configPath = Manager.ConfigPath + string.Format("\\{0}.json", Name);
  82.             this.config = JsonConvert.DeserializeObject<configObj>((string)JsonConvert.SerializeObject(Config["Config"]).ToString());
  83.  
  84.             try
  85.             {
  86.                 this.SetStackSizes();
  87.                 this.loaded = true;
  88.             }
  89.             catch (NullReferenceException e)
  90.             {
  91.                 this.loaded = false;
  92.             }
  93.         }
  94.  
  95.         void Loaded()
  96.         {
  97.             //Puts("\n\n---------------------------------------------------------------------------------------------------------------------\n\n");
  98.             this.SetupConfig();
  99.             this.Print("StackSizes by Looking For Gamers, has been started");
  100.         }
  101.  
  102.         [HookMethod("OnServerInitialized")]
  103.         void OnServerInitialized()
  104.         {
  105.             this.SetupConfig();
  106.         }
  107.  
  108.         [HookMethod("LoadDefaultConfig")]
  109.         void CreateDefaultConfig()
  110.         {
  111.             configObj localConfig = new configObj();
  112.  
  113.             localConfig.items = JsonConvert.DeserializeObject<List<itemMeta>>(
  114.                 "[" +
  115.                 "{'name': 'bone_fragments', 'stackSize': 10000}," +
  116.                 "{'name': 'charcoal', 'stackSize': 10000}," +
  117.                 "{'name': 'cloth', 'stackSize': 10000}," +
  118.                 "{'name': 'fat_animal', 'stackSize': 10000}," +
  119.                 "{'name': 'gunpowder', 'stackSize': 10000}," +
  120.                 "{'name': 'lowgradefuel', 'stackSize': 10000}," +
  121.                 "{'name': 'metal_fragments', 'stackSize': 10000}," +
  122.                 "{'name': 'metal_ore', 'stackSize': 10000}," +
  123.                 "{'name': 'metal_refined', 'stackSize': 10000}," +
  124.                 "{'name': 'paper', 'stackSize': 10000}," +
  125.                 "{'name': 'stones', 'stackSize': 100000}," +
  126.                 "{'name': 'sulfur', 'stackSize': 10000}," +
  127.                 "{'name': 'sulfur_ore', 'stackSize': 100000}," +
  128.                 "{'name': 'wood', 'stackSize': 100000}" +
  129.                 "]"
  130.             );
  131.  
  132.             this.config = localConfig;
  133.             Config["Config"] = this.config;
  134.  
  135.             Config.Save(this.configPath);
  136.             LoadConfig();
  137.         }
  138.  
  139.         private void SetStackSizes()
  140.         {
  141.             foreach (itemMeta meta in config.items)
  142.             {
  143.                 Item item = ItemManager.CreateByName(meta.name, 1);
  144.                 item.info.stackable = meta.stackSize;
  145.             }
  146.         }
  147.  
  148.         private void Print(object msg)
  149.         {
  150.             Puts("{0}: {1}", Title, (string) msg);
  151.         }
  152.         #endregion
  153.  
  154.         #region console commands
  155.         [ConsoleCommand("stacksizes.reload")]
  156.         void cmdConsoleReload(ConsoleSystem.Arg arg)
  157.         {
  158.             this.SetupConfig();
  159.             this.Print("StackSizes Config reloaded.");
  160.         }
  161.  
  162.         [ConsoleCommand("stacksizes.version")]
  163.         void cmdConsoleVersion(ConsoleSystem.Arg arg)
  164.         {
  165.             this.Print(Version.ToString());
  166.         }
  167.         #endregion
  168.     }
  169.      
  170.    
  171. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement