diff --git a/client/functions.lua b/client/functions.lua index 4b4bda124..5530d8292 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 local startTimeout = GetGameTimer() while true do local currentHeading = GetEntityHeading(ped) diff --git a/server/events.lua b/server/events.lua index f741befb8..9311e80e8 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 readyFunction = MySQL.ready local databaseConnected, bansTableExists = readyFunction == nil, readyFunction == nil diff --git a/server/functions.lua b/server/functions.lua index c4ae93b68..9cfe78e76 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