using System; using System.Collections.Generic; using System.Linq; using ConVar; using Facepunch; using Network; using Oxide.Core; using ProtoBuf; using Rust; using UnityEngine; using UnityEngine.Assertions; using Newtonsoft.Json; #region Changelogs and ToDo /********************************************************************** * * 1.0.0 : - Initial release * 1.0.1 : - Added skins * 1.0.2 : - Cleanup * 1.0.3 : - Rebranded from AdminNotes to StationaryPaper * - Added checks and debugs for cost checks * - Added skin for the vanilla note * 1.0.4 : - Added check for inventory space (thx Atope89) * 1.0.5 : - Fix for vanilla note text editing * 1.0.6 & 1.0.7 - Hotfix for vanilla note console error * 1.0.8 : - Fix for car keys resetting tekst * - Added changed tekst to debugg info * 1.0.9 : - Fix for Photographs * 1.1.0 : - Patched for Rust Update * - Coding cleanup * - Gametip optimisation * **********************************************************************/ #endregion namespace Oxide.Plugins { [Info("Stationary Paper", "Krungh Crow", "1.1.0")] [Description("Craft stationery paper notes")] class StationaryPaper : RustPlugin { #region Variables const string Admin_Perm = "stationarypaper.admin"; const string NormalCost_Perm = "stationarypaper.normal"; ulong chaticon = 76561199180049293; string FortuneMsg; string prefix; bool Debug = false; bool ActiveTip = false; #endregion #region Configuration void Init() { if (!LoadConfigVariables()) { Puts("Config file issue detected. Please delete file, or check syntax and fix."); return; } permission.RegisterPermission(Admin_Perm, this); permission.RegisterPermission(NormalCost_Perm, this); Debug = configData.PlugCFG.Debug; prefix = configData.PlugCFG.Prefix; if (Debug) Puts($"[Debug] trigger for Debug is true"); } private ConfigData configData; class ConfigData { [JsonProperty(PropertyName = "Main config")] public SettingsPlugin PlugCFG = new SettingsPlugin(); [JsonProperty(PropertyName = "Crafting Costs")] public SettingsCosts CostsCFG = new SettingsCosts(); } class SettingsPlugin { [JsonProperty(PropertyName = "Debug")] public bool Debug = false; [JsonProperty(PropertyName = "Chat Prefix")] public string Prefix = "[Stationary Paper] "; } class SettingsCosts { [JsonProperty(PropertyName = "Wood ammount")] public int CraftCost = 100; } private bool LoadConfigVariables() { try { configData = Config.ReadObject(); } catch { return false; } SaveConf(); return true; } protected override void LoadDefaultConfig() { Puts("Fresh install detected Creating a new config file."); configData = new ConfigData(); SaveConf(); } void SaveConf() => Config.WriteObject(configData, true); #endregion #region LanguageAPI protected override void LoadDefaultMessages() { lang.RegisterMessages(new Dictionary { ["NoteCrafted"] = "You succesfully crafted a {0}", ["Info"] = "\nAvailable Commands :\n/note info : Shows info on version/author and commands", ["InfoAdmin"] = "/note admin : Crafts a Admin Note", ["InfoBomb"] = "/note bomb : Crafts a Bomb letter (does not explode)", ["InfoCrow"] = "/note crow : Crafts a Crow Note", ["InfoInfo"] = "/note information : Crafts a Info Note", ["InfoLove"] = "/note love : Crafts a Love Letter", ["InvalidInput"] = "Please enter a valid command!", ["InventoryFull"] = "You need at least 1 more slot in your inventory,canceling the craft", ["Version"] = "Version : V", ["NoPermission"] = "You do not have permission to use that command!", }, this); } #endregion #region Commands [ChatCommand("Note")] private void cmdNote(BasePlayer player, string command, string[] args) { if (args.Length == 0) { Player.Message(player, prefix + string.Format(msg("InvalidInput", player.UserIDString)), chaticon); } else { if (args[0].ToLower() == "info") { Player.Message(player, prefix + string.Format(msg("Version", player.UserIDString)) + this.Version.ToString() + " By : " + this.Author.ToString() + msg("Info") + msg("\n") + msg("InfoAdmin") + msg("\n") + msg("InfoBomb") + msg("\n") + msg("InfoCrow") + msg("\n") + msg("InfoInfo") + msg("\n") + msg("InfoLove") , chaticon); return; } if (args[0].ToLower() == "admin") { if (!HasPerm(player, Admin_Perm)) { Player.Message(player, prefix + string.Format(msg("NoPermission", player.UserIDString)), chaticon); if (Debug) Puts($"[Debug] {player} had no permission for using Commands"); return; } CraftNote(player, "Admin Note", 2514975127UL); return; } if (args[0].ToLower() == "bomb") { CraftNoteBomb(player); return; } if (args[0].ToLower() == "crow") { CraftNoteCrow(player); return; } if (args[0].ToLower() == "information") { CraftNoteInfo(player); return; } if (args[0].ToLower() == "love") { CraftNoteLove(player); return; } else { Player.Message(player, prefix + string.Format(msg("InvalidInput", player.UserIDString)), chaticon); } } } #endregion #region Hooks [ConsoleCommand("note.update")] void OnNoteEdit(ConsoleSystem.Arg arg) { try { var str = arg.GetString(1, ""); BasePlayer editor = arg.Player(); var id = arg.GetULong(0); var item = editor.inventory.FindItemByUID(new ItemId(id)); if (editor == null || item == null) return; string TextCheck = item.text ?? ""; string newText = arg.Args[1]; bool PaperNoteEdit = editor.IPlayer.HasPermission(Admin_Perm) || editor.IsAdmin || editor.IsDeveloper; bool canWrite = String.IsNullOrEmpty(TextCheck); if(item.info.itemid == 62577426) { item.text = newText; if (Debug) Puts($"photo written/edited by : {editor} text = {newText}"); } if (item.info.itemid == 946662961 || item.name.Contains("Car Key")) { item.text = newText; if (Debug) Puts($"car.key written/edited/clicked on by : {editor} text = {newText}"); } if (item.name.Contains("Admin Note") && PaperNoteEdit) { item.text = newText; if (Debug) Puts($"Admin note written/edited/clicked on by : {editor} text = {newText}"); } if (item.name.Contains("Simple Note") || item.name.Contains("Bomb Note") || item.name.Contains("Crows Note") || item.name.Contains("Info Note") || item.name.Contains("Love Letter") || canWrite) { if (Debug) Puts($"{item.name} note written/edited by : {editor} text = {newText}"); item.text = newText; } item.MarkDirty(); } catch { } } void OnItemCraftFinished(ItemCraftTask task, Item item) { if (item.info.itemid == 1414245162) { item.skin = 2515255356UL; item.name = "Simple Note"; item.MarkDirty(); } } public void ItemRemove(BasePlayer player, int itemid, int amount) { var items = player.inventory.containerMain.itemList; int Amounts = 0; int Remaining = amount; for (int i = 0; i < items.Count; i++) { var item = items[i]; if (item == null || item.info.itemid != itemid) continue; Amounts = Remaining; if (item.amount < Amounts) Amounts = item.amount; if (item.amount > Amounts) item.SplitItem(Amounts); else item.UseItem(Amounts); Remaining = Remaining - Amounts; if (Remaining <= 0) break; } } #endregion #region Core private void CraftNote(BasePlayer player,string name, ulong skinid) { Item PaperNote = ItemManager.CreateByName("note", 1, skinid); if (PaperNote != null) { PaperNote.name = name; PaperNote.info.stackable = 1; PaperNote.MarkDirty(); PaperNote.MoveToContainer(player.inventory.containerMain); Player.Message(player, prefix + string.Format(msg($"NoteCrafted", player.UserIDString), PaperNote.name), chaticon); return; } else { Player.Message(player, prefix + string.Format(msg("Something went wrong", player.UserIDString)), chaticon); } } private void CraftNoteBomb(BasePlayer player) { int Cost = configData.CostsCFG.CraftCost; if (CheckWood(player, Cost)) { CraftNote(player, "Bomb Note", 2514978449UL); if (HasPerm(player ,NormalCost_Perm)) Cost = 10; ItemRemove(player, -151838493, Cost); TIP(player, $"-{Cost} wood", 5f); return; } } private void CraftNoteCrow(BasePlayer player) { int Cost = configData.CostsCFG.CraftCost; if (CheckWood(player, Cost)) { CraftNote(player, "Crows Note", 2514997813UL); if (HasPerm(player, NormalCost_Perm)) Cost = 10; ItemRemove(player, -151838493, Cost); TIP(player, $"-{Cost} wood", 5f); return; } } private void CraftNoteInfo(BasePlayer player) { int Cost = configData.CostsCFG.CraftCost; if (CheckWood(player, Cost)) { CraftNote(player, "Info Note", 2514986521UL); if (HasPerm(player, NormalCost_Perm)) Cost = 10; ItemRemove(player, -151838493, Cost); TIP(player, $"-{Cost} wood", 5f); return; } } private void CraftNoteLove(BasePlayer player) { int Cost = configData.CostsCFG.CraftCost; if (CheckWood(player, Cost)) { CraftNote(player, "Love Letter", 2514963840UL); if (HasPerm(player, NormalCost_Perm)) Cost = 10; ItemRemove(player, -151838493, Cost); TIP(player, $"-{Cost} wood", 5f); return; } } private bool CheckWood(BasePlayer player,int Cost) { if (player.inventory.GetAmount(-151838493) >= Cost && !(player.inventory.containerMain.IsFull())) { if (Debug) Puts($"{player} has enough wood and/or inventory space"); return true; } if (player.inventory.containerMain.IsFull()) { if (Debug) Puts($"{player} has no inventory space"); Player.Message(player, prefix + string.Format(msg($"InventoryFull", player.UserIDString)), chaticon); return false; } else { if (Debug) Puts($"{player} was {Cost - player.inventory.GetAmount(-151838493)} Wood short"); Player.Message(player, prefix + string.Format(msg($"you are {Cost - player.inventory.GetAmount(-151838493)} Wood short", player.UserIDString)), chaticon); return false; } } #endregion #region Message helpers private string msg(string key, string id = null) => lang.GetMessage(key, this, id); void TIP(BasePlayer player, string message, float dur) { if (player == null) return; if (!ActiveTip) { player?.SendConsoleCommand("gametip.hidegametip"); player.SendConsoleCommand("gametip.showgametip", message); ActiveTip = true; timer.Once(dur, () => { player?.SendConsoleCommand("gametip.hidegametip"); ActiveTip = false; }); } else timer.Once(1f, () => { Puts("Check frequency 1 sec"); TIP(player, message, dur); }); } bool HasPerm(BasePlayer player, string perm) { return permission.UserHasPermission(player.UserIDString, perm); } #endregion } }