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

FREE InstantAnimalKill : 1.0.6 1.0.6

Нет прав для скачивания
C#:
using System.Collections.Generic;
using System.Text.RegularExpressions;
using UnityEngine;

namespace Oxide.Plugins
{
    [Info("Instant Animal Kill", "CengizhanBucak", "1.0.6")]
    [Description("Kills animals instantly when attacked.")]
    public class InstantAnimalKill : RustPlugin
    {
        private const string permissionNameBear = "instantanimalkill.bear"; // Permission for bear
        private const string permissionNameWolf = "instantanimalkill.wolf"; // Permission for wolf
        private const string permissionNameHorse = "instantanimalkill.horse"; // Permission for horse
        private const string permissionNameChicken = "instantanimalkill.chicken"; // Permission for chicken
        private const string permissionNameAll = "instantanimalkill.all"; // Permission for all animals
        private bool enableMessages;
        private string killedAnimalMessage;

        protected override void LoadDefaultConfig()
        {
            Config["EnableMessages"] = true;
            Config["KilledAnimalMessage"] = "You killed %animal%!";
            SaveConfig();
        }

        private void Init()
        {
            LoadDefaultConfig();
            enableMessages = (bool)Config["EnableMessages"];
            killedAnimalMessage = (string)Config["KilledAnimalMessage"];

            permission.RegisterPermission(permissionNameBear, this);
            permission.RegisterPermission(permissionNameWolf, this);
            permission.RegisterPermission(permissionNameHorse, this);
            permission.RegisterPermission(permissionNameChicken, this);
            permission.RegisterPermission(permissionNameAll, this);
        }

        private void OnEntityTakeDamage(BaseCombatEntity entity, HitInfo hitInfo)
        {
            // Only apply to animals
            if (!(entity is BaseNpc) || !(hitInfo.Initiator is BasePlayer))
            {
                return;
            }

            // Check if player has permission to use or kill animals
            bool hasBearPermission = permission.UserHasPermission((hitInfo.Initiator as BasePlayer).UserIDString, permissionNameBear);
            bool hasWolfPermission = permission.UserHasPermission((hitInfo.Initiator as BasePlayer).UserIDString, permissionNameWolf);
            bool hasHorsePermission = permission.UserHasPermission((hitInfo.Initiator as BasePlayer).UserIDString, permissionNameHorse);
            bool hasChickenPermission = permission.UserHasPermission((hitInfo.Initiator as BasePlayer).UserIDString, permissionNameChicken);
            bool hasAllPermission = permission.UserHasPermission((hitInfo.Initiator as BasePlayer).UserIDString, permissionNameAll);

            // comment debug

            // Debug.Log($"Player has bear permission: {hasBearPermission}");
            // Debug.Log($"Entity short prefab name: {entity.ShortPrefabName}");

            // Check if the animal is a bear, and if so, check for permissions and kill it instantly
            if (entity.ShortPrefabName == "bear")
            {
                if (hasBearPermission)
                {
                    entity.Die();

                    // Send a message to the player if messages are enabled
                    if (enableMessages)
                    {
                        string message = killedAnimalMessage.Replace("%animal%", entity.ShortPrefabName);
                        (hitInfo.Initiator as BasePlayer).ChatMessage(message);
                    }

                    return;
                }
            }

            // Check if the animal is a wolf, and if so, check for permissions and kill it instantly
            if (entity.ShortPrefabName == "wolf")
            {
                if (hasWolfPermission)
                {
                    entity.Die();

                    // Send a message to the player if messages are enabled
                    if (enableMessages)
                    {
                        string message = killedAnimalMessage.Replace("%animal%", entity.ShortPrefabName);
                        (hitInfo.Initiator as BasePlayer).ChatMessage(message);
                    }

                    return;
                }
            }

            // Check if the animal is a horse, and if so, check for permissions and kill it instantly
            if (entity.ShortPrefabName == "horse")
            {
                if (hasHorsePermission)
                {
                    entity.Die();

                    // Send a message to the player if messages are enabled
                    if (enableMessages)
                    {
                        string message = killedAnimalMessage.Replace("%animal%", entity.ShortPrefabName);
                        (hitInfo.Initiator as BasePlayer).ChatMessage(message);
                    }

                    return;
                }
            }

            // Check if the animal is a chicken, and if so, check for permissions and kill it instantly
            if (entity.ShortPrefabName == "chicken")
            {
                if (hasChickenPermission)
                {
                    entity.Die();

                    // Send a message to the player if messages are enabled
                    if (enableMessages)
                    {
                        string message = killedAnimalMessage.Replace("%animal%", entity.ShortPrefabName);
                        (hitInfo.Initiator as BasePlayer).ChatMessage(message);
                    }

                    return;
                }
            }

            // Check if the animal is a chicken, and if so, check for permissions and kill it instantly
                if (hasAllPermission)
                {
                    entity.Die();

                    // Send a message to the player if messages are enabled
                    if (enableMessages)
                    {
                        string message = killedAnimalMessage.Replace("%animal%", entity.ShortPrefabName);
                        (hitInfo.Initiator as BasePlayer).ChatMessage(message);
                    }

                    return;
                }
        }

    }
}

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