using System; using System.Collections.Generic; using Oxide.Core; using Oxide.Game.Rust.Cui; using UnityEngine; namespace Oxide.Plugins { [Info("ZoneUI", "D420", "1.0.1")] [Description("Displays a UI message when entering a specific zone and removes it on exit.")] public class ZoneUI : RustPlugin { #region Configuration private string zoneID = "zone1"; // Example zone identifier private string message = "Welcome to the zone!"; private string messageColor = "1.0 1.0 1.0 1.0"; // White text private string backgroundColor = "0.1 0.1 0.1 0.8"; // Dark translucent background private Vector2 uiPosition = new Vector2(0.5f, 0.95f); // Top middle private Vector2 uiSize = new Vector2(0.3f, 0.05f); // Width and height #endregion #region Hooks // Called when the plugin is loaded private void Init() { LoadConfig(); } // Called when a player enters a zone private void OnEnterZone(string zoneID, BasePlayer player) { if (zoneID == this.zoneID) { ShowUI(player); } } // Called when a player leaves a zone private void OnExitZone(string zoneID, BasePlayer player) { if (zoneID == this.zoneID) { DestroyUI(player); } } // Called when an entity enters a zone private void OnEntityEnterZone(string zoneID, BaseEntity entity) { // Optional logic for entities entering the zone (e.g., NPCs, vehicles) if (zoneID == this.zoneID) { Puts($"Entity {entity.ShortPrefabName} entered the zone."); } } // Compatibility: Called when a player enters the zone private void OnPlayerEnterZone(string zoneID, BasePlayer player) { OnEnterZone(zoneID, player); } // Compatibility: Called when a player exits the zone private void OnPlayerExitZone(string zoneID, BasePlayer player) { OnExitZone(zoneID, player); } #endregion #region UI Methods // Create and show the UI private void ShowUI(BasePlayer player) { CuiElementContainer container = new CuiElementContainer(); // Background panel CuiElement panel = new CuiElement { Name = "ZoneUI", Parent = "Overlay", Components = { new CuiImageComponent { Color = backgroundColor }, new CuiRectTransformComponent { AnchorMin = $"{uiPosition.x - uiSize.x / 2} {uiPosition.y - uiSize.y / 2}", AnchorMax = $"{uiPosition.x + uiSize.x / 2} {uiPosition.y + uiSize.y / 2}" } } }; container.Add(panel); // Text element CuiElement text = new CuiElement { Parent = "ZoneUI", Components = { new CuiTextComponent { Text = message, FontSize = 20, Align = TextAnchor.MiddleCenter, Color = messageColor }, new CuiRectTransformComponent { AnchorMin = "0 0", AnchorMax = "1 1" } } }; container.Add(text); CuiHelper.AddUi(player, container); } // Destroy the UI private void DestroyUI(BasePlayer player) { CuiHelper.DestroyUi(player, "ZoneUI"); } #endregion #region Configuration Loading and Saving protected override void LoadConfig() { base.LoadConfig(); message = GetConfig("Message", message); zoneID = GetConfig("ZoneID", zoneID); } protected override void LoadDefaultConfig() { Config["Message"] = message; Config["ZoneID"] = zoneID; } private T GetConfig(string key, T defaultValue) { if (Config[key] == null) return defaultValue; return (T)Convert.ChangeType(Config[key], typeof(T)); } #endregion } }