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

FREE MinicopterStorage : 1.0.1 1.0.1

Нет прав для скачивания
C#:
using Newtonsoft.Json;
using Oxide.Core;
using System.Linq;
using UnityEngine;
namespace Oxide.Plugins {
    [Info("MinicopterStorage", "OxideBro", "1.0.1")]
    class MinicopterStorage : RustPlugin {
        static PluginConfig config;
        protected override void LoadDefaultConfig() {
            PrintWarning($"Thank you for downloading the {Name} ({Version}) plugin directly from the {Author} developer. Please note that sharing this plugin with third parties will void your guaranteed update entitlement!");
            config = PluginConfig.DefaultConfig();
        }
        protected override void LoadConfig() {
            base.LoadConfig();
            config = Config.ReadObject<PluginConfig>();
            if (config.PluginVersion < Version) UpdateConfigValues();
            Config.WriteObject(config, true);
        }
        private void UpdateConfigValues() {
            PluginConfig baseConfig = PluginConfig.DefaultConfig();
            if (config.PluginVersion < Version) {
                PrintWarning("Config update detected! Updating config values...");
                PrintWarning("Config update completed!");
            }
            config.PluginVersion = Version;
        }
        protected override void SaveConfig() {
            Config.WriteObject(config);
        }
        private class PluginConfig {
            [JsonProperty("Storage Prefab")]
            public string StoragePrefab = "assets/prefabs/deployable/hot air balloon/subents/hab_storage.prefab";
            [JsonProperty("Panel Name")]
            public string PanelName = "generic_resizable";
            [JsonProperty("Inventory Capacity")]
            public int InventoryCapacity = 18;
            [JsonProperty("Configuration version")]
            public VersionNumber PluginVersion = new VersionNumber();
            public static PluginConfig DefaultConfig() {
                return new PluginConfig {
                    StoragePrefab = "assets/prefabs/deployable/hot air balloon/subents/hab_storage.prefab", PanelName = "generic_resizable", InventoryCapacity = 10, PluginVersion = new VersionNumber(),
                }
                ;
            }
        }
        private const BaseEntity.Slot StorageSlot = BaseEntity.Slot.UpperModifier;
        void Loaded() {
            Unsubscribe("OnEntitySpawned");
        }
        void OnServerInitialized(bool init) {
            Subscribe("OnEntitySpawned");
            if (!init) foreach (var copter in BaseNetworkable.serverEntities.Where(p => p != null && !p.IsDestroyed && p.GetComponent<Minicopter>() != null)) {
                InitStorage(copter as Minicopter);
            }
        }
        void OnEntitySpawned(Minicopter entity) {
            if (entity == null) return;
            InitStorage(entity);
        }
        private void OnEntityDeath(Minicopter minicopter) {
            if (minicopter == null) return;
            var storageEnity = minicopter.GetSlot(StorageSlot);
            if (storageEnity == null || storageEnity.IsDestroyed || storageEnity.GetComponent<StorageContainer>() == null) return;
            DropItems(minicopter, storageEnity.GetComponent<StorageContainer>());
        }
        void InitStorage(Minicopter copter) {
            if (copter == null || copter.IsDestroyed || (copter.GetSlot(StorageSlot) != null && !copter.GetSlot(StorageSlot).IsDestroyed) || (copter.GetComponentInChildren<StorageContainer>() != null && copter.GetComponentInChildren<StorageContainer>().PrefabName.Contains(config.StoragePrefab))) return;
            var StorageLocalPosition = new Vector3(0, 0.4f, -0.78f);
            var StorageLocalRotation = new Quaternion(0.5f, 0.5f, 0f, 0f);
            var storage = GameManager.server.CreateEntity(config.StoragePrefab, StorageLocalPosition, StorageLocalRotation) as StorageContainer;
            if (storage == null) return;
            copter.SetSlot(StorageSlot, storage);
            storage.SetParent(copter);
            storage.Spawn();
            storage.enableSaving = true;
            storage.inventory.capacity = config.InventoryCapacity;
            storage.panelName = config.PanelName;
            storage.SendNetworkUpdateImmediate();
        }
        private string StorageDeployEffectPrefab = "assets/prefabs/deployable/small stash/effects/small-stash-deploy.prefab";
        private string DropBagPrefab = "assets/prefabs/misc/item drop/item_drop.prefab";
        private void DropItems(Minicopter minicopter, StorageContainer storage, BasePlayer pilot = null) {
            if (minicopter == null || storage == null || storage.IsDestroyed) return;
            var itemList = storage.inventory.itemList;
            if (itemList == null || itemList.Count <= 0) return;
            var dropPosition = storage.transform.position;
            if (pilot != null) {
                pilot.EndLooting();
            }
            Effect.server.Run(StorageDeployEffectPrefab, storage.transform.position);
            storage.inventory.Drop(DropBagPrefab, dropPosition, storage.transform.rotation * Quaternion.Euler(90, 0, 0), 0);
        }
        [ConsoleCommand("reset_storages")]
        void cmdResetStorages(ConsoleSystem.Arg args) {
            if (args.Connection != null) return;
            foreach (var entity in BaseNetworkable.serverEntities.Where(p => p != null && !p.IsDestroyed && p.GetComponent<Minicopter>() != null)) {
                var copter = entity as Minicopter;
                copter.GetSlot(StorageSlot)?.Kill();
                InitStorage(copter);
            }
        }
    }
}

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