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

FREE ClubFirst : 1.0.0 1.0.0

Нет прав для скачивания
C#:
using Oxide.Core;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

namespace Oxide.Plugins
{
    /*ПЛАГИН БЫЛ ПОФИКШЕН С ПОМОЩЬЮ ПРОГРАММЫ СКАЧАНОЙ С https://discord.gg/dNGbxafuJn */ [Info("ClubFirst", "https://discord.gg/dNGbxafuJn", "1.0.0")]
    [Description("ClubFirst")]
    class ClubFirst : RustPlugin
    {
        #region Classes
        private class PlayerData
        {
            public bool AirCalled = false;
            public int Position = 0;
        }

        private class PluginConfig
        {
            public bool CanLootAnyone = false;
            public int MaxPlayers = 100;
            public bool CanLootAdmin = true;
            public int Code = 5555;
            public int MinCapitacy = 6;
            public List<CustomItem> dropItems;
        }

        private class CustomItem
        {
            public string ShortName;
            public int MinAmount = 1;
            public int MaxAmount = 10;
            public ulong Skin;
            public int Chance = 50;
        }
        #endregion

        #region Variables
        [PluginReference]
        Plugin ImageLibrary;

        private PluginConfig config;
        private Dictionary<ulong, PlayerData> playerData;
        private Dictionary<Vector3, BasePlayer> tempData;
        private string DataPath = "WIPE/First/Data";
        private static string UI_Layer = "ClubFirst_UI";
        private string OpenedImage = "https://i.imgur.com/vgV961o.png";
        private string ClosedImage = "https://i.imgur.com/vvR163N.png";
        private HashSet<ulong> playerClosed;
        private HashSet<ulong> lootedAirs;
        #endregion

        #region Oxide
        private void Init()
        {
            config = Config.ReadObject<PluginConfig>();
        }
        
        void OnServerInitialized()
        {
            playerClosed = new HashSet<ulong>();
            lootedAirs = new HashSet<ulong>();
            tempData = new Dictionary<Vector3, BasePlayer>();
            playerData = new Dictionary<ulong, PlayerData>();
            if (Interface.Oxide.DataFileSystem.ExistsDatafile(DataPath))
                playerData = Interface.Oxide?.DataFileSystem?.ReadObject<Dictionary<ulong, PlayerData>>(DataPath);

            LoadImages();

            BasePlayer.activePlayerList.ToList().ForEach(p => { if (playerData.ContainsKey(p.userID) && !playerData[p.userID].AirCalled) Draw_Info(p); });

            PrintWarning("Plugin loaded! Author: BadMandarin!");
        }

        private void LoadImages()
        {
            if (plugins.Exists("ImageLibrary"))
            {
                ImageLibrary.Call("AddImage", OpenedImage, GetNameByURL(OpenedImage));
                ImageLibrary.Call("AddImage", ClosedImage, GetNameByURL(ClosedImage));
            }
            else timer.Once(2f, LoadImages);
        }

        void Unload()
        {
            Interface.Oxide.DataFileSystem.WriteObject(DataPath, playerData);
            PrintWarning("Plugin unloaded! Author: BadMandarin!");
        }

        void OnPlayerConnected(BasePlayer player)
        {
            if (player == null) return;
            if (player.HasPlayerFlag(BasePlayer.PlayerFlags.ReceivingSnapshot))
            {
                timer.Once(2f, () => OnPlayerConnected(player));
                return;
            }
            if (!player.IsConnected)
            {
                return;
            }
            if (playerData.ContainsKey(player.userID))
            {
                if(!playerData[player.userID].AirCalled)
                    Draw_Info(player);
                    
                return;
            }
            if (playerData.Count() > config.MaxPlayers) return;

            playerData.Add(player.userID, new PlayerData() { Position = playerData.Count()+1 });
            Draw_Info(player);
        }

        void OnEntitySpawned(BaseNetworkable entity)
        {
            if (entity == null) return;
            SupplyDrop drop = entity as SupplyDrop;
            if (drop == null) return;
            Vector3 pos = drop.GetDropPosition();
            pos.y = 0;
            if (tempData == null || tempData.Count < 1) return;
            var supplies = tempData.Where(x => Vector3.Distance(x.Key, pos) < 30).ToList();
            if (supplies.Count > 0)
            {
                drop.OwnerID = supplies[0].Value.userID;
                tempData.Remove(supplies[0].Key);
            }
        }
        
        void OnEntityKill(BaseNetworkable entity)
        {
            if (entity == null) return;
            SupplyDrop drop = entity as SupplyDrop;
            if (drop == null) return;
            
            if (!lootedAirs.Contains(drop.net.ID.Value)) return;

            lootedAirs.Remove(drop.net.ID.Value);
        }

