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

FREE Inbound : 0.2.0 0.2.0

Нет прав для скачивания
C#:
// Все права принадлежат дискорд сообществу https://discord.gg/VgNHPpNrz6
using System;
using System.Collections.Generic;
using UnityEngine;

namespace Oxide.Plugins
{
    [Info("Inbound", "Wulf/lukespragg", "0.2.0", ResourceId = 1457)]
    [Description("Notifies all players when a helicopter or supply drop is inbound")]

    class Inbound : RustPlugin
    {
        // Do NOT edit this file, instead edit Inbound.json in oxide/config and Inbound.en.json in the oxide/lang directory,
        // or create a new language file for another language using the 'en' file as a default.#region Initialization

        void Init()
        {
            LoadDefaultConfig();

            lang.RegisterMessages(new Dictionary<string, string>
            {
                ["HelicopterInbound"] = "Helicopter inbound!",
                ["SupplyDropInbound"] = "Supply drop inbound!"
            }, this);

            #if DEBUG
            var planeEntity = GameManager.server.CreateEntity("assets/prefabs/npc/cargo plane/cargo_plane.prefab", new Vector3(), new Quaternion(1f, 0f, 0f, 0f));
            if (planeEntity != null)
            {
                var plane = planeEntity.GetComponent<CargoPlane>();
                plane.InitDropPosition(new Vector3());
                planeEntity.Spawn();
            }
            #endif
        }

        #endregion

        #region Configuration

        bool helicopterAlerts;
        bool supplyDropAlerts;
        bool supplyDropArrow;
        //string supplyDropArrowColor;
        int supplyDropArrowLength;
        int supplyDropArrowSize;
        int supplyDropArrowTime;

        protected override void LoadDefaultConfig()
        {
            Config["SupplyDropArrow"] = supplyDropArrow = GetConfig("SupplyDropArrow", true);
            //Config["SupplyDropArrowColor"] = supplyDropArrowColor = GetConfig("SupplyDropArrowColor", "white");
            Config["SupplyDropArrowLength"] = supplyDropArrowLength = GetConfig("SupplyDropArrowLength", 15);
            Config["SupplyDropArrowSize"] = supplyDropArrowSize = GetConfig("SupplyDropArrowSize", 4);
            Config["SupplyDropArrowTime"] = supplyDropArrowTime = GetConfig("SupplyDropArrowTime", 60);
            Config["HelicopterAlerts"] = helicopterAlerts = GetConfig("HelicopterAlerts", true);
            Config["SupplyDropAlerts"] = supplyDropAlerts = GetConfig("SupplyDropAlerts", true);
            SaveConfig();
        }

        #endregion

        void OnEntitySpawned(BaseEntity entity)
        {
            if (helicopterAlerts && entity.ShortPrefabName.Equals("patrolhelicopter")) PrintToChat(Lang("HelicopterInbound"));
            if (supplyDropAlerts && entity.ShortPrefabName.Equals("supply_drop"))
            {
                PrintToChat(Lang("SupplyDropInbound"));
                if (supplyDropArrow) LandingCheck(entity);
            }
        }

        void LandingCheck(BaseEntity entity)
        {
            var distance = Vector3.Distance(entity.transform.position, GetGroundPosition(entity.transform.position));
            if (distance >= 10f)
            {
                timer.Once(1f, () => LandingCheck(entity));
                return;
            }

            var pos = entity.transform.position;
            var startPos = new Vector3(pos.x, pos.y + 5 + supplyDropArrowLength, pos.z);
            var endPos = new Vector3(pos.x, pos.y + 5, pos.z);
            var args = new object[] {supplyDropArrowTime, Color.white, startPos, endPos, supplyDropArrowSize};
            ConsoleNetwork.BroadcastToAllClients("ddraw.arrow", args);
        }

        #region Helpers

        T GetConfig<T>(string name, T defaultValue) => Config[name] == null ? defaultValue : (T) Convert.ChangeType(Config[name], typeof(T));

        string Lang(string key, string id = null, params object[] args) => string.Format(lang.GetMessage(key, this, id), args);

        static Vector3 GetGroundPosition(Vector3 sourcePos)
        {
            RaycastHit hitInfo;
            var groundLayer = LayerMask.GetMask("Terrain", "World", "Construction");
            if (Physics.Raycast(sourcePos, Vector3.down, out hitInfo, groundLayer)) sourcePos.y = hitInfo.point.y;
            sourcePos.y = Mathf.Max(sourcePos.y, TerrainMeta.HeightMap.GetHeight(sourcePos));
            return sourcePos;
        }

        #endregion
    }
}

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