C#:
using Newtonsoft.Json;
using Oxide.Game.Rust.Cui;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("FInfo", "https://topplugin.ru/", "1.0.2")]
[Description("Минималистичное меню!")]
public class FInfo : RustPlugin
{
#region Config / Конфиг
public static ConfigData FinfoConfig;
public class ConfigData
{
[JsonProperty(PropertyName = "Finfo config")]
public VoteS Fcfg = new VoteS();
public class VoteS
{
[JsonProperty(PropertyName =
"Частота обновления информации в секундах.")]
public float UpdTime;
[JsonProperty(PropertyName =
"Частота обновления сообщений в секундах.")]
public float MUpdTime;
[JsonProperty(PropertyName = "Сообщения.")]
public string[] Messages;
}
}
public ConfigData GetDefaultConfig()
{
return new ConfigData
{
Fcfg = new ConfigData.VoteS
{
UpdTime = 1,
MUpdTime = 5,
Messages = new string[]
{
"1",
"2",
"3",
"4"
}
}
};
}
protected override void LoadConfig()
{
base.LoadConfig();
try
{
FinfoConfig = Config.ReadObject<ConfigData>();
}
catch
{
LoadDefaultConfig();
}
SaveConfig();
}
protected override void LoadDefaultConfig()
{
PrintError("Config file is broken or never created, created new default config.");
FinfoConfig = GetDefaultConfig();
}
protected override void SaveConfig()
{
Config.WriteObject(FinfoConfig);
}
#endregion
#region Vars
public TOD_Sky Sky;
public Timer Timer;
public Timer Timer1;
public int OP;
public int Sleep;
public string time;
int UpdNum = 0;
int UpdNumk = 0;
#endregion
#region Update
void Unload()
{
foreach (var player in BasePlayer.activePlayerList)
{
CuiHelper.DestroyUi(player, "Finf");
}
Timer.Destroy();
Timer1.Destroy();
}
private void OnServerInitialized()
{
Sky = TOD_Sky.Instance;
Timer = timer.Every(FinfoConfig.Fcfg.UpdTime, () =>
{
time = Sky.Cycle.DateTime.ToString("hh:mm");
OP = BasePlayer.activePlayerList.Count;
Sleep = BasePlayer.sleepingPlayerList.Count;
foreach (var player in BasePlayer.activePlayerList)
{
DrawINF(player);
}
});
Timer1 = timer.Every(FinfoConfig.Fcfg.MUpdTime, () =>
{
int count = FinfoConfig.Fcfg.Messages.Length;
UpdNumk ++;
if (UpdNumk > (count - 1))
{
UpdNumk = 0;
}
UpdNum = UpdNumk;
});
}
#endregion
#region GUI
private void DrawINF(BasePlayer player)
{
CuiHelper.DestroyUi(player, "Finf");
var GuiFinf = new CuiElementContainer();
GuiFinf.Add(new CuiPanel
{
CursorEnabled = false,
Image =
{
Color = "0 0 0 0"
},
RectTransform =
{
AnchorMin = $"{0.3442709} {0.001851968}",
AnchorMax = $"{0.6411458} {0.0212963}"
}
},"Overlay","Finf");
GuiFinf.Add(new CuiElement
{
Name = "Time",
Parent = "Finf",
Components =
{
new CuiTextComponent
{
Text = $"Время : {time}",
Align = TextAnchor.MiddleLeft,
FontSize = 12,
Color = "1 1 1 1",
Font = "RobotoCondensed-Bold.ttf",
},
new CuiRectTransformComponent
{
AnchorMin = $"{-0.001754786} {0.04761934}",
AnchorMax = $"{0.1771927} {1}"
}
}
});
GuiFinf.Add(new CuiElement
{
Name = "OP",
Parent = "Finf",
Components =
{
new CuiTextComponent
{
Text = $"Онлайн : {OP}",
Align = TextAnchor.MiddleLeft,
FontSize = 12,
Color = "1 1 1 1",
Font = "RobotoCondensed-Bold.ttf",
},
new CuiRectTransformComponent
{
AnchorMin = $"{0.2070174} {0}",
AnchorMax = $"{0.3771935} {1}"
}
}
});
GuiFinf.Add(new CuiElement
{
Name = "Sleep",
Parent = "Finf",
Components =
{
new CuiTextComponent
{
Text = $"Спящие : {Sleep}",
Align = TextAnchor.MiddleLeft,
FontSize = 12,
Color = "1 1 1 1",
Font = "RobotoCondensed-Bold.ttf",
},
new CuiRectTransformComponent
{
AnchorMin = $"{0.39} {0}",
AnchorMax = $"{0.57} {1}"
}
}
});
GuiFinf.Add(new CuiElement()
{
Name = "SN",
Parent = "Finf",
Components =
{
new CuiTextComponent
{
Text = $"{FinfoConfig.Fcfg.Messages[UpdNum]}",
Align = TextAnchor.MiddleCenter,
FontSize = 12,
Color = "1 1 1 1",
Font = "RobotoCondensed-Bold.ttf",
},
new CuiRectTransformComponent
{
AnchorMin = $"{0.5} {0}",
AnchorMax = $"{1} {1}"
}
}
});
CuiHelper.AddUi(player, GuiFinf);
}
#endregion
}
}