        void OnPlayerInput(BasePlayer player, InputState input)
        {
            if (playerData.Count() > config.MaxPlayers) return;
            if (!(playerData.ContainsKey(player.userID) && !playerData[player.userID].AirCalled)) return; // я овощь
            Detonator det = player.GetHeldEntity() as Detonator;
            if (det != null && det.GetFrequency() == config.Code && input.WasJustPressed(BUTTON.FIRE_PRIMARY))
            {
                Vector3 vector3 = new Vector3();
                Quaternion quaternion = new Quaternion();
                BaseEntity baseEntity = GameManager.server.CreateEntity("assets/prefabs/npc/cargo plane/cargo_plane.prefab", vector3, quaternion, true);
                Vector3 dropPos = player.transform.position + new Vector3(0f, 10f, 0f); 
                if (baseEntity)
                {
                    baseEntity.GetComponent<CargoPlane>().InitDropPosition(dropPos);
                    baseEntity.Spawn();
                }
                dropPos.y = 0;
                playerData[player.userID].AirCalled = true;
                tempData.Add(dropPos, player);
                CuiHelper.DestroyUi(player, UI_Layer);
                SendReply(player, "[Server] Ваш аирдроп уже летит к вам!");
            }
        }

        object CanLootEntity(BasePlayer player, StorageContainer container)
        {
            try
            {
                if (!(container is SupplyDrop)) return null;
                if (container.OwnerID == 0) return null;
                if (lootedAirs.Contains(container.net.ID.Value)) return null;
                if (!player.IsAdmin && !config.CanLootAdmin)
                {
                    if (container.OwnerID != player.userID && !config.CanLootAnyone)
                    {
                        SendReply(player, "[Server] Только владелец может залутать этот аирдроп!");
                        return false;
                    }
                }

                ClearContainer(container as LootContainer);
                container.inventory.capacity = config.MinCapitacy;
                int items = 0;
                do
                {
                    var d = config.dropItems.GetRandom();
                    if (Core.Random.Range(0, 100) > d.Chance) continue;
                    Item it = ItemManager.CreateByName(d.ShortName, Core.Random.Range(d.MinAmount, d.MaxAmount + 1), d.Skin);
                    it.MoveToContainer(container.inventory);
                    items++;
                } while (items <= config.MinCapitacy);

                lootedAirs.Add(container.net.ID.Value);
            }
            catch (Exception e)
            {
            }

            return null;
        }
        #endregion

        #region Interface

        private void Draw_Info(BasePlayer player)
        {
            CuiElementContainer container = new CuiElementContainer();
            if (!playerClosed.Contains(player.userID))
                container = new CuiElementContainer()
            {
                {
                    new CuiPanel
                    {
                        CursorEnabled = false,
                        RectTransform =
                        {
                            AnchorMin = "0.5 0", AnchorMax = "0.5 0", OffsetMin = "205 0", OffsetMax = "375 100"
                        },
                        Image = {Color = "0 0 0 0" }
                    }, "Overlay", UI_Layer
                },
                {
                    new CuiElement
                    {
                        Parent = $"{UI_Layer}",
                        Components =
                        {
                            new CuiRawImageComponent
                            {
                                Png = GetImage(GetNameByURL(OpenedImage))
                            },
                            new CuiRectTransformComponent
                            {
                                AnchorMin = $"0 0",
                                AnchorMax = $"1 1",
                                OffsetMin = "0 0",
                                OffsetMax = "0 0"
                            }
                        }
                    }
                },
                {
                    new CuiElement
                    {
                        Parent = $"{UI_Layer}",
                        Components =
                        {
                            new CuiTextComponent
                            {
                                Text = "Промокод: " + config.Code, Align = TextAnchor.MiddleCenter, Font = "RobotoCondensed-Bold.ttf", FontSize = 15, Color = GetColor("#FFFFFF", 0.8f)
                            },
                            new CuiRectTransformComponent
                            {
                                AnchorMin = $"0 0",
                                AnchorMax = $"1 1",
                                OffsetMin = "0 0",
                                OffsetMax = "-17 0"
                            }
                        }
                    }
                },
                {
                    new CuiElement
                    {
                        Parent = $"{UI_Layer}",
                        Components =
                        {
                            new CuiTextComponent
                            {
                                Text = "Введи: /kit bonus", Align = TextAnchor.MiddleCenter, Font = "RobotoCondensed-Regular.ttf", FontSize = 10, Color = GetColor("#FFFFFF", 0.8f)
                            },
                            new CuiRectTransformComponent
                            {
                                AnchorMin = $"0 0",
                                AnchorMax = $"1 0",
                                OffsetMin = "0 19",
                                OffsetMax = "-17 45"
                            }
                        }
                    }
                },
                {
                    new CuiButton
                    {
                        RectTransform = { AnchorMin = "1 0", AnchorMax = "1 0", OffsetMin = "-35 0", OffsetMax = "-10 25" },
                        Button = { Color = "0 0 0 0", Command = "UI_ClubFirstClose" },
                        Text = { Text = "" }
                    }, UI_Layer
                },
                {
                    new CuiButton
                    {
                        RectTransform = { AnchorMin = "1 0", AnchorMax = "1 0", OffsetMin = "-18 40", OffsetMax = "0 62" },
                        Button = { Color = "0 0 0 0", Command = "UI_ClubFirstInfo" },
                        Text = { Text = "" }
                    }, UI_Layer
                },
            };
            else
                container = new CuiElementContainer()
                {
                    {
                        new CuiPanel
                        {
                            CursorEnabled = false,
                            RectTransform =
                            {
                                AnchorMin = "0.5 0", AnchorMax = "0.5 0", OffsetMin = "205 0", OffsetMax = "360 30"
                            },
                            Image = {Color = "0 0 0 0" }
                        }, "Overlay", UI_Layer
                    },
                    {
                        new CuiElement
                        {
                            Parent = $"{UI_Layer}",
                            Components =
                            {
                                new CuiRawImageComponent
                                {
                                    Png = GetImage(GetNameByURL(ClosedImage))
                                },
                                new CuiRectTransformComponent
                                {
                                    AnchorMin = $"0 0",
                                    AnchorMax = $"1 1",
                                    OffsetMin = "0 0",
                                    OffsetMax = "0 0"
                                }
                            }
                        }
                    },
                    {
                        new CuiButton
                        {
                            RectTransform = { AnchorMin = "1 0", AnchorMax = "1 0", OffsetMin = "-19 15", OffsetMax = "0 33" },
                            Button = { Color = "0 0 0 0", Command = "UI_ClubFirstClose" },
                            Text = { Text = "" }
                        }, UI_Layer
                    },
                };

            CuiHelper.DestroyUi(player, UI_Layer);
            CuiHelper.AddUi(player, container);
        }
        #endregion

