Иконка ресурса

FREE RandomDeployables : 0.1.9 0.1.9

Нет прав для скачивания
C#:
// Все права принадлежат дискорд сообществу https://discord.gg/VgNHPpNrz6
 // Reference: Rust.Workshop
using System;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
using Newtonsoft.Json;
using System.Reflection;
using Facepunch.Steamworks;
using Rust;
namespace Oxide.Plugins {
    [Info("RandomDeployables", "Norn", "0.1.9", ResourceId = 2187)]
    [Description("Randomize deployable skins")]
    class RandomDeployables : RustPlugin {
        void Loaded() {
            permission.RegisterPermission("randomdeployables.able", this);
        }
        private static Dictionary<string, int> deployedToItem = new Dictionary<string, int>();
        private readonly FieldInfo skins2 = typeof(ItemDefinition).GetField("_skins2", BindingFlags.NonPublic | BindingFlags.Instance);
        private void InitializeTable() {
            deployedToItem.Clear();
            List<ItemDefinition> ItemsDefinition = ItemManager.GetItemDefinitions() as List<ItemDefinition>;
            foreach (ItemDefinition itemdef in ItemsDefinition) {
                if (itemdef.GetComponent<ItemModDeployable>() != null && !deployedToItem.ContainsKey(itemdef.GetComponent<ItemModDeployable>().entityPrefab.resourcePath)) deployedToItem.Add(itemdef.GetComponent<ItemModDeployable>().entityPrefab.resourcePath, itemdef.itemid);
            }
        }
        private void OnServerInitialized() {
            InitializeTable();
            webrequest.EnqueueGet("http://s3.amazonaws.com/s3.playrust.com/icons/inventory/rust/schema.json", PullWorkshopIDS, this);
        }
        Dictionary<ulong, ulong> SkinFromInventoryID = new Dictionary<ulong, ulong>();
        private void PullWorkshopIDS(int code, string response) {
            if (response != null && code == 200) {
                SkinFromInventoryID.Clear();
                ulong wsdl;
                var schema = JsonConvert.DeserializeObject<Rust.Workshop.ItemSchema>(response);
                var defs = new List<Inventory.Definition>();
                foreach (var item in schema.items) {
                    if (string.IsNullOrEmpty(item.itemshortname)) continue;
                    if (item.workshopdownload == null) {
                        wsdl = 0;
                    }
                    else {
                        wsdl = Convert.ToUInt64(item.workshopdownload);
                    }
                    SkinFromInventoryID.Add(item.itemdefid, wsdl);
                    var steamItem = Global.SteamServer.Inventory.CreateDefinition((int)item.itemdefid);
                    steamItem.Name = item.name;
                    steamItem.SetProperty("itemshortname", item.itemshortname);
                    steamItem.SetProperty("workshopid", item.workshopid);
                    steamItem.SetProperty("workshopdownload", item.workshopdownload);
                    defs.Add(steamItem);
                }
                Global.SteamServer.Inventory.Definitions = defs.ToArray();
                foreach (var item in ItemManager.itemList) skins2.SetValue(item, Global.SteamServer.Inventory.Definitions.Where(x => (x.GetStringProperty("itemshortname") == item.shortname) && !string.IsNullOrEmpty(x.GetStringProperty("workshopdownload"))).ToArray());
                Puts($"Pulled {SkinFromInventoryID.Count} skins.");
            }
            else {
                PrintWarning($"Failed to pull skins...Error {code}");
            }
        }
        protected override void LoadDefaultConfig() {
            // -- [ RESET ] ---
            Puts("No configuration file found, generating...");
            Config.Clear();
            // --- [ SETTINGS ] ---
            Config["Settings", "AllowDefaultSkin"] = false;
        }
        private List<int> GetSkins(ItemDefinition def) {
            List<int> skins;
            skins = new List<int>();
            if(Convert.ToBoolean(Config["Settings", "AllowDefaultSkin"])) {
                skins.Add(0);
            }
            if (def.skins != null) skins.AddRange(def.skins.Select(skin => skin.id));
            if (def.skins2 != null) skins.AddRange(def.skins2.Select(skin => skin.Id));
            return skins;
        }
        private void OnEntityBuilt(Planner planner, GameObject gameObject) {
            BaseEntity e = gameObject.ToBaseEntity();
            BasePlayer player = planner.GetOwnerPlayer();
            if (permission.UserHasPermission(player.net.connection.userid.ToString(), "randomdeployables.able")) {
                if (!(e is BaseEntity) || player == null) {
                    return;
                }
                if (deployedToItem.ContainsKey(e.PrefabName)) {
                    var def = ItemManager.FindItemDefinition(deployedToItem[e.PrefabName]);
                    var skins = GetSkins(def);
                    if (skins.Count == 0) return;
                    ulong skinid = Convert.ToUInt64(skins.GetRandom());
                    if (skinid != 0 && SkinFromInventoryID.ContainsKey(skinid) && SkinFromInventoryID[skinid] != 0) {
                        e.skinID = SkinFromInventoryID[skinid];
                    }
                    else {
                        e.skinID = skinid;
                    }
                    e.SendNetworkUpdate();
                }
            }
        }
    }
}

Автор
15FPS
Скачиваний
0
Просмотры
1
Первый выпуск
Обновление
Оценка
0.00 звёзд 0 оценок
Сверху