using Newtonsoft.Json;
using Oxide.Core.Libraries.Covalence;
using Oxide.Core.Configuration;
using Oxide.Core.Plugins;
using Rust;
using Facepunch;
using System.Collections.Generic;
using UnityEngine;
using System;
using System.Linq;
using System.Collections.Generic;
using Oxide.Game.Rust.Cui;
using Oxide.Core;
#region Changelogs and Todo
/**********************************************************************
*
* 1.0.0 : - Initial release
* 1.0.1 : - Added HumanNPC support
* - Added perms for shop or npc useage
* - Added NPC responce message in language file
* 1.0.2 : - Added various text color options
* - Added Font type option
* 1.0.3 : - fix Item amount minimum check.
* - Added Internal Skin.ID check if custom bone name is removed.
* 1.1.0 : - Added check for server to be fully initialised to set values
* - Updated and added messages in the language file
* - When the players inventory is full the Tradeitem will drop on the floor
* - When the players inventory is full a warning is displayed in the UI
* - Code cleanup
* - Fixed handout amounts
* 1.1.1 - Fix for random serversave nre
* 1.2.0 - Fix for OnServerSave Patched by Mabel
* 1.2.1 - Patched for Rust oct update
*
**********************************************************************/
#endregion
namespace Oxide.Plugins
{
[Info("BoneMarket", "Krungh Crow", "1.2.1")]
[Description("Trade market for animal bones")]
class BoneMarket : CovalencePlugin
{
[PluginReference("HumanNPC")]
Plugin HumanNPC, FishR, SkinAndBones;
#region Variables
const string Shop_Perm = "bonemarket.useshop";
const string NPC_Perm = "bonemarket.usenpc";
bool IsReady;
DynamicConfigFile _BonePrices = Interface.Oxide.DataFileSystem.GetDatafile("BoneMarket_Prices");
public float MarketRefreshTime = 7.0f;
Timer RefreshTimer;
int NeededAmount;
int BearBoneValue;
int BoarBoneValue;
int ChickenBoneValue;
int FishBoneValue;
int HorseBoneValue;
int StagBoneValue;
int WolfBoneValue;
string TIDName;
string TItem;
string prefix;
bool UseNPCBool;
string _Font;
string _BoneTXTColor;
#endregion
void OnServerInitialized(bool initial)
{
if (initial)
{
IsReady = false;
CheckInit();
return;
}
IsReady = true;
if (IsReady)
{
SetPrices();
MarketRefreshTimer();
Puts("Server is Ready for Market values");
}
}
#region Configuration
void Init()
{
if (!LoadConfigVariables())
{
Puts("Config file issue detected. Please delete file, or check syntax and fix.");
return;
}
MarketRefreshTime = configData.Refreshtime;
RefreshValues();
TIDName = configData.TradeItemName;
TItem = configData.TradeItem;
UseNPCBool = configData.Npcs.UseNPC;
permission.RegisterPermission(Shop_Perm, this);
permission.RegisterPermission(NPC_Perm, this);
prefix = configData.Prefix;
_Font = configData.UISettings.Font;
_BoneTXTColor = configData.UISettings.BoneItemColor;
}
private ConfigData configData;
class ConfigData
{
[JsonProperty(PropertyName = "Chat Prefix")]
public string Prefix = "[Bone Market] : ";
[JsonProperty(PropertyName = "NPC Vendor settings")]
public NPC Npcs = new NPC();
[JsonProperty(PropertyName = "UI Settings")]
public UISettings UISettings = new UISettings();
[JsonProperty(PropertyName = "Market refresh time (gameday)")]
public float Refreshtime = 7.0f;
[JsonProperty(PropertyName = "Market Trade item (shortname)")]
public string TradeItem = "scrap";
[JsonProperty(PropertyName = "Market Trade item (View name in GUI)")]
public string TradeItemName = "Scrap";
[JsonProperty(PropertyName = "Market Unit Value")]
public Prices Prices = new Prices();
}
class NPC
{
[JsonProperty(PropertyName = "Use NPC shop")]
public bool UseNPC = false;
[JsonProperty(PropertyName = "NPC Id's")]
public List NPCID = new List();
}
class UISettings
{
[JsonProperty(PropertyName = "Font to use")]
public string Font = "permanentmarker.ttf";
[JsonProperty(PropertyName = "Market Title")]
public string Title = "Bone Market";
[JsonProperty(PropertyName = "Market Title Color (RGBA)")]
public string TitleColor = "0.5 1 1 0.90";
[JsonProperty(PropertyName = "Market Description")]
public string Description = "Trade market for hunters\nTrade your Bones right here !!!";
[JsonProperty(PropertyName = "Market Description Color (RGBA)")]
public string DescriptionColor = "1 1 1 0.90";
[JsonProperty(PropertyName = "Bone item text Color (RGBA)")]
public string BoneItemColor = "0.5 1 1 0.90";
[JsonProperty(PropertyName = "Use a background image")]
public bool UseBackgroundImage = true;
[JsonProperty(PropertyName = "Background Image link")]
public string BackgroundImageLink = "https://i.ibb.co/6NQmCgZ/Quail-Bird-Hunting-Silhouette-Free-Vector.jpg";
[JsonProperty(PropertyName = "Background Image transparency (0-1)")]
public float BackgroundImageAlpha = 0.2f;
}
class Prices
{
[JsonProperty(PropertyName = "Bear bones Low value")]
public int BearBonePriceMin = 2;
[JsonProperty(PropertyName = "Bear bones High value")]
public int BearBonePrice = 6;
[JsonProperty(PropertyName = "Boar bones Low value")]
public int BoarBonePriceMin = 1;
[JsonProperty(PropertyName = "Boar bones High value")]
public int BoarBonePrice = 3;
[JsonProperty(PropertyName = "Chicken bones Low value")]
public int ChickenBonePriceMin = 1;
[JsonProperty(PropertyName = "Chicken bones High value")]
public int ChickenBonePrice = 3;
[JsonProperty(PropertyName = "Horse bones Low value")]
public int HorseBonePriceMin = 1;
[JsonProperty(PropertyName = "Horse bones High value")]
public int HorseBonePrice = 3;
[JsonProperty(PropertyName = "Fish bones Low value")]
public int FishBonePriceMin = 1;
[JsonProperty(PropertyName = "Fish bones High value")]
public int FishBonePrice = 3;
[JsonProperty(PropertyName = "Stag bones Low value")]
public int StagBonePriceMin = 1;
[JsonProperty(PropertyName = "Stag bones High value")]
public int StagBonePrice = 3;
[JsonProperty(PropertyName = "Wolf bones Low value")]
public int WolfBonePriceMin = 1;
[JsonProperty(PropertyName = "Wolf bones High value")]
public int WolfBonePrice = 4;
}
private bool LoadConfigVariables()
{
try
{
configData = Config.ReadObject();
}
catch
{
return false;
}
SaveConf();
return true;
}
protected override void LoadDefaultConfig()
{
Puts("Creating new config file.");
configData = new ConfigData();
SaveConf();
}
void SaveConf() => Config.WriteObject(configData, true);
#endregion
#region LanguageAPI
protected override void LoadDefaultMessages()
{
lang.RegisterMessages(new Dictionary
{
["FullInventory"] = "Your inventory was full handout is dropped on the floor",
["FullInventoryUI"] = "Your Inventory is full handout will drop on the floor",
["Info"] = "\n\nAvailable Commands :\n/bone info : Shows info on version/author and commands\n/bone market : Opens the market interface where prices change each gameday",
["InvalidInput"] = "Please enter a valid command!",
["OnlyNPC"] = "The Bone Market is only available at the Bone Trader NPC in Town",
["Succesfulltrade"] = "You traded your bones for {0} {1}",
["MarketReset"] = "Market started a new day with fresh trade prices.",
["NotFound"] = "You dont have any to trade",
["NotEnough"] = "You dont have enough bones for this trade",
}, this);
}
#endregion
#region Commands
[Command("bone")]
private void Bone(IPlayer player, string command, string[] args)
{
if (player.IsServer)
{
return;
}
if (args.Length < 1)
{
player.Message(msg("InvalidInput"));
return;
}
switch (args[0])
{
case "market":
{
if (permission.UserHasPermission(player.Id, Shop_Perm))
{
ASUI(player.Object as BasePlayer);
break;
}
else
{
player.Message(msg("OnlyNPC"));
break;
}
}
case "info":
{
player.Reply(lang.GetMessage("Version : V" + this.Version.ToString() + " By : " + this.Author.ToString()
+ msginfo("Info")
, this, player.Id));
break;
}
default:
player.Reply(msg("InvalidInput"));
break;
}
}
[Command("BoneMarket")]
private void BoneUI(IPlayer player, string command, string[] args)
{
if (permission.UserHasPermission(player.Id, Shop_Perm))
{
ASUI(player.Object as BasePlayer);
}
else
{
player.Message(msg("OnlyNPC"));
}
}
#endregion
#region CUI
void Unload()
{
foreach (BasePlayer player in BasePlayer.activePlayerList)
DestroyMenu(player);
}
void OnPlayerDisconnected(BasePlayer player) => DestroyMenu(player);
void OnPlayerDeath(BasePlayer player, HitInfo info) => DestroyMenu(player);
void DestroyMenu(BasePlayer player) => CuiHelper.DestroyUi(player, "ASUI");
[Command("BMClose")]
private void BMClose(IPlayer player, string command, string[] args)
{
if (player == null)
return;
DestroyMenu(player.Object as BasePlayer);
}
void ASUI(BasePlayer player)
{
DestroyMenu(player);
RefreshValues();
var elements = new CuiElementContainer();
var mainName = elements.Add(new CuiPanel { Image = { Color = $"0.1 0.1 0.1 0.4", Material = "assets/content/ui/uibackgroundblur.mat" }, RectTransform = { AnchorMin = "0.3 0.2", AnchorMax = "0.7 0.8" }, CursorEnabled = true, FadeOut = 0.1f }, "Overlay", "ASUI");
var height = 0.7;
var heightlow = 0.66;
{
if (configData.UISettings.UseBackgroundImage == true)
{
elements.Add(new CuiElement { Parent = "ASUI", Components = { new CuiRawImageComponent { Url = $"{configData.UISettings.BackgroundImageLink}", Color = string.Format($"1 1 1 {configData.UISettings.BackgroundImageAlpha}"), FadeIn = 0f }, new CuiRectTransformComponent { AnchorMin = $"0 0", AnchorMax = $"1 1" } } });
}
elements.Add(new CuiLabel { Text = { Text = $"{configData.UISettings.Title}", Color = $"{configData.UISettings.TitleColor}", FontSize = 16, Font = $"{_Font}", Align = TextAnchor.MiddleCenter }, RectTransform = { AnchorMin = "0 0.90", AnchorMax = "1 1" } }, mainName);
elements.Add(new CuiLabel { Text = { Text = $"{configData.UISettings.Description}", Color = $"{configData.UISettings.DescriptionColor}", FontSize = 14, Font = $"{_Font}", Align = TextAnchor.MiddleCenter }, RectTransform = { AnchorMin = "0 0.75", AnchorMax = "1 1" } }, mainName);
#region top titles
elements.Add(new CuiLabel { Text = { Text = $"Merchandise", Color = "1 1 1 0.90", FontSize = 12, Font = $"{_Font}", Align = TextAnchor.MiddleCenter }, RectTransform = { AnchorMin = $"0.0 0.66", AnchorMax = $"0.2 0.7" } }, mainName);
elements.Add(new CuiLabel { Text = { Text = $"Trade Units", Color = "1 1 1 0.90", FontSize = 12, Font = $"{_Font}", Align = TextAnchor.MiddleCenter }, RectTransform = { AnchorMin = $"0.205 0.66", AnchorMax = $"0.80 0.7" } }, mainName);
elements.Add(new CuiLabel { Text = { Text = $"Unit value (10)", Color = "1 1 1 0.90", FontSize = 12, Font = $"{_Font}", Align = TextAnchor.MiddleCenter }, RectTransform = { AnchorMin = $"0.805 0.66", AnchorMax = $"0.995 0.7" } }, mainName);
#endregion
#region Bear Bones
height -= 00.05;
heightlow -= 0.05;
elements.Add(new CuiLabel { Text = { Text = $"Bear Bones", Color = $"{_BoneTXTColor}", FontSize = 12, Font = $"{_Font}", Align = TextAnchor.MiddleCenter }, RectTransform = { AnchorMin = $"0.0 {heightlow}", AnchorMax = $"0.2 {height}" } }, mainName);
elements.Add(new CuiButton { Button = { Command = "TBearB10", Color = "0 0 0 0.80" }, RectTransform = { AnchorMin = $"0.205 {heightlow}", AnchorMax = $"0.40 {height}" }, Text = { Text = "10", FontSize = 12, Font = $"{_Font}", Align = TextAnchor.MiddleCenter } }, mainName);
elements.Add(new CuiButton { Button = { Command = "TBearB100", Color = "0 0 0 0.80" }, RectTransform = { AnchorMin = $"0.405 {heightlow}", AnchorMax = $"0.60 {height}" }, Text = { Text = "100", FontSize = 12, Font = $"{_Font}", Align = TextAnchor.MiddleCenter } }, mainName);
elements.Add(new CuiButton { Button = { Command = "TBearB1000", Color = "0 0 0 0.80" }, RectTransform = { AnchorMin = $"0.605 {heightlow}", AnchorMax = $"0.80 {height}" }, Text = { Text = "1000", FontSize = 12, Font = $"{_Font}", Align = TextAnchor.MiddleCenter } }, mainName);
elements.Add(new CuiLabel { Text = { Text = $"{_BonePrices["BearBonePrice"]} {TIDName}", Color = "1 1 1 0.90", FontSize = 12, Font = $"{_Font}", Align = TextAnchor.MiddleCenter }, RectTransform = { AnchorMin = $"0.805 {heightlow}", AnchorMax = $"0.995 {height}" } }, mainName);
#endregion
#region Boar Bones
height -= 00.05;
heightlow -= 0.05;
elements.Add(new CuiLabel { Text = { Text = $"Boar Bones", Color = $"{_BoneTXTColor}", FontSize = 12, Font = $"{_Font}", Align = TextAnchor.MiddleCenter }, RectTransform = { AnchorMin = $"0.0 {heightlow}", AnchorMax = $"0.2 {height}" } }, mainName);
elements.Add(new CuiButton { Button = { Command = "TBoarB10" +
"", Color = "0 0 0 0.80" }, RectTransform = { AnchorMin = $"0.205 {heightlow}", AnchorMax = $"0.40 {height}" }, Text = { Text = "10", FontSize = 12, Font = $"{_Font}", Align = TextAnchor.MiddleCenter } }, mainName);
elements.Add(new CuiButton { Button = { Command = "TBoarB100", Color = "0 0 0 0.80" }, RectTransform = { AnchorMin = $"0.405 {heightlow}", AnchorMax = $"0.60 {height}" }, Text = { Text = "100", FontSize = 12, Font = $"{_Font}", Align = TextAnchor.MiddleCenter } }, mainName);
elements.Add(new CuiButton { Button = { Command = "TBoarB1000", Color = "0 0 0 0.80" }, RectTransform = { AnchorMin = $"0.605 {heightlow}", AnchorMax = $"0.80 {height}" }, Text = { Text = "1000", FontSize = 12, Font = $"{_Font}", Align = TextAnchor.MiddleCenter } }, mainName);
elements.Add(new CuiLabel { Text = { Text = $"{_BonePrices["BoarBonePrice"]} {TIDName}", Color = "1 1 1 0.90", FontSize = 12, Font = $"{_Font}", Align = TextAnchor.MiddleCenter }, RectTransform = { AnchorMin = $"0.805 {heightlow}", AnchorMax = $"0.995 {height}" } }, mainName);
#endregion
#region Chicken Bones
height -= 00.05;
heightlow -= 0.05;
elements.Add(new CuiLabel { Text = { Text = $"Chicken Bones", Color = $"{_BoneTXTColor}", FontSize = 12, Font = $"{_Font}", Align = TextAnchor.MiddleCenter }, RectTransform = { AnchorMin = $"0.0 {heightlow}", AnchorMax = $"0.2 {height}" } }, mainName);
elements.Add(new CuiButton { Button = { Command = "TChickenB10", Color = "0 0 0 0.80" }, RectTransform = { AnchorMin = $"0.205 {heightlow}", AnchorMax = $"0.40 {height}" }, Text = { Text = "10", FontSize = 12, Font = $"{_Font}", Align = TextAnchor.MiddleCenter } }, mainName);
elements.Add(new CuiButton { Button = { Command = "TChickenB100", Color = "0 0 0 0.80" }, RectTransform = { AnchorMin = $"0.405 {heightlow}", AnchorMax = $"0.60 {height}" }, Text = { Text = "100", FontSize = 12, Font = $"{_Font}", Align = TextAnchor.MiddleCenter } }, mainName);
elements.Add(new CuiButton { Button = { Command = "TChickenB1000", Color = "0 0 0 0.80" }, RectTransform = { AnchorMin = $"0.605 {heightlow}", AnchorMax = $"0.80 {height}" }, Text = { Text = "1000", FontSize = 12, Font = $"{_Font}", Align = TextAnchor.MiddleCenter } }, mainName);
elements.Add(new CuiLabel { Text = { Text = $"{_BonePrices["ChickenBonePrice"]} {TIDName}", Color = "1 1 1 0.90", FontSize = 12, Font = $"{_Font}", Align = TextAnchor.MiddleCenter }, RectTransform = { AnchorMin = $"0.805 {heightlow}", AnchorMax = $"0.995 {height}" } }, mainName);
#endregion
#region Fish Bones
height -= 00.05;
heightlow -= 0.05;
elements.Add(new CuiLabel { Text = { Text = $"Fish Bones", Color = $"{_BoneTXTColor}", FontSize = 12, Font = $"{_Font}", Align = TextAnchor.MiddleCenter }, RectTransform = { AnchorMin = $"0.0 {heightlow}", AnchorMax = $"0.2 {height}" } }, mainName);
elements.Add(new CuiButton { Button = { Command = "TFishB10", Color = "0 0 0 0.80" }, RectTransform = { AnchorMin = $"0.205 {heightlow}", AnchorMax = $"0.40 {height}" }, Text = { Text = "10", FontSize = 12, Font = $"{_Font}", Align = TextAnchor.MiddleCenter } }, mainName);
elements.Add(new CuiButton { Button = { Command = "TFishB100", Color = "0 0 0 0.80" }, RectTransform = { AnchorMin = $"0.405 {heightlow}", AnchorMax = $"0.60 {height}" }, Text = { Text = "100", FontSize = 12, Font = $"{_Font}", Align = TextAnchor.MiddleCenter } }, mainName);
elements.Add(new CuiButton { Button = { Command = "TFishB1000", Color = "0 0 0 0.80" }, RectTransform = { AnchorMin = $"0.605 {heightlow}", AnchorMax = $"0.80 {height}" }, Text = { Text = "1000", FontSize = 12, Font = $"{_Font}", Align = TextAnchor.MiddleCenter } }, mainName);
elements.Add(new CuiLabel { Text = { Text = $"{_BonePrices["FishBonePrice"]} {TIDName}", Color = "1 1 1 0.90", FontSize = 12, Font = $"{_Font}", Align = TextAnchor.MiddleCenter }, RectTransform = { AnchorMin = $"0.805 {heightlow}", AnchorMax = $"0.995 {height}" } }, mainName);
#endregion
#region Horse Bones
height -= 00.05;
heightlow -= 0.05;
elements.Add(new CuiLabel { Text = { Text = $"Horse Bones", Color = $"{_BoneTXTColor}", FontSize = 12, Font = $"{_Font}", Align = TextAnchor.MiddleCenter }, RectTransform = { AnchorMin = $"0.0 {heightlow}", AnchorMax = $"0.2 {height}" } }, mainName);
elements.Add(new CuiButton { Button = { Command = "THorseB10", Color = "0 0 0 0.80" }, RectTransform = { AnchorMin = $"0.205 {heightlow}", AnchorMax = $"0.40 {height}" }, Text = { Text = "10", FontSize = 12, Font = $"{_Font}", Align = TextAnchor.MiddleCenter } }, mainName);
elements.Add(new CuiButton { Button = { Command = "THorseB100", Color = "0 0 0 0.80" }, RectTransform = { AnchorMin = $"0.405 {heightlow}", AnchorMax = $"0.60 {height}" }, Text = { Text = "100", FontSize = 12, Font = $"{_Font}", Align = TextAnchor.MiddleCenter } }, mainName);
elements.Add(new CuiButton { Button = { Command = "THorseB1000", Color = "0 0 0 0.80" }, RectTransform = { AnchorMin = $"0.605 {heightlow}", AnchorMax = $"0.80 {height}" }, Text = { Text = "1000", FontSize = 12, Font = $"{_Font}", Align = TextAnchor.MiddleCenter } }, mainName);
elements.Add(new CuiLabel { Text = { Text = $"{_BonePrices["HorseBonePrice"]} {TIDName}", Color = "1 1 1 0.90", FontSize = 12, Font = $"{_Font}", Align = TextAnchor.MiddleCenter }, RectTransform = { AnchorMin = $"0.805 {heightlow}", AnchorMax = $"0.995 {height}" } }, mainName);
#endregion
#region Stag Bones
height -= 00.05;
heightlow -= 0.05;
elements.Add(new CuiLabel { Text = { Text = $"Stag Bones", Color = $"{_BoneTXTColor}", FontSize = 12, Font = $"{_Font}", Align = TextAnchor.MiddleCenter }, RectTransform = { AnchorMin = $"0.0 {heightlow}", AnchorMax = $"0.2 {height}" } }, mainName);
elements.Add(new CuiButton { Button = { Command = "TStagB10", Color = "0 0 0 0.80" }, RectTransform = { AnchorMin = $"0.205 {heightlow}", AnchorMax = $"0.40 {height}" }, Text = { Text = "10", FontSize = 12, Font = $"{_Font}", Align = TextAnchor.MiddleCenter } }, mainName);
elements.Add(new CuiButton { Button = { Command = "TStagB100", Color = "0 0 0 0.80" }, RectTransform = { AnchorMin = $"0.405 {heightlow}", AnchorMax = $"0.60 {height}" }, Text = { Text = "100", FontSize = 12, Font = $"{_Font}", Align = TextAnchor.MiddleCenter } }, mainName);
elements.Add(new CuiButton { Button = { Command = "TStagB1000", Color = "0 0 0 0.80" }, RectTransform = { AnchorMin = $"0.605 {heightlow}", AnchorMax = $"0.80 {height}" }, Text = { Text = "1000", FontSize = 12, Font = $"{_Font}", Align = TextAnchor.MiddleCenter } }, mainName);
elements.Add(new CuiLabel { Text = { Text = $"{_BonePrices["StagBonePrice"]} {TIDName}", Color = "1 1 1 0.90", FontSize = 12, Font = $"{_Font}", Align = TextAnchor.MiddleCenter }, RectTransform = { AnchorMin = $"0.805 {heightlow}", AnchorMax = $"0.995 {height}" } }, mainName);
#endregion
#region Wolf Bones
height -= 00.05;
heightlow -= 0.05;
elements.Add(new CuiLabel { Text = { Text = $"Wolf Bones", Color = $"{_BoneTXTColor}", FontSize = 12, Font = $"{_Font}", Align = TextAnchor.MiddleCenter }, RectTransform = { AnchorMin = $"0.0 {heightlow}", AnchorMax = $"0.2 {height}" } }, mainName);
elements.Add(new CuiButton { Button = { Command = "TWolfB10", Color = "0 0 0 0.80" }, RectTransform = { AnchorMin = $"0.205 {heightlow}", AnchorMax = $"0.40 {height}" }, Text = { Text = "10", FontSize = 12, Font = $"{_Font}", Align = TextAnchor.MiddleCenter } }, mainName);
elements.Add(new CuiButton { Button = { Command = "TWolfB100", Color = "0 0 0 0.80" }, RectTransform = { AnchorMin = $"0.405 {heightlow}", AnchorMax = $"0.60 {height}" }, Text = { Text = "100", FontSize = 12, Font = $"{_Font}", Align = TextAnchor.MiddleCenter } }, mainName);
elements.Add(new CuiButton { Button = { Command = "TWolfB1000", Color = "0 0 0 0.80" }, RectTransform = { AnchorMin = $"0.605 {heightlow}", AnchorMax = $"0.80 {height}" }, Text = { Text = "1000", FontSize = 12, Font = $"{_Font}", Align = TextAnchor.MiddleCenter } }, mainName);
elements.Add(new CuiLabel { Text = { Text = $"{_BonePrices["WolfBonePrice"]} {TIDName}", Color = "1 1 1 0.90", FontSize = 12, Font = $"{_Font}", Align = TextAnchor.MiddleCenter }, RectTransform = { AnchorMin = $"0.805 {heightlow}", AnchorMax = $"0.995 {height}" } }, mainName);
#endregion
#region Full Inventory
if (player.inventory.containerMain.IsFull())
{
elements.Add(new CuiLabel { Text = { Text = msg("FullInventoryUI"), Color = $"1 1 1 0.90", FontSize = 14, Font = $"{_Font}", Align = TextAnchor.MiddleCenter }, RectTransform = { AnchorMin = "0.0 0.15", AnchorMax = "1.0 0.2" } }, mainName);
}
#endregion
elements.Add(new CuiLabel { Text = { Text = $"{this.Name.ToString()} V{this.Version.ToString()} by Krungh Crow", Color = $"1 1 1 0.90", FontSize = 11, Font = $"{_Font}", Align = TextAnchor.MiddleRight }, RectTransform = { AnchorMin = "0.60 0.0", AnchorMax = "0.99 0.05" } }, mainName);
}
elements.Add(new CuiButton { Button = { Command = "BMClose", Color = "0 0 0 0.80" }, RectTransform = { AnchorMin = "0.90 0.95", AnchorMax = "0.995 0.995" }, Text = { Text = "close", FontSize = 15, Font = $"{_Font}", Align = TextAnchor.MiddleCenter } }, mainName);
CuiHelper.AddUi(player, elements);
}
#endregion
#region Hooks
void CheckInit()//checks if server is fully initialised
{
timer.Once(10f, () =>
{
if (Rust.Application.isLoading)
{
Puts($"[Debugging] Server still loading....");
CheckInit();
return;
}
IsReady = true;
Puts("Server is Ready for Market values.....");
});
}
void OnServerSave()
{
if (server != null && server.Time != null && RefreshTimer != null && server.Time.TimeOfDay.Hours != MarketRefreshTime)
{
RefreshTimer.Destroy();
MarketRefreshTimer();
Puts("Market refresh Check....");
return;
}
}
void OnUseNPC(BasePlayer npc, BasePlayer player, Vector3 destination)
{
if (configData.Npcs.NPCID != null && configData.Npcs.NPCID.Contains(npc.UserIDString) && UseNPCBool)
{
if (permission.UserHasPermission(player.UserIDString, NPC_Perm))
{
ASUI(player);
}
}
}
#endregion
#region Trades
private void TradeTheItem(IPlayer player , int takeamount , Item item , int returnvalue)
{
RefreshValues();
BasePlayer plyr = player.Object as BasePlayer;
var amount = returnvalue.ToString();
item.UseItem(takeamount);
Item TradeItem = ItemManager.CreateByName($"{TItem}" , returnvalue , 0);
if (plyr.inventory.containerMain.IsFull())
{
TradeItem.DropAndTossUpwards(plyr.transform.position);
Puts(amount);
player.Message(msg("FullInventory"));
return;
}
player.Message(msg("Succesfulltrade").Replace("{0}" , amount).Replace("{1}" , TItem));
plyr.inventory.GiveItem(TradeItem);
return;
}
#region Bear Bone Trade
[Command("TBearB10")]
private void TBearB10(IPlayer player, string command, string[] args)
{
NeededAmount = 10;
BasePlayer plyr = player.Object as BasePlayer;
foreach (var item in GetAllItems(plyr))
if (IsBearBone(item))
{
if (item.amount < NeededAmount && item != null)
{
player.Message(msg("NotEnough"));
return;
}
TradeTheItem(player , NeededAmount, item ,BearBoneValue);
return;
}
player.Message(msg($"NotFound"));
return;
}
[Command("TBearB100")]
private void TBearB100(IPlayer player, string command, string[] args)
{
NeededAmount = 100;
BasePlayer plyr = player.Object as BasePlayer;
foreach (var item in GetAllItems(plyr))
if (IsBearBone(item))
{
if (item.amount < NeededAmount && item != null)
{
player.Message(msg("NotEnough"));
return;
}
TradeTheItem(player, NeededAmount, item, BearBoneValue * 10);
return;
}
player.Message(msg($"NotFound"));
return;
}
[Command("TBearB1000")]
private void TBearB1000(IPlayer player, string command, string[] args)
{
NeededAmount = 1000;
BasePlayer plyr = player.Object as BasePlayer;
foreach (var item in GetAllItems(plyr))
if (IsBearBone(item))
{
if (item.amount < NeededAmount && item != null)
{
player.Message(msg("NotEnough"));
return;
}
TradeTheItem(player, NeededAmount, item, BearBoneValue * 100);
return;
}
player.Message(msg($"NotFound"));
return;
}
#endregion
#region Boar Bone Trade
[Command("TBoarB10")]
private void TBoarB10(IPlayer player, string command, string[] args)
{
NeededAmount = 10;
BasePlayer plyr = player.Object as BasePlayer;
foreach (var item in GetAllItems(plyr))
if (IsBoarBone(item))
{
if (item.amount < NeededAmount && item != null)
{
player.Message(msg("NotEnough"));
return;
}
TradeTheItem(player, NeededAmount, item, BoarBoneValue);
return;
}
player.Message(msg($"NotFound"));
return;
}
[Command("TBoarB100")]
private void TBoarB100(IPlayer player, string command, string[] args)
{
NeededAmount = 100;
BasePlayer plyr = player.Object as BasePlayer;
foreach (var item in GetAllItems(plyr))
if (IsBoarBone(item))
{
if (item.amount < NeededAmount && item != null)
{
player.Message(msg("NotEnough"));
return;
}
TradeTheItem(player, NeededAmount, item, BoarBoneValue * 10);
return;
}
player.Message(msg($"NotFound"));
return;
}
[Command("TBoarB1000")]
private void TBoarB1000(IPlayer player, string command, string[] args)
{
NeededAmount = 1000;
BasePlayer plyr = player.Object as BasePlayer;
foreach (var item in GetAllItems(plyr))
if (IsBoarBone(item))
{
if (item.amount < NeededAmount && item != null)
{
player.Message(msg("NotEnough"));
return;
}
TradeTheItem(player, NeededAmount, item, BoarBoneValue * 100);
return;
}
player.Message(msg($"NotFound"));
return;
}
#endregion
#region Chicken Bone Trade
[Command("TChickenB10")]
private void TChickenB10(IPlayer player, string command, string[] args)
{
NeededAmount = 10;
BasePlayer plyr = player.Object as BasePlayer;
foreach (var item in GetAllItems(plyr))
if (IsChickenBone(item))
{
if (item.amount < NeededAmount && item != null)
{
player.Message(msg("NotEnough"));
return;
}
TradeTheItem(player, NeededAmount, item, ChickenBoneValue);
return;
}
player.Message(msg($"NotFound"));
return;
}
[Command("TChickenB100")]
private void TChickenB100(IPlayer player, string command, string[] args)
{
NeededAmount = 100;
BasePlayer plyr = player.Object as BasePlayer;
foreach (var item in GetAllItems(plyr))
if (IsChickenBone(item))
{
if (item.amount < NeededAmount && item != null)
{
player.Message(msg("NotEnough"));
return;
}
TradeTheItem(player, NeededAmount, item, ChickenBoneValue * 10);
return;
}
player.Message(msg($"NotFound"));
return;
}
[Command("TChickenB1000")]
private void TChickenB1000(IPlayer player, string command, string[] args)
{
NeededAmount = 1000;
BasePlayer plyr = player.Object as BasePlayer;
foreach (var item in GetAllItems(plyr))
if (IsChickenBone(item))
{
if (item.amount < NeededAmount && item != null)
{
player.Message(msg("NotEnough"));
return;
}
TradeTheItem(player, NeededAmount, item, ChickenBoneValue * 100);
return;
}
player.Message(msg($"NotFound"));
return;
}
#endregion
#region Fish Bone Trade
[Command("TFishB10")]
private void TFishB10(IPlayer player, string command, string[] args)
{
NeededAmount = 10;
BasePlayer plyr = player.Object as BasePlayer;
foreach (var item in GetAllItems(plyr))
if (IsFishBone(item))
{
if (item.amount < NeededAmount && item != null)
{
player.Message(msg("NotEnough"));
return;
}
TradeTheItem(player, NeededAmount, item, FishBoneValue);
return;
}
player.Message(msg($"NotFound"));
return;
}
[Command("TFishB100")]
private void TFishB100(IPlayer player, string command, string[] args)
{
NeededAmount = 100;
BasePlayer plyr = player.Object as BasePlayer;
foreach (var item in GetAllItems(plyr))
if (IsFishBone(item))
{
if (item.amount < NeededAmount && item != null)
{
player.Message(msg("NotEnough"));
return;
}
TradeTheItem(player, NeededAmount, item, FishBoneValue * 10);
return;
}
player.Message(msg($"NotFound"));
return;
}
[Command("TFishB1000")]
private void TFishB1000(IPlayer player, string command, string[] args)
{
NeededAmount = 1000;
BasePlayer plyr = player.Object as BasePlayer;
foreach (var item in GetAllItems(plyr))
if (IsFishBone(item))
{
if (item.amount < NeededAmount && item != null)
{
player.Message(msg("NotEnough"));
return;
}
TradeTheItem(player, NeededAmount, item, FishBoneValue * 100);
return;
}
player.Message(msg($"NotFound"));
return;
}
#endregion
#region Horse Bone Trade
[Command("THorseB10")]
private void THorseB10(IPlayer player, string command, string[] args)
{
NeededAmount = 10;
BasePlayer plyr = player.Object as BasePlayer;
foreach (var item in GetAllItems(plyr))
if (IsHorseBone(item))
{
if (item.amount < NeededAmount && item != null)
{
player.Message(msg("NotEnough"));
return;
}
TradeTheItem(player, NeededAmount, item, HorseBoneValue);
return;
}
player.Message(msg($"NotFound"));
return;
}
[Command("THorseB100")]
private void THorseB100(IPlayer player, string command, string[] args)
{
NeededAmount = 100;
BasePlayer plyr = player.Object as BasePlayer;
foreach (var item in GetAllItems(plyr))
if (IsHorseBone(item))
{
if (item.amount < NeededAmount && item != null)
{
player.Message(msg("NotEnough"));
return;
}
TradeTheItem(player, NeededAmount, item, HorseBoneValue * 10);
return;
}
player.Message(msg($"NotFound"));
return;
}
[Command("THorseB1000")]
private void THorseB1000(IPlayer player, string command, string[] args)
{
NeededAmount = 1000;
BasePlayer plyr = player.Object as BasePlayer;
foreach (var item in GetAllItems(plyr))
if (IsHorseBone(item))
{
if (item.amount < NeededAmount && item != null)
{
player.Message(msg("NotEnough"));
return;
}
TradeTheItem(player, NeededAmount, item, HorseBoneValue * 100);
return;
}
player.Message(msg($"NotFound"));
return;
}
#endregion
#region Stag Bone Trade
[Command("TStagB10")]
private void TStagB10(IPlayer player, string command, string[] args)
{
NeededAmount = 10;
BasePlayer plyr = player.Object as BasePlayer;
foreach (var item in GetAllItems(plyr))
if (IsStagBone(item))
{
if (item.amount < NeededAmount && item != null)
{
player.Message(msg("NotEnough"));
return;
}
TradeTheItem(player, NeededAmount, item, StagBoneValue);
return;
}
player.Message(msg($"NotFound"));
return;
}
[Command("TStagB100")]
private void TStagB100(IPlayer player, string command, string[] args)
{
NeededAmount = 100;
BasePlayer plyr = player.Object as BasePlayer;
foreach (var item in GetAllItems(plyr))
if (IsStagBone(item))
{
if (item.amount < NeededAmount && item != null)
{
player.Message(msg("NotEnough"));
return;
}
TradeTheItem(player, NeededAmount, item, StagBoneValue * 10);
return;
}
player.Message(msg($"NotFound"));
return;
}
[Command("TStagB1000")]
private void TStagB1000(IPlayer player, string command, string[] args)
{
NeededAmount = 1000;
BasePlayer plyr = player.Object as BasePlayer;
foreach (var item in GetAllItems(plyr))
if (IsStagBone(item))
{
if (item.amount < NeededAmount && item != null)
{
player.Message(msg("NotEnough"));
return;
}
TradeTheItem(player, NeededAmount, item, StagBoneValue * 100);
return;
}
player.Message(msg($"NotFound"));
return;
}
#endregion
#region Wolf Bone Trade
[Command("TWolfB10")]
private void TWolfB10(IPlayer player, string command, string[] args)
{
NeededAmount = 10;
BasePlayer plyr = player.Object as BasePlayer;
foreach (var item in GetAllItems(plyr))
if (IsWolfBone(item))
{
if (item.amount < NeededAmount && item != null)
{
player.Message(msg("NotEnough"));
return;
}
TradeTheItem(player, NeededAmount, item, WolfBoneValue);
return;
}
player.Message(msg($"NotFound"));
return;
}
[Command("TWolfB100")]
private void TWolfB100(IPlayer player, string command, string[] args)
{
NeededAmount = 100;
BasePlayer plyr = player.Object as BasePlayer;
foreach (var item in GetAllItems(plyr))
if (IsWolfBone(item))
{
if (item.amount < NeededAmount && item != null)
{
player.Message(msg("NotEnough"));
return;
}
TradeTheItem(player, NeededAmount, item, WolfBoneValue * 10);
return;
}
player.Message(msg($"NotFound"));
return;
}
[Command("TWolfB1000")]
private void TWolfB1000(IPlayer player, string command, string[] args)
{
NeededAmount = 1000;
BasePlayer plyr = player.Object as BasePlayer;
foreach (var item in GetAllItems(plyr))
if (IsWolfBone(item))
{
if (item.amount < NeededAmount && item != null)
{
player.Message(msg("NotEnough"));
return;
}
TradeTheItem(player, NeededAmount, item, WolfBoneValue * 100);
return;
}
player.Message(msg($"NotFound"));
return;
}
private IEnumerable- GetAllItems(BasePlayer player)
{
return player.inventory.containerMain.itemList
.Concat(player.inventory.containerBelt.itemList)
.Concat(player.inventory.containerWear.itemList);
}
#endregion
#endregion
#region Core
private void RefreshValues()
{
BearBoneValue = Convert.ToInt32(_BonePrices["BearBonePrice"]);
BoarBoneValue = Convert.ToInt32(_BonePrices["BoarBonePrice"]);
ChickenBoneValue = Convert.ToInt32(_BonePrices["ChickenBonePrice"]);
FishBoneValue = Convert.ToInt32(_BonePrices["FishBonePrice"]);
HorseBoneValue = Convert.ToInt32(_BonePrices["HorseBonePrice"]);
StagBoneValue = Convert.ToInt32(_BonePrices["StagBonePrice"]);
WolfBoneValue = Convert.ToInt32(_BonePrices["WolfBonePrice"]);
}
private void SetPrices()
{
_BonePrices["BearBonePrice"] = UnityEngine.Random.Range(configData.Prices.BearBonePriceMin, configData.Prices.BearBonePrice);
_BonePrices["BoarBonePrice"] = UnityEngine.Random.Range(configData.Prices.BoarBonePriceMin, configData.Prices.BoarBonePrice);
_BonePrices["ChickenBonePrice"] = UnityEngine.Random.Range(configData.Prices.ChickenBonePriceMin, configData.Prices.ChickenBonePrice);
_BonePrices["FishBonePrice"] = UnityEngine.Random.Range(configData.Prices.FishBonePriceMin, configData.Prices.FishBonePrice);
_BonePrices["HorseBonePrice"] = UnityEngine.Random.Range(configData.Prices.HorseBonePriceMin, configData.Prices.HorseBonePrice);
_BonePrices["StagBonePrice"] = UnityEngine.Random.Range(configData.Prices.StagBonePriceMin, configData.Prices.StagBonePrice);
_BonePrices["WolfBonePrice"] = UnityEngine.Random.Range(configData.Prices.WolfBonePriceMin, configData.Prices.WolfBonePrice);
_BonePrices.Save();
}
private void MarketRefreshTimer()
{
if (server != null && server.Time != null && server.Time.TimeOfDay != null)
{
RefreshTimer = timer.Repeat(1f , 0 , () =>
{
if (server.Time.TimeOfDay.Hours == MarketRefreshTime)
{
RefreshTimer.Destroy();
server.Broadcast(msg("MarketReset"));
foreach (var player in players.Connected)
{
DestroyMenu(player.Object as BasePlayer);
}
}
});
}
}
#endregion
#region API
private bool IsBearBone(Item item)
{
if (item.name == ("Bear Bones") || item.skin == (2582006231)) return true;
return false;
}
private bool IsBoarBone(Item item)
{
if (item.name == ("Boar Bones") || item.skin == (2582018117)) return true;
return false;
}
private bool IsChickenBone(Item item)
{
if (item.name == ("Chicken Bones") || item.skin == (2582002045)) return true;
return false;
}
private bool IsFishBone(Item item)
{
if (item.name == ("Fish Bones") || item.skin == (2583801321)) return true;
return false;
}
private bool IsHorseBone(Item item)
{
if (item.name == ("Horse Bones") || item.skin == (2582022311)) return true;
return false;
}
private bool IsStagBone(Item item)
{
if (item.name == ("Stag Bones") || item.skin == (2582020463)) return true;
return false;
}
private bool IsWolfBone(Item item)
{
if (item.name == ("Wolf Bones") || item.skin == (2582021640)) return true;
return false;
}
#endregion
#region Message helper
private string msg(string key, string id = null) => prefix + lang.GetMessage(key, this, id);
private string msginfo(string key, string id = null) => lang.GetMessage(key, this, id);
#endregion
}
}