Advertisement
ElDubya

Untitled

Jul 2nd, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.79 KB | None | 0 0
  1. using System;
  2. using System.Globalization;
  3. using Oxide.Core.Plugins;
  4. using Oxide.Game.Rust.Cui;
  5. using System.Collections.Generic;
  6. using Newtonsoft.Json;
  7. using UnityEngine;
  8. using System.Linq;
  9.  
  10. namespace Oxide.Plugins
  11. {
  12.     [Info("MiddleText", "ElDubya_OZ", "0.0.1")]
  13.     class MiddleText : RustPlugin
  14.     {
  15.         #region Color
  16.        
  17.         public string colors = "#5982a7";
  18.        
  19.         #endregion
  20.        
  21.         #region Hooks
  22.        
  23.         private void OnServerInitialized()
  24.         {
  25.             BasePlayer.activePlayerList.ForEach(OnPlayerInit);
  26.         }
  27.        
  28.         void Unload()
  29.         {
  30.             foreach (BasePlayer player in BasePlayer.activePlayerList)
  31.             {
  32.                 CuiHelper.DestroyUi(player, "Layer");  
  33.             }  
  34.         }
  35.        
  36.         private void OnPlayerInit(BasePlayer player)
  37.         {
  38.             if (player.IsReceivingSnapshot)
  39.             {
  40.                 NextTick(() => OnPlayerInit(player));
  41.                 return;
  42.             }
  43.            
  44.             foreach (var players in BasePlayer.activePlayerList)
  45.             {
  46.                 timer.Once(1, () =>
  47.                 {
  48.                     DrawInterface(players);
  49.                 });
  50.             }
  51.         }
  52.        
  53.         private void OnPlayerDisconnected(BasePlayer player, string reason)
  54.         {
  55.             foreach (var players in BasePlayer.activePlayerList)
  56.             {
  57.                 timer.Once(1, () =>
  58.                 {
  59.                     DrawInterface(players);
  60.                 });
  61.             }
  62.         }
  63.        
  64.         #endregion
  65.        
  66.         #region UI
  67.        
  68.         private void DrawInterface(BasePlayer player)
  69.         {
  70.             var SleepersCount = BasePlayer.sleepingPlayerList.Count.ToString();
  71.             var JoiningCount = ServerMgr.Instance.connectionQueue.Joining.ToString();
  72.  
  73.             string Layer = "Layer";
  74.             CuiHelper.DestroyUi(player, Layer);
  75.             var container = new CuiElementContainer();
  76.             container.Add(new CuiPanel
  77.             {
  78.                 Image = { Color = HexToRustFormat("#FFFFFF00") },
  79.                 RectTransform = { AnchorMin = "0.34375 7.21775E-09", AnchorMax = "0.640625 0.02499998" },
  80.                 CursorEnabled = false,
  81.             }, "Hud", Layer);
  82.            
  83.             container.Add(new CuiElement
  84.             {
  85.                 Parent = Layer,
  86.                 Components =
  87.                 {
  88.                     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"},
  89.                     new CuiOutlineComponent { Color = "0 0 0 1", Distance = "0.5 0.5" },
  90.                     new CuiRectTransformComponent { AnchorMin = "0 0", AnchorMax = "1 1" }
  91.                 }
  92.             });
  93.  
  94.             CuiHelper.AddUi(player, container);
  95.         }
  96.        
  97.         #endregion
  98.        
  99.         #region Helpers
  100.        
  101.         private static string HexToRustFormat(string hex)
  102.         {
  103.             if (string.IsNullOrEmpty(hex))
  104.             {
  105.                 hex = "#FFFFFFFF";
  106.             }
  107.  
  108.             var str = hex.Trim('#');
  109.  
  110.             if (str.Length == 6)
  111.                 str += "FF";
  112.  
  113.             if (str.Length != 8)
  114.             {
  115.                 throw new Exception(hex);
  116.                 throw new InvalidOperationException("Cannot convert a wrong format.");
  117.             }
  118.  
  119.             var r = byte.Parse(str.Substring(0, 2), NumberStyles.HexNumber);
  120.             var g = byte.Parse(str.Substring(2, 2), NumberStyles.HexNumber);
  121.             var b = byte.Parse(str.Substring(4, 2), NumberStyles.HexNumber);
  122.             var a = byte.Parse(str.Substring(6, 2), NumberStyles.HexNumber);
  123.  
  124.             Color color = new Color32(r, g, b, a);
  125.  
  126.             return string.Format("{0:F2} {1:F2} {2:F2} {3:F2}", color.r, color.g, color.b, color.a);
  127.         }
  128.        
  129.         #endregion
  130.     }
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement