C#:
using Oxide.Core;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using Newtonsoft.Json;
using UnityEngine;
using System.Collections.Generic;
namespace Oxide.Plugins
{
[Info("MBLogo", "Barry_Allenn", "1.1.0")]
[Description("Display server logo, time, and online count")]
public class MBLogo : RustPlugin
{
[PluginReference]
private Plugin ImageLibrary;
private ConfigData config;
private const string UI_MAIN = "MBLogoUI";
private const string UI_ONLINE = "MBLogoOnline";
private class ConfigData
{
[JsonProperty("Смужка назви 1")] public string text_1 = "<color=#0057b8><b>FREEDOM</b></color>";
[JsonProperty("Смужка назви 2")] public string text_2 = "<color=#ffd700><b>UA-RUST</b></color>";
}
protected override void LoadDefaultConfig() => config = new ConfigData();
protected override void LoadConfig()
{
base.LoadConfig();
config = Config.ReadObject<ConfigData>() ?? new ConfigData();
}
protected override void SaveConfig() => Config.WriteObject(config);
private void OnServerInitialized()
{
if (ImageLibrary == null)
{
PrintError("ImageLibrary is not connected.Install and load ImageLibrary.");
return;
}
foreach (var player in BasePlayer.activePlayerList)
{
CreateMBLogo(player);
}
timer.Every(30f, UpdateAllTimes);
}
private void OnPlayerConnected(BasePlayer player)
{
timer.Once(2f, () =>
{
CreateMBLogo(player);
UpdateAllPlayersOnlineUI(); // <-- добавь эту строку
});
}
private void OnPlayerDisconnected(BasePlayer player, string reason)
{
timer.Once(1f, UpdateAllPlayersOnlineUI);
}
private void CreateMBLogo(BasePlayer player)
{
CuiHelper.DestroyUi(player, UI_MAIN);
var container = new CuiElementContainer();
string root = container.Add(new CuiPanel
{
Image = { Color = "0 0 0 0" },
RectTransform = { AnchorMin = "1 1", AnchorMax = "1 1", OffsetMin = "-180 -80", OffsetMax = "-1 0" },
CursorEnabled = false
}, "Hud", UI_MAIN);
container.Add(new CuiLabel
{
RectTransform = { AnchorMin = "0.35 0.6", AnchorMax = "0.97 0.97" },
Text = { Text = config.text_1, Color = "1 1 1 0.5", Align = TextAnchor.MiddleLeft, FontSize = 21, Font = "permanentmarker.ttf" }
}, root);
container.Add(new CuiLabel
{
RectTransform = { AnchorMin = "0.35 0.4", AnchorMax = "0.97 0.78" },
Text = { Text = config.text_2, Color = "1 1 1 0.5", Align = TextAnchor.MiddleCenter, FontSize = 21, Font = "permanentmarker.ttf" }
}, root);
container.Add(new CuiLabel
{
Text = {
Text = $"{GetServerTime()}",
FontSize = 22,
Align = TextAnchor.MiddleCenter,
Color = "1 1 1 1"
},
RectTransform = { AnchorMin = "0.005 0.5", AnchorMax = "0.315 0.87" }
}, root, "MBLogoTime");
container.Add(new CuiLabel
{
Text = {
Text = $"Online: {BasePlayer.activePlayerList.Count}",
FontSize = 12,
Align = TextAnchor.MiddleCenter,
Color = "1 1 1 1"
},
RectTransform = { AnchorMin = "0.59 0.15", AnchorMax = "0.97 0.35" }
}, root, UI_ONLINE);
container.Add(new CuiLabel
{
Text = {
Text = $"Sleep: {BasePlayer.sleepingPlayerList.Count}",
FontSize = 12,
Align = TextAnchor.MiddleCenter,
Color = "1 1 1 1"
},
RectTransform = { AnchorMin = "0.245 0.15", AnchorMax = "0.6 0.35" }
}, root, "MBLogoSleepers");
CuiHelper.AddUi(player, container);
}
private void UpdateAllTimes()
{
foreach (var player in BasePlayer.activePlayerList)
{
UpdateTimeUI(player);
}
}
private void UpdateTimeUI(BasePlayer player)
{
CuiHelper.DestroyUi(player, "MBLogoTime");
var container = new CuiElementContainer();
container.Add(new CuiLabel
{
Text = {
Text = $"{GetServerTime()}",
FontSize = 22,
Align = TextAnchor.MiddleCenter,
Color = "1 1 1 1"
},
RectTransform = { AnchorMin = "0.005 0.5", AnchorMax = "0.315 0.87" }
}, UI_MAIN, "MBLogoTime");
CuiHelper.AddUi(player, container);
}
private void UpdateAllPlayersOnlineUI()
{
foreach (var player in BasePlayer.activePlayerList)
{
UpdateOnlineUI(player);
UpdateSleepersUI(player);
}
}
private void UpdateOnlineUI(BasePlayer player)
{
CuiHelper.DestroyUi(player, UI_ONLINE);
var container = new CuiElementContainer();
container.Add(new CuiLabel
{
Text = {
Text = $"Online: {BasePlayer.activePlayerList.Count}",
FontSize = 11,
Align = TextAnchor.MiddleCenter,
Color = "1 1 1 1"
},
RectTransform = { AnchorMin = "0.59 0.15", AnchorMax = "0.97 0.35" }
}, UI_MAIN, UI_ONLINE);
CuiHelper.AddUi(player, container);
}
private void UpdateSleepersUI(BasePlayer player)
{
CuiHelper.DestroyUi(player, "MBLogoSleepers");
var container = new CuiElementContainer();
container.Add(new CuiLabel
{
Text = {
Text = $"Sleep: {BasePlayer.sleepingPlayerList.Count}",
FontSize = 11,
Align = TextAnchor.MiddleCenter,
Color = "1 1 1 1"
},
RectTransform = { AnchorMin = "0.245 0.15", AnchorMax = "0.6 0.35" }
}, UI_MAIN, "MBLogoSleepers");
CuiHelper.AddUi(player, container);
}
private string GetServerTime()
{
if (TOD_Sky.Instance == null)
return "⏰ Загрузка...";
float time = TOD_Sky.Instance.Cycle.Hour;
int hours = Mathf.FloorToInt(time);
int minutes = Mathf.FloorToInt((time - hours) * 60f);
return $"{hours:00}:{minutes:00}";
}
}
}