using Oxide.Core; using Oxide.Core.Plugins; using System.Collections.Generic; using UnityEngine; namespace Oxide.Plugins { [Info("EventNotifier", "Kalvi", "1.3.3")] [Description("Notifies players of various events.")] public class EventNotifier : RustPlugin { private const string configFileName = "EventNotifier"; private ConfigData configData; private class ConfigData { public bool NotifyCargoPlane { get; set; } public bool NotifyTank { get; set; } public bool NotifyCargoShip { get; set; } public bool NotifyChinook { get; set; } public bool NotifyAttackHelicopter { get; set; } public bool ShowDirection { get; set; } } private void Init() { LoadConfigData(); } private void LoadConfigData() { configData = Config.ReadObject(); if (configData == null) { configData = new ConfigData { NotifyCargoPlane = true, NotifyTank = true, NotifyCargoShip = true, NotifyChinook = true, NotifyAttackHelicopter = true, ShowDirection = true }; SaveConfigData(); } } protected override void LoadDefaultConfig() { Config.WriteObject(GetDefaultConfig(), true); } private ConfigData GetDefaultConfig() { return new ConfigData { NotifyCargoPlane = true, NotifyTank = true, NotifyCargoShip = true, NotifyChinook = true, NotifyAttackHelicopter = true, ShowDirection = true }; } private void SaveConfigData() { Config.WriteObject(configData, true); } private void OnEntitySpawned(BaseEntity entity) { if (entity == null) return; var entityName = entity.ShortPrefabName; string message = null; string direction = configData.ShowDirection ? $" towards {GetDirection(entity.transform.position)}" : ""; switch (entityName) { case "cargo_plane": if (configData.NotifyCargoPlane) message = Lang("CargoPlaneNotification", direction); break; case "cargoshiptest": if (configData.NotifyCargoShip) message = Lang("CargoShipNotification", direction); break; case "ch47.entity": if (configData.NotifyChinook) message = Lang("ChinookNotification", direction); break; case "patrolhelicopter": if (configData.NotifyAttackHelicopter) message = Lang("AttackHelicopterNotification", direction); break; case "bradleyapc": if (configData.NotifyTank) message = Lang("TankNotification", ""); break; } if (message != null) { PrintToChat(message); } } private string GetDirection(Vector3 position) { float angle = Mathf.Atan2(position.z, position.x) * Mathf.Rad2Deg; if (angle < 0) angle += 360; if (angle >= 315 || angle < 45) return "East"; else if (angle >= 45 && angle < 135) return "North"; else if (angle >= 135 && angle < 225) return "West"; else return "South"; } #region Lang API protected override void LoadDefaultMessages() { lang.RegisterMessages(new Dictionary { ["CargoPlaneNotification"] = "Cargo Plane has spawned{0}!", ["TankNotification"] = "Tank has spawned!", ["CargoShipNotification"] = "Cargo Ship has spawned{0}!", ["ChinookNotification"] = "Chinook has spawned{0}!", ["AttackHelicopterNotification"] = "Attack Helicopter has spawned{0}!" }, this); } private string Lang(string key, params object[] args) { return string.Format(lang.GetMessage(key, this), args); } #endregion } }