using UnityEngine; using Oxide.Core.Libraries.Covalence; using System.Collections.Generic; using Oxide.Game.Rust.Cui; using System; using Oxide.Core; using Newtonsoft.Json; using Oxide.Core.Plugins; namespace Oxide.Plugins { [Info("CustomStatusFrameworkDemo", "mr01sam", "1.0.0")] [Description("A demo for custom status framework for developers to use as a reference")] internal class CustomStatusFrameworkDemo : CovalencePlugin { /* * A brief demo for showcasing the API available for Custom Status Framework v1.0.8. */ [PluginReference] private Plugin CustomStatusFramework; [PluginReference] private Plugin ImageLibrary; private void Unload() { /* Global statuses should be deleted when the is plugin unloaded */ CustomStatusFramework?.Call("DeleteStatus", "demo.crouched"); CustomStatusFramework?.Call("DeleteStatus", "demo.scrap"); /* It is also recommended to clear all other statues for active players on unload */ foreach(var basePlayer in BasePlayer.activePlayerList) { CustomStatusFramework?.Call("ClearStatus", basePlayer, "demo.vip" ); CustomStatusFramework?.Call("ClearStatus", basePlayer, "demo.welcome" ); } } private void OnPluginLoaded(Plugin plugin) { /* * IMPORTANT - You'll want to re-create any global statuses if CSF is reloaded. */ if (plugin.Name == "CustomStatusFramework") { CreateGlobalStatuses(); } } private void OnServerInitialized() { /* * These custom images are hosted on imgur and will be used for the status images. */ ImageLibrary.Call("AddImage", "https://i.imgur.com/vnHTj1C.png", "star", 0UL); ImageLibrary.Call("AddImage", "https://i.imgur.com/SDfm0Eb.png", "ninja", 0UL); ImageLibrary.Call("AddImage", "https://i.imgur.com/MLRiCM0.png", "wave", 0UL); ImageLibrary.Call("AddImage", "https://i.imgur.com/pe5KmTb.png", "money", 0UL); CreateGlobalStatuses(); } private void CreateGlobalStatuses() { /* * We will create a global status that will only be shown to players who are crouching. */ Func crouched = (basePlayer) => { if (basePlayer == null) { return false; } return basePlayer.IsDucked(); }; CustomStatusFramework?.Call("CreateStatus", "demo.crouched", "0.3 0.3 0.3 1", "Ninja", "1 1 1 1", "So sneaky!", "0.7 0.7 0.7 1", "ninja", "1 1 1 1", crouched ); /* * We will create a global dynamic status that will show a player how much scrap they have in their * inventory and will only appear for players that have any scrap in their inventory. * * WARNING - Dynamic statuses should be used infrequently, as they may affect performance with large * amounts of players. If possible, it is better to use UpdateStatus and ClearStatus when a hook is * triggered. */ Func hasScrap = (basePlayer) => { if (basePlayer == null) { return false; } return basePlayer.inventory.GetAmount(-932201673) > 0; }; Func scrapAmount = (basePlayer) => { if (basePlayer == null) { return ""; } return basePlayer.inventory.GetAmount(-932201673).ToString(); // this will only consider 1 stack, but its fine for this demo }; CustomStatusFramework?.Call("CreateDynamicStatus", "demo.scrap", "0.2 0.4 0.2 1", "Scrap", "1 1 1 1", "0.7 0.7 0.7 1", "money", "1 1 1 1", hasScrap, scrapAmount ); } /// /// Shows a welcome status for a few seconds before disappearing. /// [Command("welcome")] void CmdWelcome(IPlayer player, string command, string[] args) { var basePlayer = player.Object as BasePlayer; if (basePlayer == null) { return; } CustomStatusFramework?.Call("ShowStatus", basePlayer, "demo.welcome", "0.6 0 0.6 1", "Welcome!", "1 1 1 1", basePlayer.displayName, "0.7 0.7 0.7 1", "wave", "1 1 1 1" ); } HashSet PlayersWithStarEnabled = new HashSet(); /// /// Toggles the visibility of the VIP status. /// [Command("star")] void CmdStar(IPlayer player, string command, string[] args) { var basePlayer = player.Object as BasePlayer; if (basePlayer == null) { return; } if (!PlayersWithStarEnabled.Contains(basePlayer)) { // Turn on the VIP status PlayersWithStarEnabled.Add(basePlayer); CustomStatusFramework?.Call("UpdateStatus", basePlayer, "demo.vip", "0.7 0.4 0 1", "VIP", "1 1 1 1", "You rock!", "1 1 1 1", "star", "1 1 1 1" ); } else { // Turn off the VIP status PlayersWithStarEnabled.Remove(basePlayer); CustomStatusFramework?.Call("ClearStatus", basePlayer, "demo.vip" ); } } } }