From 79e765fbb0e7c91cf56c8161e359e21936c0a0a3 Mon Sep 17 00:00:00 2001 From: Jim Shield Date: Fri, 11 Jul 2025 13:33:44 +0100 Subject: [PATCH] Stop crafting trying to check blank stash names Skimmed through the stash checking and editing functions and added more "security" for handling nil or blank stash names --- shared/crafting.lua | 2 +- shared/stashcontrol.lua | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/shared/crafting.lua b/shared/crafting.lua index 958cacc..e050ce5 100644 --- a/shared/crafting.lua +++ b/shared/crafting.lua @@ -89,7 +89,7 @@ function craftingMenu(data) -- Check if the player can carry the required items (server callback). local canCarryTable = triggerCallback(getScript()..':server:canCarry', tempCarryTable) - local usingStash = data.stashName ~= nil + local usingStash = data.stashName ~= nil and data.stashName ~= "" Menu[#Menu+1] = { icon = usingStash and "fas fa-boxes-stacked" or "fas fa-person", diff --git a/shared/stashcontrol.lua b/shared/stashcontrol.lua index 458007c..66c874e 100644 --- a/shared/stashcontrol.lua +++ b/shared/stashcontrol.lua @@ -15,6 +15,9 @@ local stash -- If running on the server, create a callback to retrieve stash items. if isServer() then createCallback(getScript()..':server:GetStashItems', function(source, stashName) + if stashName == nil or stashName == "" then + return {} + end stash = getStash(stashName) return stash end) @@ -35,9 +38,9 @@ local stashCache = {} --- local cached = GetStashTimeout("playerStash") --- ``` function GetStashTimeout(stashName, stop) - if stop then + if stop or (stashName == nil or stashName == "") then stashCache = {} - return + return false end -- Retrieve cache for this stash, or initialize if not present. @@ -85,7 +88,7 @@ end --- local found, stashName = checkStashItem({"playerStash", "storageStash"}, { iron = 2, wood = 5 }) --- ``` function checkStashItem(stashes, itemTable) - if not stashes then + if not stashes or stashes == "" then return hasItem(itemTable), nil end @@ -317,7 +320,7 @@ end --- ``` function getStash(stashName) local stashResource = "" - if type(stashName) ~= "string" then + if stashName == "" or type(stashName) ~= "string" then print("^6Bridge^7: ^2Stash name was not a string ^3"..stashName.."^7(^3"..type(stashName).."^7)") return {} end @@ -420,6 +423,10 @@ end --- stashRemoveItem(currentItems, "playerStash", { iron = 2, wood = 5 }) --- ``` function stashRemoveItem(stashItems, stashName, items) + if stashName == "" or stashName == nil then + print("^1ERROR^7: ^1stashRemoveItem triggered but stashName was empty^7") + return + end if type(stashName) ~= "table" then stashName = { stashName } end