C#:
// Все права принадлежат дискорд сообществу https://discord.gg/VgNHPpNrz6
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using Newtonsoft.Json;
using Oxide.Core;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using UnityEngine;
using UnityEngine.UI;
namespace Oxide.Plugins {
[Info("Hud", "ahigao", "3.1.6")]
internal class Hud : RustPlugin {
#region Static
private const string PERM_STREAMER = "hud.streamer";
private Timer InfoMessageUpdate;
private int EnableEventsCount, EventsPosStartPosX;
[PluginReference]
private Plugin Economics, ServerRewards;
private enum States {
Full, Events, Hide, Close
}
#region Classes
private class Configuration {
[JsonIgnore]
public string JSON;
[JsonProperty("Auto reload [If you change the config and save the file the plugin will reload itself]")]
public bool AutoReload = false;
[JsonProperty("Main setup")]
public MainSetup MainSetup = new MainSetup {
IsOverall = false, Size = 80, Logo = "https://www.dropbox.com/scl/fi/9j4fv475el3gfbq9wvoox/logo.png?rlkey=rq710tuayr8syuk54fljluqqa&dl=1", EventsBGOpacity = 80, BGOpacity = 60, Position = new Postition {
Align = "TopLeft", LeftOffSet = 40, TopOffSet = 25,
}
, ServerName = "Your Server Name", ActivePlayersAppearance = new BaseAppearance {
Color = "#fff", Icon = "https://www.dropbox.com/scl/fi/weax6ug55o0u4f87bhchs/active.png?rlkey=lbpuhpqs7tutpgv1i4t3b1107&dl=1", IsEnable = true,
}
, SleepPlayersAppearance = new BaseAppearance {
Color = "#fff", Icon = "https://www.dropbox.com/scl/fi/3d76i9rg4i34zprgekr3j/sleep.png?rlkey=s57ehdeoc16h58ace6s5yuhcl&dl=1", IsEnable = true,
}
, QueuePlayersAppearance = new BaseAppearance {
Color = "#fff", Icon = "https://www.dropbox.com/scl/fi/aneas55vx6pnrwmg8bh1z/line.png?rlkey=kwmlqihaopckijm98ta0qn9p2&dl=1", IsEnable = true,
}
, Time = new TimeAppearance {
IsAutomaticDetection = true, IsAmPm = false, Color = "#fff", IsEnable = true,
}
, PlayerPosition = new PlayerPositionAppearance {
IsGrid = true, Color = "cyan", IsEnable = true,
}
, Economy = new EconomyAppearance() {
Currency = "$", Plugin = "ServerRewards", Color = "#10ff10", IsEnable = false,
}
, InfoMessages = new InfoMessage {
UpdateInterval = 60, Align = "BottomCenter", Width = 260, OffsetTB = 0, OffsetR = 0, OutlineColor = "#000", IsOverall = true, IsEnable = true, Messages = new List<string> {
"Welcome to Your Server Name", "Good luck"
}
}
, AdditionalMenu = new AdditionalMenu {
AutoCloseTime = 60, AutoCloseCommand = true, ButtonColor = "yellow", CommandsOpacity = 100, IsEnable = true, Commands = new List<CommandAppearance> {
new CommandAppearance {
Command = "chat.say Hello there", Icon = "https://www.dropbox.com/scl/fi/weax6ug55o0u4f87bhchs/active.png?rlkey=lbpuhpqs7tutpgv1i4t3b1107&dl=1", Image = "https://www.dropbox.com/scl/fi/ypbnnbs07i2t322x1pu4c/command.png?rlkey=a693i43bn70wiy2p0v0216uw7&dl=1", Text = "Say Something", OutlineColor = "#000", IsConsole = true,
}
, new CommandAppearance {
Command = "/shop", Icon = "", Image = "https://www.dropbox.com/scl/fi/ypbnnbs07i2t322x1pu4c/command.png?rlkey=a693i43bn70wiy2p0v0216uw7&dl=1", Text = "Say Something", OutlineColor = "#000", IsConsole = false,
}
,
}
,
}
}
;
[JsonProperty("Base Events", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public List<BaseEventsAppearance> BaseEvents = new List<BaseEventsAppearance> {
new BaseEventsAppearance {
Name = "Bradley", Color = "#fff", ActiveColor = "#10ff10", Icon = "https://www.dropbox.com/scl/fi/i7531lubr8jy62w6zugkt/bradley.png?rlkey=fpnpmqndjgt63hamyrd0jzyc2&dl=1", IsEnable = true,
}
, new BaseEventsAppearance {
Name = "PatrolHeli", Color = "#fff", ActiveColor = "#10ff10", Icon = "https://www.dropbox.com/scl/fi/140cku9l167y8i778br2i/heli.png?rlkey=25wxs16n0s9dk8uea7bn0p7sd&dl=1", IsEnable = true,
}
, new BaseEventsAppearance {
Name = "CH47", Color = "#fff", ActiveColor = "#10ff10", Icon = "https://www.dropbox.com/scl/fi/a0cuylwwtrwqrxr933jpd/ch47.png?rlkey=w9rv4ap58hmr3fwtkp4et4dn1&dl=1", IsEnable = true,
}
, new BaseEventsAppearance {
Name = "Cargo", Color = "#fff", ActiveColor = "#10ff10", Icon = "https://www.dropbox.com/scl/fi/lt4b833tybzzyas7bxst0/cargo.png?rlkey=i0xn03ctyz93a4rbybol2x5c2&dl=1", IsEnable = true,
}
, new BaseEventsAppearance {
Name = "AirDrop", Color = "#fff", ActiveColor = "#10ff10", Icon = "https://www.dropbox.com/scl/fi/udt3221xk7yk2zwqdd7id/airdrop.png?rlkey=7642d4ye3n63rby8nz0ej9ayr&dl=1", IsEnable = true,
}
,
}
;
[JsonProperty("Custom Events", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public List<CustomEventsAppearance> CustomEvents = new List<CustomEventsAppearance> {
new CustomEventsAppearance {
Name = "Convoy", Color = "#fff", ActiveColor = "#10ff10", Icon = "https://www.dropbox.com/scl/fi/s2ovq1yo8umvkn213cno0/convoy.png?rlkey=9mxlg4ypbypk5be59b57qgck3&dl=1", IsEnable = false, OnEventStart = new List<string> {
"OnConvoyStart"
}
, OnEventEnd = new List<string> {
"OnConvoyStop"
}
}
, new CustomEventsAppearance {
Name = "Sputnik", Color = "#fff", ActiveColor = "#10ff10", Icon = "https://www.dropbox.com/scl/fi/tlys9ulw51i74fpm6oec0/sputnik.png?rlkey=oe27iqf5ali445c90mgmcilea&dl=1", IsEnable = false, OnEventStart = new List<string> {
"OnSputnikEventStart"
}
, OnEventEnd = new List<string> {
"OnSputnikEventStop"
}
}
, new CustomEventsAppearance {
Name = "ArmoredTrain", Color = "#fff", ActiveColor = "#10ff10", Icon = "https://www.dropbox.com/scl/fi/d78jg4yrer0vqdspkxpg2/train.png?rlkey=9m4xll5wv6qrr0u2kb3pd2o4z&dl=1", IsEnable = false, OnEventStart = new List<string> {
"OnArmoredTrainEventStart"
}
, OnEventEnd = new List<string> {
"OnArmoredTrainEventStop"
}
}
, new CustomEventsAppearance {
Name = "Harbor", Color = "#fff", ActiveColor = "#10ff10", Icon = "https://www.dropbox.com/scl/fi/3qzyayoa4dxog2t8gyvzw/harbor.png?rlkey=v7jnpk8tyngwywvhbgrfhk5a4&dl=1", IsEnable = false, OnEventStart = new List<string> {
"OnHarborEventStart"
}
, OnEventEnd = new List<string> {
"OnHarborEventEnd"
}
}
,
}
;
public BaseEventsAppearance GetEventByName(string name) {
foreach (var check in BaseEvents) if (string.Equals(check.Name, name, StringComparison.CurrentCultureIgnoreCase)) return check;
foreach (var check in CustomEvents) if (string.Equals(check.Name, name, StringComparison.CurrentCultureIgnoreCase)) return check;
return null;
}
}
private class Data {
[JsonProperty("Players' state hud", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public Dictionary<string, States> PlayersState = new Dictionary<string, States>();
[JsonProperty(PropertyName = "First Run")]
public bool FirstRun = true;
}
private class Postition {
[JsonProperty("Align [TopLeft | TopRight | BottomLeft | BottomRight")]
public string Align;
[JsonProperty("Left | Right - offset")]
public int LeftOffSet;
[JsonProperty("Top | Bottom - offset")]
public int TopOffSet;
}
private class MainSetup {
[JsonProperty("Overall layer [you will see the hud in your inventory]")]
public bool IsOverall;
[JsonProperty("Size ALL [0% - inf]")]
public int Size;
[JsonProperty("Logo [HUD interact button]")]
public string Logo;
[JsonProperty("Background opacity [0% - 100%]")]
public int EventsBGOpacity;
[JsonProperty("Events background opacity [0% - 100%]")]
public int BGOpacity;
[JsonProperty("Position")]
public Postition Position;
[JsonProperty("Server name")]
public string ServerName;
[JsonProperty("Active players")]
public BaseAppearance ActivePlayersAppearance;
[JsonProperty("Sleep players")]
public BaseAppearance SleepPlayersAppearance;
[JsonProperty("Queue players")]
public BaseAppearance QueuePlayersAppearance;
[JsonProperty("Time")]
public TimeAppearance Time = new TimeAppearance();
[JsonProperty("Player position [hide permisson - hud.streamer]")]
public PlayerPositionAppearance PlayerPosition = new PlayerPositionAppearance();
[JsonProperty("Economy plugin [Economics | ServerRewards]")]
public EconomyAppearance Economy = new EconomyAppearance();
[JsonProperty("Info messages")]
public InfoMessage InfoMessages = new InfoMessage();
[JsonProperty("Additional menu")]
public AdditionalMenu AdditionalMenu = new AdditionalMenu();
}
private class EconomyAppearance {
[JsonProperty("Currency")]
public string Currency;
[JsonProperty("Value color")]
public string Color;
[JsonProperty("Enable")]
public bool IsEnable;
[JsonProperty("Which plugin use [ServerRewards | Economics]")]
public string Plugin;
}
private class TimeAppearance {
[JsonProperty("Use automatic detection of the time format for each player")]
public bool IsAutomaticDetection;
[JsonProperty("Use AM/PM format [If you use this turn off automatic detection]")]
public bool IsAmPm;
[JsonProperty("Value color")]
public string Color;
[JsonProperty("Enable")]
public bool IsEnable;
}
private class BaseAppearance {
[JsonProperty("Icon")]
public string Icon;
[JsonProperty("Color")]
public string Color;
[JsonProperty("Enable")]
public bool IsEnable;
}
private class BaseEventsAppearance : BaseAppearance {
[JsonIgnore]
public bool isActive;
[JsonProperty("Name")]
public string Name;
[JsonProperty("Active color")]
public string ActiveColor;
}
private class CustomEventsAppearance : BaseEventsAppearance {
[JsonProperty("Hook OnEventStart", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public List<string> OnEventStart;
[JsonProperty("Hook OnEventStop", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public List<string> OnEventEnd;
}
private class AdditionalMenu {
[JsonProperty("Auto close timer [seconds | 0 - disable]")]
public int AutoCloseTime;
[JsonProperty("Auto close after command use")]
public bool AutoCloseCommand;
[JsonProperty("Open/Close button color")]
public string ButtonColor;
[JsonProperty("Commands background opacity [0% - 100%]")]
public int CommandsOpacity;
[JsonProperty("Enable")]
public bool IsEnable;
[JsonProperty("Commands", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public List<CommandAppearance> Commands = new List<CommandAppearance>();
}
private class CommandAppearance {
[JsonProperty("Background image")]
public string Image;
[JsonProperty("Icon [optional]")]
public string Icon;
[JsonProperty("Command")]
public string Command;
[JsonProperty("Text")]
public string Text;
[JsonProperty("Outline color")]
public string OutlineColor;
[JsonProperty("Is Console")]
public bool IsConsole;
}
private class InfoMessage {
[JsonProperty("Update interval [in seconds]")]
public int UpdateInterval;
[JsonProperty("Align [BottomCenter | TopCenter | TopRight]")]
public string Align;
[JsonProperty("Width [in px]")]
public int Width;
[JsonProperty("Offset [top | bottom]")]
public int OffsetTB;
[JsonProperty("Offset [Center]")]
public int OffsetR;
[JsonProperty("Use Outline")]
public bool UseOutline = true;
[JsonProperty("Outline color")]
public string OutlineColor;
[JsonProperty("Overall [you will see messages in your invenotory]")]
public bool IsOverall;
[JsonProperty("Enable")]
public bool IsEnable;
[JsonProperty("Messages", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public List<string> Messages = new List<string>();
}
private class PlayerPositionAppearance {
[JsonProperty("Enable")]
public bool IsEnable;
[JsonProperty("true - grid | false - x,z coordinates")]
public bool IsGrid;
[JsonProperty("Color")]
public string Color;
}
#endregion
#endregion
#region OxideHooks
private void OnServerInitialized() {
if (_config.AutoReload) ServerMgr.Instance.StartCoroutine(ConfigCheck());
LoadImages();
LoadData();
FillCustomHooks();
EventsInit();
if (_data.FirstRun) timer.In(5, () => {
_data.FirstRun = false;
Interface.Oxide.ReloadPlugin("ImageLibrary");
Interface.Oxide.ReloadPlugin("Hud");
}
);
permission.RegisterPermission(PERM_STREAMER, this);
UI.Size = _config.MainSetup.Size / 100f;
if (!_config.MainSetup.QueuePlayersAppearance.IsEnable) Unsubscribe(nameof(OnConnectionQueue));
if (!_config.MainSetup.SleepPlayersAppearance.IsEnable) {
Unsubscribe(nameof(OnPlayerSleep));
Unsubscribe(nameof(OnPlayerSleepEnded));
}
foreach (var player in BasePlayer.activePlayerList) OnPlayerConnected(player);
if (_config.MainSetup.InfoMessages.IsEnable) InfoMessageUpdate = timer.Every(_config.MainSetup.InfoMessages.UpdateInterval, () => {
foreach (var check in BasePlayer.activePlayerList) ShowUIMessagesInfo(check);
}
);
ServerMgr.Instance.StartCoroutine(InfoUpdate());
}
private void Unload() {
SaveData();
UI.DestroyToAll(".bg");
UI.DestroyToAll(".bg.Messages.bg");
UI.DestroyToAll(".bgSettings");
}
private void OnPlayerConnected(BasePlayer player) {
if (player == null) return;
_data.PlayersState.TryAdd(player.UserIDString, States.Full);
ShowUIBG(player);
NextTick(() => ShowUIPlayersCounts());
}
private void OnConnectionQueue(Network.Connection connection) => NextTick(() => ShowUIPlayersCounts());
private void OnPlayerSleep(BasePlayer player) => NextTick(() => ShowUIPlayersCounts());
private void OnPlayerSleepEnded(BasePlayer player) => NextTick(() => ShowUIPlayersCounts());
#region EVENTS
private void OnEntitySpawned(BradleyAPC entity) => EventTouch(entity);
private void OnEntityKill(BradleyAPC entity) => EventTouch(entity);
private void OnEntitySpawned(PatrolHelicopter entity) => EventTouch(entity);
private void OnEntityKill(PatrolHelicopter entity) => EventTouch(entity);
private void OnEntitySpawned(CH47Helicopter entity) => EventTouch(entity);
private void OnEntityKill(CH47Helicopter entity) => EventTouch(entity);
private void OnEntitySpawned(CargoShip entity) => EventTouch(entity);
private void OnEntityKill(CargoShip entity) => EventTouch(entity);
private void OnEntitySpawned(SupplyDrop entity) => EventTouch(entity);
private void OnEntityKill(SupplyDrop entity) => EventTouch(entity);
private void EventTouch(BaseEntity entity) => NextTick(() => {
if (entity?.OwnerID != 0) return;
if (entity is BradleyAPC) _config.GetEventByName("Bradley").isActive = BaseNetworkable.serverEntities.OfType<BradleyAPC>().Any();
else if (entity is PatrolHelicopter) _config.GetEventByName("PatrolHeli").isActive = BaseNetworkable.serverEntities.OfType<PatrolHelicopter>().Any();
else if (entity is CH47Helicopter) _config.GetEventByName("CH47").isActive = BaseNetworkable.serverEntities.OfType<CH47Helicopter>().Any();
else if (entity is CargoShip) _config.GetEventByName("Cargo").isActive = BaseNetworkable.serverEntities.OfType<CargoShip>().Any();
else if (entity is SupplyDrop) _config.GetEventByName("AirDrop").isActive = BaseNetworkable.serverEntities.OfType<SupplyDrop>().Any();
else return;
ShowUIEvents();
}
);
#endregion
#endregion
#region Commands
[ConsoleCommand("UI_H")]
private void cmdConsoleUI_H(ConsoleSystem.Arg arg) {
if (!arg.HasArgs()) return;
var player = arg.Player();
switch (arg.GetString(0)) {
case "CHANGESTATE" : var state = _data.PlayersState[player.UserIDString];
_data.PlayersState[player.UserIDString] = state == States.Full ? States.Events : state == States.Events ? States.Hide : States.Full;
ShowUIMain(player);
break;
case "CHANGEADMENUSTATE" : ShowUIAdditionalMenu(player, !arg.GetBool(1));
if (!arg.GetBool(1) && _config.MainSetup.AdditionalMenu.AutoCloseTime > 0) timer.Once(_config.MainSetup.AdditionalMenu.AutoCloseTime, () => ShowUIAdditionalMenu(player));
break;
case "USECOMMAND" : player.SendConsoleCommand(arg.GetBool(1) ? $"{string.Join(" ", arg.Args.Skip(2))}" : $"chat.say \"{string.Join(" ", arg.Args.Skip(2))}\"");
if (_config.MainSetup.AdditionalMenu.AutoCloseCommand) ShowUIAdditionalMenu(player);
break;
case "s" : BaseAppearance ap = null;
switch (arg.GetString(1)) {
case "io" : _config.MainSetup.IsOverall = !_config.MainSetup.IsOverall;
ShowUISettings(player);
break;
case "size" : _config.MainSetup.Size = arg.GetInt(2);
UI.Size = _config.MainSetup.Size / 100f;
ShowUISettings(player);
break;
case "logo" : _config.MainSetup.Logo = arg.GetString(2);
AddImage(_config.MainSetup.Logo);
ShowUISettings(player);
break;
case "eventsbgop" : _config.MainSetup.EventsBGOpacity = arg.GetInt(2);
ShowUISettings(player);
break;
case "bgop" : _config.MainSetup.BGOpacity = arg.GetInt(2);
ShowUISettings(player);
break;
case "posalign" : _config.MainSetup.Position.Align = arg.GetString(2);
ShowUISettings(player);
break;
case "posleft" : _config.MainSetup.Position.LeftOffSet = arg.GetInt(2);
ShowUISettings(player);
break;
case "postop" : _config.MainSetup.Position.TopOffSet = arg.GetInt(2);
ShowUISettings(player);
break;
case "name" : _config.MainSetup.ServerName = string.Join(" ", arg.Args.Skip(2));
ShowUISettings(player);
break;
case "activeopen" : ap = _config.MainSetup.ActivePlayersAppearance;
OpenPlayersConfiguration(player, "Active players", ap.IsEnable, ap.Icon, ap.Color, "UI_H s aenable", "UI_H s aicon ", "UI_H s acolor ");
break;
case "sleepopen" : ap = _config.MainSetup.SleepPlayersAppearance;
OpenPlayersConfiguration(player, "Sleep players", ap.IsEnable, ap.Icon, ap.Color, "UI_H s senable", "UI_H s sicon ", "UI_H s scolor ");
break;
case "queueopen" : ap = _config.MainSetup.QueuePlayersAppearance;
OpenPlayersConfiguration(player, "Queue players", ap.IsEnable, ap.Icon, ap.Color, "UI_H s qenable", "UI_H s qicon ", "UI_H s qcolor ");
break;
case "aenable" : ap = _config.MainSetup.ActivePlayersAppearance;
ap.IsEnable = !ap.IsEnable;
OpenPlayersConfiguration(player, "Active players", ap.IsEnable, ap.Icon, ap.Color, "UI_H s aenable", "UI_H s aicon ", "UI_H s acolor ");
break;
case "aicon" : ap = _config.MainSetup.ActivePlayersAppearance;
ap.Icon = arg.GetString(2);
AddImage(ap.Icon);
OpenPlayersConfiguration(player, "Active players", ap.IsEnable, ap.Icon, ap.Color, "UI_H s aenable", "UI_H s aicon ", "UI_H s acolor ");
break;
case "acolor" : ap = _config.MainSetup.ActivePlayersAppearance;
ap.Color = arg.GetString(2);
OpenPlayersConfiguration(player, "Active players", ap.IsEnable, ap.Icon, ap.Color, "UI_H s aenable", "UI_H s aicon ", "UI_H s acolor ");
break;
case "senable" : ap = _config.MainSetup.SleepPlayersAppearance;
ap.IsEnable = !ap.IsEnable;
OpenPlayersConfiguration(player, "Active players", ap.IsEnable, ap.Icon, ap.Color, "UI_H s senable", "UI_H s sicon ", "UI_H s scolor ");
break;
case "sicon" : ap = _config.MainSetup.SleepPlayersAppearance;
ap.Icon = arg.GetString(2);
AddImage(ap.Icon);
OpenPlayersConfiguration(player, "Active players", ap.IsEnable, ap.Icon, ap.Color, "UI_H s senable", "UI_H s sicon ", "UI_H s scolor ");
break;
case "scolor" : ap = _config.MainSetup.SleepPlayersAppearance;
ap.Color = arg.GetString(2);
OpenPlayersConfiguration(player, "Active players", ap.IsEnable, ap.Icon, ap.Color, "UI_H s senable", "UI_H s sicon ", "UI_H s scolor ");
break;
case "qenable" : ap = _config.MainSetup.QueuePlayersAppearance;
ap.IsEnable = !ap.IsEnable;
OpenPlayersConfiguration(player, "Active players", ap.IsEnable, ap.Icon, ap.Color, "UI_H s qenable", "UI_H s qicon ", "UI_H s qcolor ");
break;
case "qicon" : ap = _config.MainSetup.QueuePlayersAppearance;
ap.Icon = arg.GetString(2);
AddImage(ap.Icon);
OpenPlayersConfiguration(player, "Active players", ap.IsEnable, ap.Icon, ap.Color, "UI_H s qenable", "UI_H s qicon ", "UI_H s qcolor ");
break;
case "qcolor" : ap = _config.MainSetup.QueuePlayersAppearance;
ap.Color = arg.GetString(2);
OpenPlayersConfiguration(player, "Active players", ap.IsEnable, ap.Icon, ap.Color, "UI_H s qenable", "UI_H s qicon ", "UI_H s qcolor ");
break;
case "timeopen" : OpenClockConfiguration(player);
break;
case "playerposopen" : OpenPlayerPositionConfiguration(player);
break;
case "economyopen" : OpenEconomyConfiguration(player);
break;
case "tautodetect" : _config.MainSetup.Time.IsAutomaticDetection = !_config.MainSetup.Time.IsAutomaticDetection;
OpenClockConfiguration(player);
break;
case "tisam" : _config.MainSetup.Time.IsAmPm = !_config.MainSetup.Time.IsAmPm;
OpenClockConfiguration(player);
break;
case "tcolor" : _config.MainSetup.Time.Color = arg.GetString(2);
OpenClockConfiguration(player);
break;
case "tenable" : _config.MainSetup.Time.IsEnable = !_config.MainSetup.Time.IsEnable;
OpenClockConfiguration(player);
break;
case "ppisgrid" : _config.MainSetup.PlayerPosition.IsGrid = !_config.MainSetup.PlayerPosition.IsGrid;
OpenPlayerPositionConfiguration(player);
break;
case "ppcolor" : _config.MainSetup.PlayerPosition.Color = arg.GetString(2);
OpenPlayerPositionConfiguration(player);
break;
case "ppenabled" : _config.MainSetup.PlayerPosition.IsEnable = !_config.MainSetup.PlayerPosition.IsEnable;
OpenPlayerPositionConfiguration(player);
break;
case "ecurrency" : _config.MainSetup.Economy.Currency = arg.GetString(2);
OpenEconomyConfiguration(player);
break;
case "eplugin" : _config.MainSetup.Economy.Plugin = arg.GetString(2);
OpenEconomyConfiguration(player);
break;
case "ecolor" : _config.MainSetup.Economy.Color = arg.GetString(2);
OpenEconomyConfiguration(player);
break;
case "eenable" : _config.MainSetup.Economy.IsEnable = !_config.MainSetup.Economy.IsEnable;
OpenEconomyConfiguration(player);
break;
case "openinfo" : OpenInfoMessagesConfiguration(player);
break;
case "ienable" : _config.MainSetup.InfoMessages.IsEnable = !_config.MainSetup.InfoMessages.IsEnable;
if (_config.MainSetup.InfoMessages.IsEnable) {
InfoMessageUpdate?.Destroy();
InfoMessageUpdate = timer.Every(_config.MainSetup.InfoMessages.UpdateInterval, () => {
foreach (var check in BasePlayer.activePlayerList) ShowUIMessagesInfo(check);
}
);
}
else {
InfoMessageUpdate?.Destroy();
UI.DestroyToAll(UI.Layer + ".Messages.bg");
}
OpenInfoMessagesConfiguration(player);
break;
case "ioverall" : _config.MainSetup.InfoMessages.IsOverall = !_config.MainSetup.InfoMessages.IsOverall;
OpenInfoMessagesConfiguration(player);
break;
case "iuseoutline" : _config.MainSetup.InfoMessages.UseOutline = !_config.MainSetup.InfoMessages.UseOutline;
OpenInfoMessagesConfiguration(player);
break;
case "iupdateint" : _config.MainSetup.InfoMessages.UpdateInterval = arg.GetInt(2);
if (_config.MainSetup.InfoMessages.IsEnable) {
InfoMessageUpdate?.Destroy();
InfoMessageUpdate = timer.Every(_config.MainSetup.InfoMessages.UpdateInterval, () => {
foreach (var check in BasePlayer.activePlayerList) ShowUIMessagesInfo(check);
}
);
}
OpenInfoMessagesConfiguration(player);
break;
case "ialign" : _config.MainSetup.InfoMessages.Align = arg.GetString(2);
OpenInfoMessagesConfiguration(player);
break;
case "iwidth" : _config.MainSetup.InfoMessages.Width = arg.GetInt(2);
OpenInfoMessagesConfiguration(player);
break;
case "itboff" : _config.MainSetup.InfoMessages.OffsetTB = arg.GetInt(2);
OpenInfoMessagesConfiguration(player);
break;
case "iroff" : _config.MainSetup.InfoMessages.OffsetR = arg.GetInt(2);
OpenInfoMessagesConfiguration(player);
break;
case "ioutlinecolor" : _config.MainSetup.InfoMessages.OutlineColor = arg.GetString(2);
OpenInfoMessagesConfiguration(player);
break;
case "imremove" : _config.MainSetup.InfoMessages.Messages.RemoveAt(arg.GetInt(2));
OpenInfoMessagesConfiguration(player);
break;
case "imadd" : _config.MainSetup.InfoMessages.Messages.Add(string.Join(" ", arg.Args.Skip(2)));
OpenInfoMessagesConfiguration(player);
break;
case "amenable" : _config.MainSetup.AdditionalMenu.IsEnable = !_config.MainSetup.AdditionalMenu.IsEnable;
OpenAdditionalMenuConfiguration(player);
break;
case "amautoclose" : _config.MainSetup.AdditionalMenu.AutoCloseCommand = !_config.MainSetup.AdditionalMenu.AutoCloseCommand;
OpenAdditionalMenuConfiguration(player);
break;
case "amclosetimer" : _config.MainSetup.AdditionalMenu.AutoCloseTime = arg.GetInt(2);
OpenAdditionalMenuConfiguration(player);
break;
case "amopacity" : _config.MainSetup.AdditionalMenu.CommandsOpacity = arg.GetInt(2);
OpenAdditionalMenuConfiguration(player);
break;
case "amcolor" : _config.MainSetup.AdditionalMenu.ButtonColor = arg.GetString(2);
OpenAdditionalMenuConfiguration(player);
break;
case "amopen" : OpenAdditionalMenuConfiguration(player);
break;
case "amcreatenew" : _config.MainSetup.AdditionalMenu.Commands.Add(new CommandAppearance {
Text = "Nex Example", Command = "chat.say Hello there", Icon = "https://www.dropbox.com/scl/fi/weax6ug55o0u4f87bhchs/active.png?rlkey=lbpuhpqs7tutpgv1i4t3b1107&dl=1", Image = "https://www.dropbox.com/scl/fi/ypbnnbs07i2t322x1pu4c/command.png?rlkey=a693i43bn70wiy2p0v0216uw7&dl=1", IsConsole = true, OutlineColor = "#000"
}
);
OpenAdditionalMenuConfiguration(player);
break;
case "amedit" : OpenAdditionalMenuButtonConfiguration(player, arg.GetInt(2));
break;
case "ceventhookedit" : OpenEventHookList(player, arg.GetInt(2), arg.GetInt(3));
break;
case "amebtext" : _config.MainSetup.AdditionalMenu.Commands[arg.GetInt(2)].Text = string.Join(" ", arg.Args.Skip(3));
OpenAdditionalMenuConfiguration(player);
OpenAdditionalMenuButtonConfiguration(player, arg.GetInt(2));
break;
case "amebcommand" : _config.MainSetup.AdditionalMenu.Commands[arg.GetInt(2)].Command = string.Join(" ", arg.Args.Skip(3));
OpenAdditionalMenuButtonConfiguration(player, arg.GetInt(2));
break;
case "ameboutlinecolor" : _config.MainSetup.AdditionalMenu.Commands[arg.GetInt(2)].OutlineColor = arg.GetString(3);
OpenAdditionalMenuButtonConfiguration(player, arg.GetInt(2));
break;
case "amebicon" : _config.MainSetup.AdditionalMenu.Commands[arg.GetInt(2)].Icon = arg.GetString(3);
AddImage(_config.MainSetup.AdditionalMenu.Commands[arg.GetInt(2)].Icon);
OpenAdditionalMenuButtonConfiguration(player, arg.GetInt(2));
break;
case "amebimage" : _config.MainSetup.AdditionalMenu.Commands[arg.GetInt(2)].Image = arg.GetString(3);
AddImage(_config.MainSetup.AdditionalMenu.Commands[arg.GetInt(2)].Image);
OpenAdditionalMenuButtonConfiguration(player, arg.GetInt(2));
break;
case "amebisconsole" : _config.MainSetup.AdditionalMenu.Commands[arg.GetInt(2)].IsConsole = !_config.MainSetup.AdditionalMenu.Commands[arg.GetInt(2)].IsConsole;
OpenAdditionalMenuButtonConfiguration(player, arg.GetInt(2));
break;
case "ambdelete" : _config.MainSetup.AdditionalMenu.Commands.RemoveAt(arg.GetInt(2));
OpenAdditionalMenuConfiguration(player);
break;
case "beopen" : OpenBaseEventConfiguration(player, arg.GetInt(2));
break;
case "beenable" : _config.BaseEvents[arg.GetInt(2)].IsEnable = !_config.BaseEvents[arg.GetInt(2)].IsEnable;
CalculateEventsWidth();
OpenBaseEventConfiguration(player, arg.GetInt(2));
break;
case "beicon" : _config.BaseEvents[arg.GetInt(2)].Icon = arg.GetString(3);
AddImage(_config.BaseEvents[arg.GetInt(2)].Icon);
ShowUISettings(player);
OpenBaseEventConfiguration(player, arg.GetInt(2));
break;
case "beacolor" : _config.BaseEvents[arg.GetInt(2)].ActiveColor = arg.GetString(3);
OpenBaseEventConfiguration(player, arg.GetInt(2));
break;
case "becolor" : _config.BaseEvents[arg.GetInt(2)].Color = arg.GetString(3);
OpenBaseEventConfiguration(player, arg.GetInt(2));
break;
case "ceopen" : OpenCustomEventConfiguration(player, arg.GetInt(2));
break;
case "ceenable" : _config.CustomEvents[arg.GetInt(2)].IsEnable = !_config.CustomEvents[arg.GetInt(2)].IsEnable;
CalculateEventsWidth();
OpenCustomEventConfiguration(player, arg.GetInt(2));
break;
case "cename" : _config.CustomEvents[arg.GetInt(2)].Name = arg.GetString(3);
OpenCustomEventConfiguration(player, arg.GetInt(2));
break;
case "ceicon" : _config.CustomEvents[arg.GetInt(2)].Icon = arg.GetString(3);
AddImage(_config.CustomEvents[arg.GetInt(2)].Icon);
OpenCustomEventConfiguration(player, arg.GetInt(2));
break;
case "ceactivecolor" : _config.CustomEvents[arg.GetInt(2)].ActiveColor = arg.GetString(3);
OpenCustomEventConfiguration(player, arg.GetInt(2));
break;
case "cecolor" : _config.CustomEvents[arg.GetInt(2)].Color = arg.GetString(3);
OpenCustomEventConfiguration(player, arg.GetInt(2));
break;
case "cedelete" : _config.CustomEvents.RemoveAt(arg.GetInt(2));
CalculateEventsWidth();
ShowUISettings(player);
break;
case "ceventhooksstartrem" : _config.CustomEvents[arg.GetInt(2)].OnEventStart.RemoveAt(arg.GetInt(3));
OpenEventHookList(player, arg.GetInt(2), 1);
break;
case "ceventhooksendrem" : _config.CustomEvents[arg.GetInt(2)].OnEventEnd.RemoveAt(arg.GetInt(3));
OpenEventHookList(player, arg.GetInt(2), 0);
break;
case "ceventhooksaddstart" : _config.CustomEvents[arg.GetInt(2)].OnEventStart.Add(arg.GetString(3));
OpenEventHookList(player, arg.GetInt(2), 1);
break;
case "ceventhooksaddend" : _config.CustomEvents[arg.GetInt(2)].OnEventEnd.Add(arg.GetString(3));
OpenEventHookList(player, arg.GetInt(2), 0);
break;
case "ceadd" : _config.CustomEvents.Add(new CustomEventsAppearance {
Name = "CustomEvent", IsEnable = true, Color = "#fff", Icon = "https://www.dropbox.com/scl/fi/3qzyayoa4dxog2t8gyvzw/harbor.png?rlkey=v7jnpk8tyngwywvhbgrfhk5a4&dl=1", ActiveColor = "#10ff10", OnEventStart = new List<string> {
"OnHarborEventStart"
}
, OnEventEnd = new List<string> {
"OnHarborEventEnd"
}
}
);
CalculateEventsWidth();
ShowUISettings(player);
break;
}
SaveConfig();
foreach (var check in BasePlayer.activePlayerList) ShowUIBG(check);
break;
}
}
[ChatCommand("h")]
private void cmdChat(BasePlayer player, string command, string[] args) {
if (player == null) return;
var text = "All commands:\n<color=yellow>/h open</color> - open ServerHud UI\n<color=yellow>/h events</color> - open Events only\n<color=yellow>/h hide</color> - hide ServerHud UI\n<color=yellow>/h close</color> - close ServerHud UI";
if (args.Length != 1) {
SendReply(player, text);
return;
}
var playerState = _data.PlayersState[player.UserIDString];
switch (args[0]) {
case "open" : _data.PlayersState[player.UserIDString] = States.Full;
break;
case "events" : _data.PlayersState[player.UserIDString] = States.Events;
break;
case "hide" : _data.PlayersState[player.UserIDString] = States.Hide;
break;
case "setup" : if (!player.IsAdmin) return;
ShowUISettingsBg(player);
return;
case "close" : _data.PlayersState[player.UserIDString] = States.Close;
UI.Destroy(player, ".bg");
UI.Destroy(player, ".bg.Messages.bg");
return;
default : SendReply(player, text);
break;
}
if (playerState == States.Close) ShowUIBG(player);
ShowUIMain(player);
}
#endregion
#region Functions
private void FillCustomHooks() {
var used = new List<string>();
var pluginCode = File.ReadAllText(Utility.CleanPath(Interface.Oxide.PluginDirectory + Path.DirectorySeparatorChar + "Hud.cs"));
var lastIndex = pluginCode.LastIndexOf("/*CUSTOMEVENTAUTOCODE-START*/");
var length = pluginCode.Length;
var customarea = pluginCode.Substring(lastIndex, length - lastIndex - (length - pluginCode.LastIndexOf("*/")) + 2);
var currentCode = "/*CUSTOMEVENTAUTOCODE-START*/";
foreach (var check in _config.CustomEvents) {
if (!check.IsEnable) continue;
foreach (var hook in check.OnEventStart) {
if (used.Contains(hook)) continue;
currentCode += $"private void {hook}()=>OnEventTouch(System.Reflection.MethodBase.GetCurrentMethod().Name);";
used.Add(hook);
}
foreach (var hook in check.OnEventEnd) {
if (used.Contains(hook)) continue;
currentCode += $"private void {hook}()=>OnEventTouch(System.Reflection.MethodBase.GetCurrentMethod().Name);";
used.Add(hook);
}
}
currentCode += "/*CUSTOMEVENTAUTOCODE-END*/";
if (customarea == currentCode) return;
PrintWarning("We noticed a change in CustomEventHooks, we are rewriting the plugin with your changes.The plugin will be automatically reloaded!");
var newPluginCode = pluginCode.Replace(customarea, currentCode);
File.WriteAllText(Utility.CleanPath(Interface.Oxide.PluginDirectory + Path.DirectorySeparatorChar + "Hud.cs"), newPluginCode);
}
private void OnEventTouch(string name) {
foreach (var check in _config.CustomEvents) {
if (!check.IsEnable || (!check.OnEventStart.Contains(name) && !check.OnEventEnd.Contains(name))) continue;
check.isActive = check.OnEventStart.Contains(name);
ShowUIEvents();
break;
}
}
private string PositionToGridCoord(Vector3 position) {
var a = new Vector2(TerrainMeta.NormalizeX(position.x), TerrainMeta.NormalizeZ(position.z));
var num = TerrainMeta.Size.x / 1024f;
var num2 = 7;
var vector = a * num * num2;
var num3 = Mathf.Floor(vector.x) + 1f;
var num4 = Mathf.Floor(num * num2 - vector.y);
var text = string.Empty;
var num5 = num3 / 26f;
var num6 = num3 % 26f;
if (num6 == 0f) num6 = 26f;
if (num5 > 1f) text += Convert.ToChar(64 + (int)num5).ToString();
text += Convert.ToChar(64 + (int)num6).ToString();
return text + num4;
}
private IEnumerator InfoUpdate() {
while (true) {
if (!IsLoaded) yield break;
foreach (var check in BasePlayer.activePlayerList) {
if (_config.MainSetup.Time.IsEnable) ShowUITime(check);
if (_config.MainSetup.PlayerPosition.IsEnable) ShowUIPosition(check);
if (_config.MainSetup.Economy.IsEnable) ShowUIBalance(check);
}
yield return new WaitForSeconds(1f);
}
}
private void EventsInit() {
CalculateEventsWidth();
foreach (var entity in BaseNetworkable.serverEntities) {
if (entity == null || entity.IsDestroyed || !(entity is BaseEntity) || (entity as BaseEntity).OwnerID != 0) continue;
if (entity is BradleyAPC) _config.GetEventByName("Bradley").isActive = BaseNetworkable.serverEntities.OfType<BradleyAPC>().Any();
else if (entity is PatrolHelicopter) _config.GetEventByName("PatrolHeli").isActive = BaseNetworkable.serverEntities.OfType<PatrolHelicopter>().Any();
else if (entity is CH47Helicopter) _config.GetEventByName("CH47").isActive = BaseNetworkable.serverEntities.OfType<CH47Helicopter>().Any();
else if (entity is CargoShip) _config.GetEventByName("Cargo").isActive = BaseNetworkable.serverEntities.OfType<CargoShip>().Any();
else if (entity is SupplyDrop) _config.GetEventByName("AirDrop").isActive = BaseNetworkable.serverEntities.OfType<SupplyDrop>().Any();
}
}
private void CalculateEventsWidth() {
EventsPosStartPosX = 2;
foreach (var check in _config.BaseEvents) if (check.IsEnable) EventsPosStartPosX -= 17;
foreach (var check in _config.CustomEvents) if (check.IsEnable) EventsPosStartPosX -= 17;
EnableEventsCount = Math.Abs(EventsPosStartPosX - 2) / 17;
if (EnableEventsCount > 5) EventsPosStartPosX += _config.MainSetup.Position.Align.ToLower().Contains("right") ? -4 : 14;
}
#endregion
#region UI
private void ShowUISettingsBg(BasePlayer player) {
var container = new CuiElementContainer();
UI.MainParent(ref container, "Settings", "0 0", "1 1", sprite : "assets/content/ui/ui.background.transparent.radial.psd", color : "0.1691 0.1619 0.143 0.741");
UI.Panel(ref container, ".bgSettings", aMin : "0 0", aMax : "1 1", bgColor : "0.1691 0.1619 0.143 0.747", sprite : "assets/content/ui/ui.background.tile.psd", material : "assets/content/ui/uibackgroundblur-ingamemenu.mat", ignoreSize : true);
UI.Label(ref container, ".bgSettings", aMin : "0.5 0.5", aMax : "0.5 0.5", oXMin : -190, oXMax : 190, oYMin : -238, oYMax : -208, text : "Click anywhere outside the panel to exit", color : "0.9686 0.9216 0.8824 0.502", fontSize : 12, ignoreSize : true);
UI.TextButton(ref container, ".bgSettings", aMin : "0 0", aMax : "1 1", close : ".bgSettings", ignoreSize : true);
UI.Create(player, container);
ShowUISettings(player);
}
private void ShowUISettings(BasePlayer player) {
var y = -30;
var main = _config.MainSetup;
var container = new CuiElementContainer();
UI.Panel(ref container, ".bgSettings", ".bgSettings.Main", ".bgSettings.Main", "0.5 0.5", "0.5 0.5", -198, -208, 198, 268, "0.9686 0.9216 0.8824 0.0392", "assets/icons/greyout.mat", "assets/content/ui/ui.background.tile.psd", ignoreSize : true);
UI.Label(ref container, ".bgSettings.Main", null, null, "0.5 1", "0.5 1", -198, 0, 198, 35, "HUD SETUP", 28, outlineDistance : "0.
// ... [Code preview truncated due to length. Full source in attached file] ...