From 9fbab7a4e649e900f67045a0cc898430cc404b88 Mon Sep 17 00:00:00 2001 From: Zerio Date: Sat, 25 May 2024 21:04:30 +0000 Subject: [PATCH 1/3] fix: remove usable item after resource stop --- server/events.lua | 8 ++++++++ server/functions.lua | 21 ++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/server/events.lua b/server/events.lua index 49ec40f0c..e1cfcb3c7 100644 --- a/server/events.lua +++ b/server/events.lua @@ -18,6 +18,14 @@ AddEventHandler('playerDropped', function(reason) QBCore.Players[src] = nil end) +AddEventHandler("onResourceStop", function(resName) + for i,v in pairs(QBCore.UsableItems) do + if v.resource == resName then + QBCore.UsableItems[i] = nil + end + end +end) + -- Player Connecting local function onPlayerConnecting(name, _, deferrals) diff --git a/server/functions.lua b/server/functions.lua index 3f7689d40..116573f52 100644 --- a/server/functions.lua +++ b/server/functions.lua @@ -462,7 +462,26 @@ end ---@param item string ---@param data function function QBCore.Functions.CreateUseableItem(item, data) - QBCore.UsableItems[item] = data + local rawFunc = nil + + if type(data) == "table" then + if rawget(data, '__cfx_functionReference') then + rawFunc = data + elseif data.cb and rawget(data.cb, '__cfx_functionReference') then + rawFunc = data.cb + elseif data.callback and rawget(data.callback, '__cfx_functionReference') then + rawFunc = data.callback + end + elseif type(data) == "function" then + rawFunc = data + end + + if rawFunc then + QBCore.UsableItems[item] = { + func = rawFunc, + resource = GetInvokingResource() + } + end end ---Checks if the given item is usable From d203762b73db0d8d8111c5805b8d85d387736965 Mon Sep 17 00:00:00 2001 From: Zerio Date: Sat, 25 May 2024 21:10:01 +0000 Subject: [PATCH 2/3] fix: lint issues --- client/functions.lua | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/client/functions.lua b/client/functions.lua index 4b4bda124..3224b0d93 100644 --- a/client/functions.lua +++ b/client/functions.lua @@ -43,16 +43,13 @@ end function QBCore.Functions.LookAtEntity(entity, timeout, speed) local involved = GetInvokingResource() if not DoesEntityExist(entity) then - turnPromise:reject(involved .. ' :^1 Entity does not exist') - return turnPromise.value + return involved .. ' :^1 Entity does not exist' end - if not type(entity) == 'number' then - turnPromise:reject(involved .. ' :^1 Entity must be a number') - return turnPromise.value + if type(entity) ~= 'number' then + return involved .. ' :^1 Entity must be a number' end - if not type(speed) == 'number' then - turnPromise:reject(involved .. ' :^1 Speed must be a number') - return turnPromise.value + if type(speed) ~= 'number' then + return involved .. ' :^1 Speed must be a number' end if speed > 5.0 then speed = 5.0 end if timeout > 5000 then timeout = 5000 end @@ -62,7 +59,7 @@ function QBCore.Functions.LookAtEntity(entity, timeout, speed) local dx = targetPos.x - playerPos.x local dy = targetPos.y - playerPos.y local targetHeading = GetHeadingFromVector_2d(dx, dy) - local turnSpeed = speed + local turnSpeed = nil local startTimeout = GetGameTimer() while true do local currentHeading = GetEntityHeading(ped) From 36549a6cc92b11fea919671a0b2f38d9f8a42508 Mon Sep 17 00:00:00 2001 From: Zerio Date: Sat, 25 May 2024 21:14:44 +0000 Subject: [PATCH 3/3] fix: `value assigned to variable 'turnSpeed' is unused` --- client/functions.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/functions.lua b/client/functions.lua index 3224b0d93..5530d8292 100644 --- a/client/functions.lua +++ b/client/functions.lua @@ -59,7 +59,7 @@ function QBCore.Functions.LookAtEntity(entity, timeout, speed) local dx = targetPos.x - playerPos.x local dy = targetPos.y - playerPos.y local targetHeading = GetHeadingFromVector_2d(dx, dy) - local turnSpeed = nil + local turnSpeed local startTimeout = GetGameTimer() while true do local currentHeading = GetEntityHeading(ped)