this doesn't work with the default config. It seems pretty messy, can you clean it up and make it all work with the default config that loads?
GUI Shop
GUI Shop based on Economics. Supports NPC
Total Downloads: 11,479 - First Release: Aug 29, 2015 - Last Update: May 3, 2018
- 5/5, 38 likes
-
Code:private static CuiElementContainer CreateShopOverlay(string shopname) { return new CuiElementContainer { { new CuiPanel { Image = {Color = "0.1 0.1 0.1 0.8"}, RectTransform = {AnchorMin = "0 0", AnchorMax = "1 1"}, CursorEnabled = true }, new CuiElement().Parent, ShopOverlayName }, { new CuiLabel { Text = {Text = shopname, FontSize = 30, Align = TextAnchor.MiddleCenter}, RectTransform = {AnchorMin = "0.3 0.85", AnchorMax = "0.7 0.95"} }, ShopOverlayName }, { new CuiLabel { Text = {Text = "Item", FontSize = 20, Align = TextAnchor.MiddleLeft}, RectTransform = {AnchorMin = "0.2 0.73", AnchorMax = "0.4 0.77"} }, ShopOverlayName }, { new CuiLabel { Text = {Text = "Buy", FontSize = 20, Align = TextAnchor.MiddleLeft}, RectTransform = {AnchorMin = "0.55 0.73", AnchorMax = "0.7 0.77"} }, ShopOverlayName }, { new CuiLabel { Text = {Text = "Sell", FontSize = 20, Align = TextAnchor.MiddleLeft}, RectTransform = {AnchorMin = "0.80 0.73", AnchorMax = "0.95 0.77"} }, ShopOverlayName }, { new CuiButton { Button = {Close = ShopOverlayName, Color = "0.5 0.5 0.5 0.2"}, RectTransform = {AnchorMin = "0.55 0.12", AnchorMax = "0.7 0.17"}, Text = {Text = "Close", FontSize = 20, Align = TextAnchor.MiddleCenter} }, ShopOverlayName } }; } private readonly CuiLabel shopDescription = new CuiLabel { Text = { Text = "{shopdescription}", FontSize = 15, Align = TextAnchor.MiddleCenter }, RectTransform = { AnchorMin = "0.2 0.83", AnchorMax = "0.8 0.88" } }; private CuiElementContainer CreateShopItemEntry(string price, float ymax, float ymin, string shop, string item, string color, bool sell, bool cooldown) { var container = new CuiElementContainer { { new CuiLabel { Text = {Text = price, FontSize = 15, Align = TextAnchor.MiddleLeft}, RectTransform = {AnchorMin = $"{(sell ? 0.725 : 0.45)} {ymin}", AnchorMax = $"{(sell ? 0.755 : 0.5)} {ymax}"} }, ShopContentName } }; for (var i = 0; i < steps.Length; i++) { container.Add(new CuiButton { Button = {Command = $"shop.{(sell ? "sell" : "buy")} {shop} {item} {steps[i]}", Color = color}, RectTransform = {AnchorMin = $"{(sell ? 0.775 : 0.5) + i*0.03 + 0.001} {ymin}", AnchorMax = $"{(sell ? 0.805 : 0.53) + i*0.03 - 0.001} {ymax}"}, Text = {Text = steps[i].ToString(), FontSize = 15, Align = TextAnchor.MiddleCenter} }, ShopContentName); //if (cooldown) break; } if (!cooldown) { container.Add(new CuiButton { Button = { Command = $"shop.{(sell ? "sell" : "buy")} {shop} {item} all", Color = color }, RectTransform = { AnchorMin = $"{(sell ? 0.775 : 0.5) + steps.Length * 0.03 + 0.001} {ymin}", AnchorMax = $"{(sell ? 0.805 : 0.53) + steps.Length * 0.03 - 0.001} {ymax}" }, Text = { Text = "All", FontSize = 15, Align = TextAnchor.MiddleCenter } }, ShopContentName); } return container; } private CuiElementContainer CreateShopItemIcon(string name, float ymax, float ymin, ItemData data) { string url = null; if (!string.IsNullOrEmpty(data.Img)) url = data.Img; else if (!string.IsNullOrEmpty(data.Shortname)) url = string.Format(IconUrl, data.Shortname); var label = new CuiLabel { Text = { Text = name, FontSize = 15, Align = TextAnchor.MiddleLeft }, RectTransform = { AnchorMin = $"0.18 {ymin}", AnchorMax = $"0.3 {ymax}" } }; if (string.IsNullOrEmpty(url)) return new CuiElementContainer { { label, ShopContentName } }; var rawImage = new CuiRawImageComponent(); if (url.StartsWith("http") || url.StartsWith("file")) { var id = (string)ImageCache?.CallHook("Get", url); if (!string.IsNullOrEmpty(id)) rawImage.Png = id; else rawImage.Url = url; rawImage.Sprite = "assets/content/textures/generic/fulltransparent.tga"; } else rawImage.Sprite = url; var container = new CuiElementContainer { { label, ShopContentName }, new CuiElement { Parent = ShopContentName, Components = { rawImage, new CuiRectTransformComponent {AnchorMin = $"0.14 {ymin}", AnchorMax = $"0.17 {ymax}"} } } }; return container; } private static CuiElementContainer CreateShopChangePage(string currentshop, int shoppageminus, int shoppageplus) { return new CuiElementContainer { { new CuiButton { Button = {Command = $"shop.show {currentshop} {shoppageminus}", Color = "0.5 0.5 0.5 0.2"}, RectTransform = {AnchorMin = "0.2 0.12", AnchorMax = "0.3 0.17"}, Text = {Text = "<<", FontSize = 20, Align = TextAnchor.MiddleCenter} }, ShopOverlayName, "ButtonBack" }, { new CuiButton { Button = {Command = $"shop.show {currentshop} {shoppageplus}", Color = "0.5 0.5 0.5 0.2"}, RectTransform = {AnchorMin = "0.35 0.12", AnchorMax = "0.45 0.17"}, Text = {Text = ">>", FontSize = 20, Align = TextAnchor.MiddleCenter} }, ShopOverlayName, "ButtonForward" } }; } readonly Hash<ulong, int> shopPage = new Hash<ulong, int>(); private Dictionary<ulong, Dictionary<string, double>> cooldowns; private Dictionary<string, ulong> buyed; private Dictionary<string, ulong> selled; private bool configChanged; void ShowShop(BasePlayer player, string shopid, int from = 0, bool fullPaint = true, bool refreshMoney = false) { shopPage[player.userID] = from; object shopObj; if (!Shops.TryGetValue(shopid, out shopObj)) { SendReply(player, MessageErrorNoShop); return; } if (Economics == null) { SendReply(player, MessageShowNoEconomics); return; } var playerCoins = (double) Economics.CallHook("GetPlayerMoney", player.userID); var shop = (Dictionary<string, object>) shopObj; shopDescription.Text.Text = string.Format((string) shop["description"], playerCoins); if (refreshMoney) { CuiHelper.DestroyUi(player, ShopDescOverlay); CuiHelper.AddUi(player, new CuiElementContainer { { shopDescription, ShopOverlayName, ShopDescOverlay } }); return; } DestroyUi(player, fullPaint); CuiElementContainer container; if (fullPaint) { container = CreateShopOverlay((string) shop["name"]); container.Add(shopDescription, ShopOverlayName, ShopDescOverlay); } else container = new CuiElementContainer(); container.Add(new CuiPanel { Image = { Color = "0 0 0 0" }, RectTransform = { AnchorMin = "0 0.2", AnchorMax = "1 0.6" } }, ShopOverlayName, ShopContentName); if (from < 0) { CuiHelper.AddUi(player, container); return; } var itemslist = new Dictionary<string, Dictionary<string, bool>>(); object type; if (shop.TryGetValue("sell", out type)) { foreach (string itemname in (List<object>)type) { Dictionary<string, bool> itemEntry; if (!itemslist.TryGetValue(itemname, out itemEntry)) itemslist[itemname] = itemEntry = new Dictionary<string, bool>(); itemEntry["sell"] = true; } } if (shop.TryGetValue("buy", out type)) { foreach (string itemname in (List<object>)type) { Dictionary<string, bool> itemEntry; if (!itemslist.TryGetValue(itemname, out itemEntry)) itemslist[itemname] = itemEntry = new Dictionary<string, bool>(); itemEntry["buy"] = true; } } var current = 0; foreach (var pair in itemslist) { ItemData data; if (!ShopCategories.TryGetValue(pair.Key, out data)) continue; if (current >= from && current < from + 10) { var pos = 1.15f - 0.125f * (current - from); var cooldown = data.Cooldown > 0; var name = pair.Key; if (cooldown) name += $" ({FormatTime((long)data.Cooldown)})"; container.AddRange(CreateShopItemIcon(name, pos + 0.125f, pos, data)); var buyed = false; if (cooldown) { Dictionary<string, double> itemCooldowns; double itemCooldown; if (cooldowns.TryGetValue(player.userID, out itemCooldowns) && itemCooldowns.TryGetValue(pair.Key, out itemCooldown) && itemCooldown > CurrentTime()) { buyed = true; container.Add(new CuiLabel { Text = {Text = GetBuyPrice(data).ToString(), FontSize = 15, Align = TextAnchor.MiddleLeft}, RectTransform = {AnchorMin = $"0.45 {pos}", AnchorMax = $"0.5 {pos + 0.125f}"} }, ShopContentName); container.Add(new CuiLabel { Text = {Text = FormatTime((long)(itemCooldown - CurrentTime())), FontSize = 15, Align = TextAnchor.MiddleLeft}, RectTransform = {AnchorMin = $"0.5 {pos}", AnchorMax = $"0.6 {pos + 0.125f}"} }, ShopContentName); //current++; //continue; } } if (!buyed && pair.Value.ContainsKey("buy")) container.AddRange(CreateShopItemEntry(GetBuyPrice(data).ToString(), pos + 0.125f, pos, $"'{shopid}'", $"'{pair.Key}'", "0 0.6 0 0.1", false, cooldown)); if (pair.Value.ContainsKey("sell")) container.AddRange(CreateShopItemEntry(GetSellPrice(data).ToString(), pos + 0.125f, pos, $"'{shopid}'", $"'{pair.Key}'", "1 0 0 0.1", true, cooldown)); } current++; } var minfrom = from <= 10 ? 0 : from - 10; var maxfrom = from + 10 >= current ? from : from + 10; container.AddRange(CreateShopChangePage(shopid, minfrom, maxfrom)); CuiHelper.AddUi(player, container); }
-
-
-
Attached Files:
-
-
-
is it a seperate plugin to call heli though the shop ?
-
Attached Files:
-
-
-
Maybe I'm missing something but GUIShop doesn't seem to work with the latest Economics update.
(06:41:54) | Failed to call hook 'OnUseNPC' on plugin 'GUIShop v1.4.2' (NullReferenceException: Object reference not set to an instance of an object)
(06:41:54) | at Oxide.Plugins.GUIShop.ShowShop (.BasePlayer player, System.String shopid, Int32 from, Boolean fullPaint, Boolean refreshMoney) [0x00000] in <filename unknown>:0
at Oxide.Plugins.GUIShop.OnUseNPC (.BasePlayer npc, .BasePlayer player) [0x00000] in <filename unknown>:0
at Oxide.Plugins.GUIShop.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x00000] in <filename unknown>:0
at Oxide.Plugins.CSharpPlugin.InvokeMethod (Oxide.Core.Plugins.HookMethod method, System.Object[] args) [0x00000] in <filename unknown>:0
at Oxide.Core.Plugins.CSPlugin.OnCallHook (System.String name, System.Object[] args) [0x00000] in <filename unknown>:0
at Oxide.Core.Plugins.Plugin.CallHook (System.String hook, System.Object[] args) [0x00000] in <filename unknown>:0 -
-
AND whenever I installed the new version 3.1.0, it erased the data file containing all players money. Lots of mad players will yell at me tomorrow. FYI -
-
Wulf Community Admin
-
same here i have dont a Backup
-
Wulf Community Admin
If you're having an issue with a dependency, please use it's support thread, not this plugin's thread.
-
sorry GUIShop works only Economics dont work
-
Wulf Community Admin
-
-
Is it possible to get this included as an update?