Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Globalization;
- using Oxide.Core.Plugins;
- using Oxide.Game.Rust.Cui;
- using System.Collections.Generic;
- using Newtonsoft.Json;
- using UnityEngine;
- using System.Linq;
- namespace Oxide.Plugins
- {
- [Info("MiddleText", "ElDubya_OZ", "0.0.1")]
- class MiddleText : RustPlugin
- {
- #region Color
- public string colors = "#5982a7";
- #endregion
- #region Hooks
- private void OnServerInitialized()
- {
- BasePlayer.activePlayerList.ForEach(OnPlayerInit);
- }
- void Unload()
- {
- foreach (BasePlayer player in BasePlayer.activePlayerList)
- {
- CuiHelper.DestroyUi(player, "Layer");
- }
- }
- private void OnPlayerInit(BasePlayer player)
- {
- if (player.IsReceivingSnapshot)
- {
- NextTick(() => OnPlayerInit(player));
- return;
- }
- foreach (var players in BasePlayer.activePlayerList)
- {
- timer.Once(1, () =>
- {
- DrawInterface(players);
- });
- }
- }
- private void OnPlayerDisconnected(BasePlayer player, string reason)
- {
- foreach (var players in BasePlayer.activePlayerList)
- {
- timer.Once(1, () =>
- {
- DrawInterface(players);
- });
- }
- }
- #endregion
- #region UI
- private void DrawInterface(BasePlayer player)
- {
- var SleepersCount = BasePlayer.sleepingPlayerList.Count.ToString();
- var JoiningCount = ServerMgr.Instance.connectionQueue.Joining.ToString();
- string Layer = "Layer";
- CuiHelper.DestroyUi(player, Layer);
- var container = new CuiElementContainer();
- container.Add(new CuiPanel
- {
- Image = { Color = HexToRustFormat("#FFFFFF00") },
- RectTransform = { AnchorMin = "0.34375 7.21775E-09", AnchorMax = "0.640625 0.02499998" },
- CursorEnabled = false,
- }, "Hud", Layer);
- container.Add(new CuiElement
- {
- Parent = Layer,
- Components =
- {
- new CuiTextComponent { Text = $"<color=#3CB371>Salt City Rust</color> <color=orange>PVE</color> - <color=silver>https://saltcity.enjin.com/</color>", Align = TextAnchor.MiddleCenter, FontSize = 10, Font = "RobotoCondensed-regular.ttf"},
- new CuiOutlineComponent { Color = "0 0 0 1", Distance = "0.5 0.5" },
- new CuiRectTransformComponent { AnchorMin = "0 0", AnchorMax = "1 1" }
- }
- });
- CuiHelper.AddUi(player, container);
- }
- #endregion
- #region Helpers
- private static string HexToRustFormat(string hex)
- {
- if (string.IsNullOrEmpty(hex))
- {
- hex = "#FFFFFFFF";
- }
- var str = hex.Trim('#');
- if (str.Length == 6)
- str += "FF";
- if (str.Length != 8)
- {
- throw new Exception(hex);
- throw new InvalidOperationException("Cannot convert a wrong format.");
- }
- var r = byte.Parse(str.Substring(0, 2), NumberStyles.HexNumber);
- var g = byte.Parse(str.Substring(2, 2), NumberStyles.HexNumber);
- var b = byte.Parse(str.Substring(4, 2), NumberStyles.HexNumber);
- var a = byte.Parse(str.Substring(6, 2), NumberStyles.HexNumber);
- Color color = new Color32(r, g, b, a);
- return string.Format("{0:F2} {1:F2} {2:F2} {3:F2}", color.r, color.g, color.b, color.a);
- }
- #endregion
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement