From 848353053b12ad113c28f227e327708b0aa6b5b0 Mon Sep 17 00:00:00 2001 From: hydrant Date: Sat, 22 May 2021 19:10:40 +0200 Subject: [PATCH] addserver function to set inventory show --- ReallifeGamemode.Client/inventory/inventory.ts | 6 +++--- ReallifeGamemode.Server/Events/Key.cs | 2 +- .../Extensions/ClientExtension.cs | 12 ++++++++++++ .../Util/InventoryToggleOption.cs | 11 +++++++++++ 4 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 ReallifeGamemode.Server/Util/InventoryToggleOption.cs diff --git a/ReallifeGamemode.Client/inventory/inventory.ts b/ReallifeGamemode.Client/inventory/inventory.ts index 1f2a7504..05a90982 100644 --- a/ReallifeGamemode.Client/inventory/inventory.ts +++ b/ReallifeGamemode.Client/inventory/inventory.ts @@ -21,14 +21,14 @@ invBrowser = mp.browsers.new('package://assets/html/inventory/inventory.html'); }); - mp.events.add('inventoryShow', () => { - if (!globalData.InMenu && !loaded) { + mp.events.add('inventoryShow', (force = undefined) => { + if (!globalData.InMenu && !loaded || force === true) { globalData.InMenu = true; mp.gui.cursor.show(true, true); loaded = true; invBrowser.execute(`showInventory()`); - } else if (loaded) { + } else if (loaded || force === true) { globalData.InMenu = false; mp.gui.cursor.show(false, false); loaded = false; diff --git a/ReallifeGamemode.Server/Events/Key.cs b/ReallifeGamemode.Server/Events/Key.cs index 234616eb..b77f8649 100644 --- a/ReallifeGamemode.Server/Events/Key.cs +++ b/ReallifeGamemode.Server/Events/Key.cs @@ -769,7 +769,7 @@ namespace ReallifeGamemode.Server.Events if (!player.IsLoggedIn() || player.GetData("isDead")) return; if (player.GetData("isDead")) return; - player.TriggerEvent("inventoryShow"); + player.ToggleInventory(); InventoryManager.SetBackpackItems(player); } diff --git a/ReallifeGamemode.Server/Extensions/ClientExtension.cs b/ReallifeGamemode.Server/Extensions/ClientExtension.cs index 817d2ee4..2ffa1af2 100644 --- a/ReallifeGamemode.Server/Extensions/ClientExtension.cs +++ b/ReallifeGamemode.Server/Extensions/ClientExtension.cs @@ -477,5 +477,17 @@ namespace ReallifeGamemode.Server.Extensions if (player.GetUser().Wanteds > 0) PositionManager.cuffPoints.Add(player); } + + public static void ToggleInventory(this Player player, InventoryToggleOption option = InventoryToggleOption.TOGGLE) + { + if(option == InventoryToggleOption.TOGGLE) + { + player.TriggerEvent("inventoryShow"); + } + else + { + player.TriggerEvent("inventoryShow", option == InventoryToggleOption.SHOW); + } + } } } diff --git a/ReallifeGamemode.Server/Util/InventoryToggleOption.cs b/ReallifeGamemode.Server/Util/InventoryToggleOption.cs new file mode 100644 index 00000000..863e6210 --- /dev/null +++ b/ReallifeGamemode.Server/Util/InventoryToggleOption.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace ReallifeGamemode.Server.Util +{ + public enum InventoryToggleOption + { + TOGGLE, SHOW, HIDE + } +}