Plugin Update - Top Left Balance Display without Background

Hello everyone!

I want to share with the community some modifications I made to the Economics Balance GUI plugin created by Misticos. I am extremely grateful to Misticos for their excellent work in developing this plugin. I have taken the liberty to make some adjustments to better fit the specific needs of my server.

Modifications:

Position of the Balance:

  • Now, the coin balance is displayed in the top left corner of the screen, aligned similarly to the clock in the top right corner.

No Background:

  • I have removed the background of the balance for a cleaner and more minimalist appearance.

Currency Symbol ($):

  • The currency symbol ($) is displayed next to the amount without the original spacing, achieving a more compact and aesthetic integration.

Sharper and Smaller Font:

  • The font has been adjusted to be sharper and smaller, similar to the clock, to improve visual coherence.

Modified Code:


using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using System;
using System.Collections.Generic;
using UnityEngine;

namespace Oxide.Plugins
{
    [Info("Economics Balance GUI", "lethal_d0se & misticos", "1.1.4")]
    [Description("Displays a player's economics balance on the HUD.")]
    public class EconomicsBalanceGUI : RustPlugin
    {
        [PluginReference]
        private Plugin Economics;
        private List Looters = new List();
        private Dictionary<ulong, double> Balances = new Dictionary<ulong, double>();
        private string GUIColor => GetConfig("GUIColor", "0 0 0 0");
        private string GUIAnchorMin => GetConfig("GUIAnchorMin", "0.02 0.97");
        private string GUIAnchorMax => GetConfig("GUIAnchorMax", "0.06 1.0");
        private string GUICurrency => GetConfig("GUICurrency", "$");
        private string GUICurrencySize => GetConfig("GUICurrencySize", "12");
        private string GUICurrencyColor => GetConfig("GUICurrencyColor", "1.0 1.0 1.0 1.0");
        private string GUIBalanceSize => GetConfig("GUIBalanceSize", "12");
        private string GUIBalanceColor => GetConfig("GUIBalanceColor", "1.0 1.0 1.0 1.0");

        private const string UINamePrefix = "EconomicsBalanceUI"; // Prefijo para el identificador ΓΊnico de la UI

        private void OnServerInitialized()
        {
            if (Economics)
            {
                PrintWarning("Economics plugin found, initializing balance display.");
                timer.Repeat(0.5f, 0, () =>
                {
                    if (Economics.IsLoaded)
                    {
                        foreach (BasePlayer player in BasePlayer.activePlayerList)
                        {
                            double currentBalance = Economics.Call("Balance", player.UserIDString);

                            if (Balances.ContainsKey(player.userID))
                            {
                                double savedBalance = Balances[player.userID];

                                if (savedBalance != currentBalance)
                                {
                                    if (!Looters.Contains(player.userID))
                                    {
                                        Balances[player.userID] = currentBalance;
                                        GUIRefresh(player);
                                    }
                                }
                            }
                            else
                            {
                                Balances.Add(player.userID, currentBalance);
                                GUIRefresh(player);
                            }
                        }
                    }
                });
            }
        }

        private void Unload()
        {
            if (Economics)
            {
                foreach (BasePlayer player in BasePlayer.activePlayerList)
                    GUIDestroy(player);
            }
        }

        protected override void LoadDefaultConfig()
        {
            PrintWarning("Loading default configuration.");
            Config["GUIColor"] = "0 0 0 0";
            Config["GUIAnchorMin"] = "0.02 0.97";
            Config["GUIAnchorMax"] = "0.06 1.0";
            Config["GUICurrency"] = "$";
            Config["GUICurrencySize"] = "12";
            Config["GUICurrencyColor"] = "1.0 1.0 1.0 1.0";
            Config["GUIBalanceSize"] = "12";
            Config["GUIBalanceColor"] = "1.0 1.0 1.0 1.0";
            SaveConfig();
        }

