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

FREE DropInventory : 1.0.3 1.0.3

Нет прав для скачивания
C#:
/*
Copyright © 2026 Mabel

All rights reserved. This plugin is protected by copyright law.

You may not modify, redistribute, or resell this software without explicit written permission from the copyright owner.

For any support please message me directly via Discord `mabel8686` or join my discord https://discord.gg/2GUsHZskCA

███╗   ███╗ █████╗ ██████╗ ███████╗██╗
████╗ ████║██╔══██╗██╔══██╗██╔════╝██║
██╔████╔██║███████║██████╔╝█████╗  ██║
██║╚██╔╝██║██╔══██║██╔══██╗██╔══╝  ██║
██║ ╚═╝ ██║██║  ██║██████╔╝███████╗███████╗
╚═╝     ╚═╝╚═╝  ╚═╝╚═════╝ ╚══════╝╚══════╝
*/
using Newtonsoft.Json;
using Oxide.Core;
using System;
using System.Collections.Generic;
using UnityEngine;
namespace Oxide.Plugins {
    [Info("Drop Inventory", "Mabel", "1.0.3")]
    [Description("Drops a player's inventory on command")]
    class DropInventory : RustPlugin {
#region Fields
        const string permission_use = "dropinventory.use";
        const string permission_bypass = "dropinventory.cooldown.bypass";
        const string permission_admin = "dropinventory.admin";
        readonly Dictionary<ulong, float> cooldowns = new Dictionary<ulong, float>();
        static Configuration config;
#endregion
#region Configuration
        public class BroadcastSettings {
            [JsonProperty("Chat Prefix")]
            public string chatPrefix;
            [JsonProperty("Use Chat Message")]
            public bool useChat;
            [JsonProperty("Use Game Tip Message")]
            public bool useTip;
        }
        public class DropSettings {
            [JsonProperty("Sound Effect")]
            public string soundEffect;
            [JsonProperty("Drop Velocity")]
            public float dropVelocity;
            [JsonProperty("Drop Main Container")]
            public bool dropMain;
            [JsonProperty("Drop Wear Container")]
            public bool dropWear;
            [JsonProperty("Drop Belt Container")]
            public bool dropBelt;
        }
        public class CommandSettings {
            [JsonProperty("Chat Command Cooldown")]
            public float commandCooldown;
            [JsonProperty("Player Chat Command")]
            public string playerCommand;
            [JsonProperty("Admin Chat Command")]
            public string adminCommand;
            [JsonProperty("Admin Console Command")]
            public string consoleCommand;
        }
        public class Configuration {
            [JsonProperty(PropertyName = "Broadcast Settings")]
            public BroadcastSettings BroadcastSettings;
            [JsonProperty(PropertyName = "Drop Inventory Settings")]
            public DropSettings DropSettings;
            [JsonProperty(PropertyName = "Command Settings")]
            public CommandSettings CommandSettings;
            public VersionNumber Version;
            public static Configuration DefaultConfig() {
                return new Configuration {
                    BroadcastSettings = new BroadcastSettings() {
                        chatPrefix = "<color=#FF0000>[DropInv]</color> ", useChat = false, useTip = true,
                    }
                    , DropSettings = new DropSettings() {
                        soundEffect = "assets/bundled/prefabs/fx/gestures/drink_vomit.prefab", dropVelocity = 5f, dropMain = true, dropWear = true, dropBelt = true,
                    }
                    , CommandSettings = new CommandSettings() {
                        commandCooldown = 60f, playerCommand = "drop", adminCommand = "drop.admin", consoleCommand = "drop.admin"
                    }
                    , Version = default(VersionNumber)
                }
                ;
            }
        }
        protected override void LoadConfig() {
            base.LoadConfig();
            try {
                config = Config.ReadObject<Configuration>();
                if (config == null) throw new Exception("Configuration file is null");
                bool isNewConfig = config.Version == default(VersionNumber);
                if (!isNewConfig && config.Version < Version) UpdateConfig();
                config.Version = Version;
                SaveConfig();
            }
            catch (Exception ex) {
                Debug.LogException(ex);
                PrintError($"Failed to load configuration: {ex.Message}");
            }
        }
        protected override void LoadDefaultConfig() => config = Configuration.DefaultConfig();
        protected override void SaveConfig() => Config.WriteObject(config);
        void UpdateConfig() {
            PrintWarning("Config update detected! Updating config values...");
            Configuration baseConfig = Configuration.DefaultConfig();
            if (config.Version < new VersionNumber(1, 0, 0)) config = baseConfig;
            config.Version = Version;
            PrintWarning("Config update completed!");
        }
#endregion
#region Localization
        protected override void LoadDefaultMessages() {
            lang.RegisterMessages(new Dictionary<string, string> {
                ["Cooldown"]
                = "Drop is on cooldown. Time remaining: <color=#FF0000>{0}</color> seconds.", ["DropAll"] = "Your Main, Belt and Wear items have been dropped.", ["DropMain"] = "Your Main items have been dropped.", ["DropBelt"] = "Your Belt items have been dropped.", ["DropWear"] = "Your Wear items have been dropped.", ["DropMainBelt"] = "Your Main and Belt items have been dropped.", ["DropMainWear"] = "Your Main and Wear items have been dropped.", ["DropBeltWear"] = "Your Belt and Wear items have been dropped.", ["NoContainers"] = "No containers are enabled for dropping items.", ["AdminDroppedItems"] = "Your items were dropped by an admin.", ["AdminDroppedItemsReply"] = "You dropped (Player: <color=#FF0000>{0}</color>) Items.", ["NoPermission"] = "You don't have permission to use this command.", ["AdminCommandUsage"] = "Usage: /drop.admin <all|belt|wear|main> <playername or steamid>", ["PlayerNotFound"] = "Player not found or multiple players found matching the name or ID provided.", ["Restrained"] = "You Can Not Use This Command While Restrained"
            }
            , this);
        }
#endregion
#region Initialization
        void Init() {
            permission.RegisterPermission(permission_use, this);
            permission.RegisterPermission(permission_bypass, this);
            permission.RegisterPermission(permission_admin, this);
            cmd.AddChatCommand(config.CommandSettings.playerCommand, this, nameof(DropInventoryCommand));
            cmd.AddChatCommand(config.CommandSettings.adminCommand, this, nameof(DropInventoryAdminCommand));
            cmd.AddConsoleCommand(config.CommandSettings.consoleCommand, this, nameof(DropInventoryAdminConsoleCommand));
        }
#endregion
#region Commands
        void DropInventoryCommand(BasePlayer player, string command, string[] args) {
            if (!permission.UserHasPermission(player.UserIDString, permission_use)) {
                if (config.BroadcastSettings.useChat) {
                    var message = $"{config.BroadcastSettings.chatPrefix} {string.Format(lang.GetMessage("NoPermission", this, player.UserIDString))}";
                    SendReply(player, message);
                }
                if (config.BroadcastSettings.useTip) {
                    player?.ShowToast(GameTip.Styles.Red_Normal, string.Format(lang.GetMessage("NoPermission", this, player.UserIDString)));
                }
                return;
            }
            if (!CanUseCommand(player)) return;
            PlayDropEffect(player);
            DropPlayerItems(player);
            if (config.BroadcastSettings.useChat) {
                var message = $"{config.BroadcastSettings.chatPrefix} {GetDropMessage(player)}";
                SendReply(player, message);
            }
            if (config.BroadcastSettings.useTip) {
                player?.ShowToast(GameTip.Styles.Blue_Normal, GetDropMessage(player));
            }
        }
        void DropInventoryAdminCommand(BasePlayer player, string command, string[] args) {
            if (!permission.UserHasPermission(player.UserIDString, permission_admin)) {
                if (config.BroadcastSettings.useChat) {
                    var message = $"{config.BroadcastSettings.chatPrefix} {lang.GetMessage("NoPermission", this, player.UserIDString)}";
                    SendReply(player, message);
                }
                if (config.BroadcastSettings.useTip) {
                    player?.ShowToast(GameTip.Styles.Red_Normal, string.Format(lang.GetMessage("NoPermission", this, player.UserIDString)));
                }
                return;
            }
            if (args.Length < 2) {
                if (config.BroadcastSettings.useChat) {
                    var message = $"{config.BroadcastSettings.chatPrefix} {lang.GetMessage("AdminCommandUsage", this, player.UserIDString)}";
                    SendReply(player, message);
                }
                if (config.BroadcastSettings.useTip) {
                    player?.ShowToast(GameTip.Styles.Blue_Normal, string.Format(lang.GetMessage("AdminCommandUsage", this, player.UserIDString)));
                }
                return;
            }
            string dropType = args[0].ToLower();
            string targetPlayerName = args[1];
            BasePlayer targetPlayer = BasePlayer.Find(targetPlayerName);
            if (targetPlayer == null) {
                if (config.BroadcastSettings.useChat) {
                    var message = $"{config.BroadcastSettings.chatPrefix} {lang.GetMessage("PlayerNotFound", this, player.UserIDString)}";
                    SendReply(player, message);
                }
                if (config.BroadcastSettings.useTip) {
                    player?.ShowToast(GameTip.Styles.Red_Normal, string.Format(lang.GetMessage("PlayerNotFound", this, player.UserIDString)));
                }
                return;
            }
            PlayDropEffect(targetPlayer);
            if (!DropItemsByType(targetPlayer, dropType)) {
                if (config.BroadcastSettings.useChat) {
                    SendReply(player, $"{config.BroadcastSettings.chatPrefix} Invalid drop type. Valid types: all, belt, wear, main.");
                }
                return;
            }
            if (config.BroadcastSettings.useChat) {
                var message = $"{config.BroadcastSettings.chatPrefix} {string.Format(lang.GetMessage("AdminDroppedItemsReply", this, player.UserIDString),targetPlayer.displayName)}";
                SendReply(player, message);
                var message1 = $"{config.BroadcastSettings.chatPrefix} {lang.GetMessage("AdminDroppedItems", this, targetPlayer.UserIDString)}";
                SendReply(targetPlayer, message1);
            }
            if (config.BroadcastSettings.useTip) {
                player?.ShowToast(GameTip.Styles.Blue_Normal, string.Format(lang.GetMessage("AdminDroppedItemsReply", this, player.UserIDString), targetPlayer.displayName));
                targetPlayer?.ShowToast(GameTip.Styles.Blue_Normal, string.Format(lang.GetMessage("AdminDroppedItems", this, player.UserIDString)));
            }
        }
        void DropInventoryAdminConsoleCommand(ConsoleSystem.Arg arg) {
            if (arg?.Args == null || arg.Args.Length < 2) {
                SendReply(arg, $"Usage: {config.CommandSettings.consoleCommand} (all|belt|wear|main) (playername or steamid)");
                return;
            }
            string dropType = arg.GetString(0).ToLowerInvariant();
            string targetPlayerName = arg.GetString(1);
            BasePlayer targetPlayer = BasePlayer.Find(targetPlayerName);
            if (targetPlayer == null) {
                SendReply(arg, "Player not found or multiple players found matching the name or ID provided.");
                return;
            }
            if (!DropItemsByType(targetPlayer, dropType)) {
                SendReply(arg, "Invalid drop type. Valid types: all, belt, wear, main.");
                return;
            }
            SendReply(arg, $"You dropped {dropType} items from Player: {targetPlayer.displayName}'s inventory.");
            if (config.BroadcastSettings.useChat) {
                var message = $"{config.BroadcastSettings.chatPrefix} {lang.GetMessage("AdminDroppedItems", this, targetPlayer.UserIDString)}";
                SendReply(targetPlayer, message);
            }
            if (config.BroadcastSettings.useTip) {
                targetPlayer?.ShowToast(GameTip.Styles.Blue_Normal, string.Format(lang.GetMessage("AdminDroppedItems", this, targetPlayer.UserIDString)));
            }
        }
#endregion
#region Helpers
        string GetDropMessage(BasePlayer player) {
            bool mainContainerEnabled = config.DropSettings.dropMain;
            bool beltContainerEnabled = config.DropSettings.dropBelt;
            bool wearContainerEnabled = config.DropSettings.dropWear;
            if (!mainContainerEnabled && !beltContainerEnabled && !wearContainerEnabled) return lang.GetMessage("NoContainers", this, player.UserIDString);
            else if (mainContainerEnabled && beltContainerEnabled && wearContainerEnabled) return lang.GetMessage("DropAll", this, player.UserIDString);
            else if (mainContainerEnabled && beltContainerEnabled) return lang.GetMessage("DropMainBelt", this, player.UserIDString);
            else if (mainContainerEnabled && wearContainerEnabled) return lang.GetMessage("DropMainWear", this, player.UserIDString);
            else if (beltContainerEnabled && wearContainerEnabled) return lang.GetMessage("DropBeltWear", this, player.UserIDString);
            else if (mainContainerEnabled) return lang.GetMessage("DropMain", this, player.UserIDString);
            else if (beltContainerEnabled) return lang.GetMessage("DropBelt", this, player.UserIDString);
            else if (wearContainerEnabled) return lang.GetMessage("DropWear", this, player.UserIDString);
            return "Unknown drop combination.";
        }
        bool DropItemsByType(BasePlayer targetPlayer, string dropType) {
            switch (dropType) {
                case "all" : DropItemsFromContainer(targetPlayer.inventory?.containerMain, targetPlayer, true);
                DropItemsFromContainer(targetPlayer.inventory?.containerBelt, targetPlayer, true);
                DropItemsFromContainer(targetPlayer.inventory?.containerWear, targetPlayer, true);
                return true;
                case "belt" : DropItemsFromContainer(targetPlayer.inventory?.containerBelt, targetPlayer, true);
                return true;
                case "wear" : DropItemsFromContainer(targetPlayer.inventory?.containerWear, targetPlayer, true);
                return true;
                case "main" : DropItemsFromContainer(targetPlayer.inventory?.containerMain, targetPlayer, true);
                return true;
                default : return false;
            }
        }
        bool CanUseCommand(BasePlayer player) {
            if (player.IsRestrained) {
                player?.ShowToast(GameTip.Styles.Red_Normal, lang.GetMessage("Restrained", this, player.UserIDString));
                return false;
            }
            if (permission.UserHasPermission(player.UserIDString, permission_bypass)) return true;
            ulong userId = player.userID;
            float currentTime = Time.realtimeSinceStartup;
            float lastUsageTime;
            if (cooldowns.TryGetValue(userId, out lastUsageTime)) {
                float timeRemaining = lastUsageTime + config.CommandSettings.commandCooldown - currentTime;
                int roundedTimeRemaining = Mathf.CeilToInt(timeRemaining);
                if (timeRemaining > 0f) {
                    if (config.BroadcastSettings.useChat) {
                        var message = $"{config.BroadcastSettings.chatPrefix} {string.Format(lang.GetMessage("Cooldown", this, player.UserIDString), roundedTimeRemaining)}";
                        SendReply(player, message);
                    }
                    if (config.BroadcastSettings.useTip) {
                        player?.ShowToast(GameTip.Styles.Blue_Normal, string.Format(lang.GetMessage("Cooldown", this, player.UserIDString), roundedTimeRemaining));
                    }
                    return false;
                }
            }
            cooldowns[userId] = currentTime;
            return true;
        }
        Vector3 GetRandomVelocity() {
            return new Vector3(UnityEngine.Random.Range(-config.DropSettings.dropVelocity, config.DropSettings.dropVelocity), config.DropSettings.dropVelocity, UnityEngine.Random.Range(-config.DropSettings.dropVelocity, config.DropSettings.dropVelocity));
        }
        void PlayDropEffect(BasePlayer player) {
            if (!string.IsNullOrEmpty(config.DropSettings.soundEffect)) {
                Effect.server.Run(config.DropSettings.soundEffect, player.transform.position);
            }
        }
        void DropPlayerItems(BasePlayer player) {
            DropItemsFromContainer(player.inventory?.containerMain, player, config.DropSettings.dropMain);
            DropItemsFromContainer(player.inventory?.containerBelt, player, config.DropSettings.dropBelt);
            DropItemsFromContainer(player.inventory?.containerWear, player, config.DropSettings.dropWear);
        }
        void DropItemsFromContainer(ItemContainer container, BasePlayer player, bool shouldDrop) {
            if (container == null || !shouldDrop) return;
            List<Item> itemsToDrop = new List<Item>(container.itemList);
            foreach (var item in itemsToDrop) {
                var randomVelocity = GetRandomVelocity();
                item.Drop(player.GetDropPosition(), randomVelocity);
            }
        }
#endregion
    }
}

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