Merge pull request #1109 from Z3rio/main

feat: remove usable item fn after stopped resource
This commit is contained in:
Kakarot
2024-11-13 16:01:10 -05:00
committed by GitHub
3 changed files with 34 additions and 10 deletions
+6 -9
View File
@@ -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)
+8
View File
@@ -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
+20 -1
View File
@@ -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