        private void OnPlayerConnected(BasePlayer player)
        {
            if (Economics && Economics.IsLoaded)
            {
                Balances[player.userID] = Economics.Call("Balance", player.UserIDString);
                GUIRefresh(player);
            }
        }

        private void OnPlayerSleepEnded(BasePlayer player)
        {
            if (Economics)
                GUIRefresh(player);
        }

        private void OnPlayerLootEnd(PlayerLoot inventory)
        {
            if (Economics)
            {
                BasePlayer player = inventory.GetComponent();
                if (player != null && Looters.Contains(player.userID))
                {
                    Looters.Remove(player.userID);
                    GUICreate(player);
                }
            }
        }

        private void OnPlayerRespawned(BasePlayer player)
        {
            if (Economics)
                GUIDestroy(player);
        }

        private void OnPlayerDisconnected(BasePlayer player)
        {
            if (Economics)
            {
                GUIDestroy(player);
                Balances.Remove(player.userID);
            }
        }

        private void OnLootEntity(BasePlayer looter, BaseEntity target)
        {
            if (Economics)
            {
                Looters.Add(looter.userID);
                GUIDestroy(looter);
            }
        }

        private void OnLootPlayer(BasePlayer looter, BasePlayer beingLooter)
        {
            if (Economics)
            {
                Looters.Add(looter.userID);
                GUIDestroy(looter);
            }
        }

        private void OnLootItem(BasePlayer looter, Item lootedItem)
        {
            if (Economics)
            {
                Looters.Add(looter.userID);
                GUIDestroy(looter);
            }
        }

        // Interface.

        private void GUICreate(BasePlayer player)
        {
            string currentBalance = (Economics.IsLoaded) ? GetFormattedMoney(player) : "...";
            string combinedText = $"{GUICurrency}{currentBalance}";

            var GUIElement = new CuiElementContainer();
            var panelName = $"{UINamePrefix}_{player.UserIDString}"; // Identificador ΓΊnico para el panel del jugador

            GUIElement.Add(new CuiPanel
            {
                Image =
                {
                    Color = GUIColor
                },
                RectTransform =
                {
                    AnchorMin = GUIAnchorMin,
                    AnchorMax = GUIAnchorMax
                },
                CursorEnabled = false
            }, "Hud", panelName);

            GUIElement.Add(new CuiLabel
            {
                Text =
                {
                    Text = combinedText,
                    FontSize = 12,
                    Align = TextAnchor.MiddleLeft,
                    Color = GUIBalanceColor,
                    Font = "RobotoCondensed-Bold.ttf"
                },
                RectTransform =
                {
                    AnchorMin = "0 0",
                    AnchorMax = "1 1"
                }
            }, panelName);

            CuiHelper.AddUi(player, GUIElement);
        }

        private void GUIDestroy(BasePlayer player)
        {
            var panelName = $"{UINamePrefix}_{player.UserIDString}";
            CuiHelper.DestroyUi(player, panelName); // Destruye la UI usando el identificador ΓΊnico
        }

        private void GUIRefresh(BasePlayer player)
        {
            GUIDestroy(player);
            GUICreate(player);
        }

        // Helpers.

        private string GetFormattedMoney(BasePlayer player)
        {
            string s = string.Format("{0:C}", (double)Economics?.Call("Balance", player.UserIDString));
            s = s.Substring(1);
            s = s.Remove(s.Length - 3);
            return s;
        }

        private T GetConfig(string name, T defaultValue)
        {
            if (Config[name] == null)
                return defaultValue;

            return (T)Convert.ChangeType(Config[name], typeof(T));
        }
    }
}

Thank you very much to Misticos for creating the original plugin. I hope these modifications will be useful to other server admins looking for a cleaner and more tailored balance display.

Best regards, and happy server administration! πŸš€

Error while compiling EconomicsBalanceGUI: The type or namespace name 'T' could not be found (are you missing a using directive or an

Β 

got this error