C#:
using System.Collections.Generic;
using Newtonsoft.Json;
using Oxide.Game.Rust.Cui;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("Bottom", "MikeHawke", "1.0.1")]
[Description("Add a simple line of text under your hotbar that changes")]
class Bottom : RustPlugin
{
public static string BottomJson;
private static ConfigData configData;
class ConfigData
{
[JsonProperty(PropertyName = "Bottom Text List", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public List<string> messageList = new List<string>
{
"Welcome to our server",
"Join our discord",
"Do you like the music of showaddywaddy?"
};
[JsonProperty(PropertyName = "Change timer in seconds")]
public float timer = 60f;
}
private bool LoadConfigVariables()
{
try
{ configData = Config.ReadObject<ConfigData>(); }
catch
{ return false; }
SaveConfig(configData);
return true;
}
void Init()
{
if (!LoadConfigVariables())
{
Puts("Config file issue detected. Please delete file, or check syntax and fix.");
return;
}
}
protected override void LoadDefaultConfig()
{
Puts("Creating new config file.");
configData = new ConfigData();
SaveConfig(configData);
}
void SaveConfig(ConfigData config)
{ Config.WriteObject(config, true); }
private void OnServerInitialized()
{
BottomJson = UIJson();
ServerMgr.Instance.InvokeRepeating(UpdateUITask, 1f, configData.timer);
}
private void Unload()
{
ServerMgr.Instance.CancelInvoke(UpdateUITask);
foreach(BasePlayer player in BasePlayer.activePlayerList)
{ DestroyUI(player); }
}
void UpdateUITask()
{
string json = GetRandomJson();
if (BasePlayer.activePlayerList.Count == 0) { return; }
foreach (var player in BasePlayer.activePlayerList)
{
if (player == null || !player.userID.IsSteamId()) continue;
DestroyUI(player);
CuiHelper.AddUi(player, json);
}
}
private static string GetRandomJson()
{ return BottomJson.Replace("{Text}", configData.messageList.GetRandom());}
public static void DestroyUI(BasePlayer player)
{ CuiHelper.DestroyUi(player, "BottomUI"); }
private static string UIJson()
{
return new CuiElementContainer
{
{ new CuiPanel { Image = {Color = "0 0 0 0"}, RectTransform = { AnchorMin = "0.5 0", AnchorMax = "0.5 0", OffsetMin = "-199 0", OffsetMax = "182 15" } }, "Overlay", "BottomUI" },
{ new CuiLabel { Text = { Text = "{Text}", FontSize = 10, Align = TextAnchor.MiddleCenter, Color = "1 1 1 1"}, RectTransform = {AnchorMin = "0.05 0.05", AnchorMax = "0.95 0.95"}}, "BottomUI"}}.ToJson();
}
}
}