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

FREE OneHit : 1.0.0 1.0.0

Нет прав для скачивания
C#:
using Oxide.Core.Plugins;
using Oxide.Core.Configuration;
using Oxide.Core;
using Oxide.Core.Libraries.Covalence;
using System.Collections.Generic;
using UnityEngine;

namespace Oxide.Plugins
{
    [Info("OneHit", "M&B-Studios", "1.0.0")]
    public class OneHit : RustPlugin
    {
        private PluginConfig config;
        private const string permissionName = "onehit.use";
        private bool oneHitEnabled = true;

        private class PluginConfig
        {
            public Dictionary<string, bool> OneHitEntities { get; set; }
            public bool UsePermission { get; set; }
            public bool EnableCommand { get; set; }
            public string CommandName { get; set; }
            public bool AutoLootBarrels { get; set; }
            public bool AutoLootRoadSigns { get; set; }
            public float OneHitRadius { get; set; }
            public float AutoLootRadius { get; set; }

            public static PluginConfig DefaultConfig()
            {
                return new PluginConfig
                {
                    OneHitEntities = new Dictionary<string, bool>
                    {
//Animals
                        ["stag"] = false,
                        ["boar"] = false,
                        ["bear"] = false,
                        ["polarbear"] = false,
                        ["wolf"] = false,
                        ["testridablehorse"] = false,
                        ["chicken"] = false,
//LootBarrels
                        ["loot-barrel-1"] = true,
                        ["loot_barrel_1"] = true,
                        ["loot-barrel-2"] = true,
                        ["loot_barrel_2"] = true,
                        ["oil_barrel"] = true,
//NPC
                        ["scientistnpc_patrol"] = false,
                        ["scientistnpc_junkpile_pistol"] = false,
                        ["scientistnpc_peacekeeper"] = false,
                        ["scientistnpc_excavator"] = false,
                        ["scientistnpc_full_any"] = false,
                        ["testridablehorse"] = false,
                        ["scientistnpc_full_lr300"] = false,
                        ["scientistnpc_oilrig"] = false,
                        ["scientistnpc_heavy"] = false,
                        ["scientistnpc_full_shotgun"] = false,
                        ["scarecrow"] = false,
//Roadsigns
                        ["roadsign1"] = true,
                        ["roadsign1static"] = true,
                        ["roadsign2"] = true,
                        ["roadsign2static"] = true,
                        ["roadsign3"] = true,
                        ["roadsign3static"] = true,
                        ["roadsign4"] = true,
                        ["roadsign4static"] = true,
                        ["roadsign5"] = true,
                        ["roadsign5static"] = true,
                        ["roadsign6"] = true,
                        ["roadsign6static"] = true,
                        ["roadsign7"] = true,
                        ["roadsign7static"] = true,
                        ["roadsign8"] = true,
                        ["roadsign8static"] = true,
                        ["roadsign9"] = true,
                        ["roadsign9static"] = true
                    },
                    UsePermission = true,
                    EnableCommand = true,
                    CommandName = "onehit",
                    AutoLootBarrels = true,
                    AutoLootRoadSigns = true,
                    OneHitRadius = 5.0f,
                    AutoLootRadius = 5.0f
                };
            }
        }

        protected override void LoadDefaultConfig() => config = PluginConfig.DefaultConfig();

        private void Init()
        {
            permission.RegisterPermission(permissionName, this);
            config = Config.ReadObject<PluginConfig>();
            SaveConfig();

            if (config.EnableCommand)
            {
                cmd.AddChatCommand(config.CommandName, this, nameof(ToggleOneHitCommand));
                Puts($"OneHit Command '/{config.CommandName}' has been registered.");
            }
            else
            {
                Puts("OneHit Command is disabled in the configuration.");
            }
        }

        protected override void SaveConfig() => Config.WriteObject(config);

        private void ToggleOneHitCommand(BasePlayer player, string command, string[] args)
        {
            Puts($"ToggleOneHitCommand called by {player.IPlayer.Name}");

            if (!config.EnableCommand)
            {
                Puts("OneHit Command is disabled in config.");
                player.IPlayer.Reply("OneHit Command is disabled in config.");
                return;
            }

            if (config.UsePermission && !player.IPlayer.HasPermission(permissionName))
            {
                Puts($"Player {player.IPlayer.Name} does not have permission.");
                player.IPlayer.Reply("You do not have permission to use this command.");
                return;
            }

            oneHitEnabled = !oneHitEnabled;
            string statusMessage = oneHitEnabled ? "<color=green>enabled</color>" : "<color=red>disabled</color>";
            Puts($"OneHit is now {statusMessage}");
            player.IPlayer.Reply($"OneHit is now {statusMessage}.");
        }

        private void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo info)
        {
            if (entity == null || info == null || !oneHitEnabled) return;

            var attacker = info.InitiatorPlayer;
            if (attacker == null || (config.UsePermission && !permission.UserHasPermission(attacker.UserIDString, permissionName))) return;

            string entityName = entity.ShortPrefabName;
            float distance = Vector3.Distance(attacker.transform.position, entity.transform.position);

            if (config.OneHitEntities.TryGetValue(entityName, out bool isOneHit) && isOneHit && distance <= config.OneHitRadius)
            {
                if ((config.AutoLootBarrels && entity is LootContainer && entity.ShortPrefabName.Contains("barrel")) ||
                    (config.AutoLootRoadSigns && entityName.Contains("roadsign") && distance <= config.AutoLootRadius))
                {
                    AutoLootEntity(entity, attacker);
                }
                entity.Die(info);
            }
        }

        private void AutoLootEntity(BaseCombatEntity entity, BasePlayer player)
        {
            if (entity is LootContainer barrel)
            {
                ItemContainer container = barrel.inventory;
                List<Item> items = new List<Item>(container.itemList);
                foreach (Item item in items)
                {
                    player.GiveItem(item);
                }
            }
            else if (entity is Signage roadSign)
            {
                // Implementieren Sie hier die Logik für AutoLoot bei Straßenschildern, falls erforderlich
            }
        }
    }
}

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