        #region Commands
        [ConsoleCommand("UI_ClubFirstClose")]
        private void Console_UI_ClubFirstClose(ConsoleSystem.Arg arg)
        {
            BasePlayer player = arg.Player();
            if (player == null) return;
            if (playerClosed.Contains(player.userID))
            {
                playerClosed.Remove(player.userID);
            }
            else playerClosed.Add(player.userID);
            Draw_Info(player);
        }
        [ConsoleCommand("UI_ClubFirstInfo")]
        private void Console_UI_ClubFirstInfo(ConsoleSystem.Arg arg)
        {
            BasePlayer player = arg.Player();
            if (player == null) return;
            SendReply(player, "[RUSTCLUB] Возьмите в руки рацию из бонуса(/kit bonus) и введите промокод! И Аир-дроп прилетит к вам!");
        }
        #endregion

        #region Utils
        private string GetImage(string name)
        {
            string ID = (string)ImageLibrary?.Call("GetImage", name);
            if (ID == "")
                ID = (string)ImageLibrary?.Call("GetImage", name) ?? ID;

            return ID;
        }

        private static string GetNameByURL(string url)
        {
            var splitted = url.Split('/');
            var endUrl = splitted[splitted.Length - 1];
            var name = endUrl.Split('.')[0];
            return name;
        }

        public static string GetColor(string hex, float alpha = 1f)
        {
            var color = ColorTranslator.FromHtml(hex);
            var r = Convert.ToInt16(color.R) / 255f;
            var g = Convert.ToInt16(color.G) / 255f;
            var b = Convert.ToInt16(color.B) / 255f;
            //var a = Convert.ToInt16(color.A) / {DarkPluginsID}f;

            return $"{r} {g} {b} {alpha}";
        }

        private void ClearContainer(LootContainer container)
        {
            if (container.inventory == null)
            {
                container.inventory = new ItemContainer();
                container.inventory.ServerInitialize(null, 36);
                container.inventory.GiveUID();
            }
            else
            {
                while (container.inventory.itemList.Count > 0)
                {
                    Item item = container.inventory.itemList[0];
                    item.RemoveFromContainer();
                    item.Remove(0f);
                }
                container.inventory.capacity = 36;
            }

            container.inventory.itemList.Clear();
            container.inventory.Clear();
            ItemManager.DoRemoves();
        }

        protected override void LoadDefaultConfig()
        {
            Config.WriteObject(GetDefaultConfig(), true);
        }

        private PluginConfig GetDefaultConfig()
        {
            return new PluginConfig
            {
                dropItems = new List<CustomItem>()
                {
                    new CustomItem()
                    {
                        ShortName = "sulfur",
                        MinAmount = 100,
                        MaxAmount = 1000,
                        Skin = 0
                    }
                }
            };
        }
        #endregion
    }
}

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