using System; using System.Collections.Generic; using Oxide.Core; using Oxide.Game.Rust.Cui; using UnityEngine; namespace Oxide.Plugins { [Info("ZoneRules", "D420", "1.1.1")] [Description("Displays a UI with rules when entering or exiting specific zones.")] public class ZoneRules : RustPlugin { private Dictionary playerTimers = new Dictionary(); private Dictionary zoneRules; private float displayDuration; #region Config private class PluginConfig { public Dictionary ZoneMessages { get; set; } public float DisplayDuration { get; set; } = 10.0f; // Default duration } protected override void LoadDefaultConfig() { var config = new PluginConfig { ZoneMessages = new Dictionary { { "zone1", "Welcome to ServerName Town!\nhere you can add your own text and \nrules \n1.Here \n2.Here \n3.Here" }, { "zone2", "Zone 2 has strict rules. Read them carefully!" } }, DisplayDuration = 10.0f // Default display duration }; Config.WriteObject(config, true); } protected override void LoadConfig() { base.LoadConfig(); var config = Config.ReadObject(); zoneRules = config.ZoneMessages ?? new Dictionary(); displayDuration = config.DisplayDuration; // Load the display duration from config } #endregion #region UI private void ShowRulesUI(BasePlayer player, string message) { CuiElementContainer container = new CuiElementContainer(); string panelName = CuiHelper.GetGuid(); container.Add(new CuiElement { Name = panelName, Parent = "Overlay", Components = { new CuiImageComponent { Color = "0.1 0.1 0.1 0.8" }, // Dark semi-transparent panel new CuiRectTransformComponent { AnchorMin = "0.02 0.5", AnchorMax = "0.3 0.9" } } }); container.Add(new CuiElement { Parent = panelName, Components = { new CuiTextComponent { Text = message, FontSize = 20, Align = TextAnchor.MiddleCenter, Color = "1 1 1 1" // White text }, new CuiRectTransformComponent { AnchorMin = "0.05 0.05", AnchorMax = "0.95 0.95" } } }); CuiHelper.AddUi(player, container); if (playerTimers.ContainsKey(player)) { playerTimers[player].Destroy(); } // Use the display duration from the config playerTimers[player] = timer.Once(displayDuration, () => CuiHelper.DestroyUi(player, panelName)); } #endregion #region Hooks void OnEnterZone(string ZoneID, BasePlayer player) { if (zoneRules != null && zoneRules.ContainsKey(ZoneID)) { ShowRulesUI(player, zoneRules[ZoneID]); } } void OnExitZone(string ZoneID, BasePlayer player) { if (zoneRules != null && zoneRules.ContainsKey(ZoneID)) { if (playerTimers.ContainsKey(player)) { playerTimers[player].Destroy(); playerTimers.Remove(player); } } } void OnEntityEnterZone(string ZoneID, BaseEntity entity) { // Optional: Handle entities entering the zone, not just players } #endregion #region Initialization private void Init() { LoadConfig(); // Load configuration when the plugin initializes } #endregion } }