Skip to content

Commit

Permalink
Merge pull request #1109 from Z3rio/main
Browse files Browse the repository at this point in the history
feat: remove usable item fn after stopped resource
  • Loading branch information
GhzGarage authored Nov 13, 2024
2 parents a1b72ca + bbf2349 commit acdefdf
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
15 changes: 6 additions & 9 deletions client/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions server/events.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 20 additions & 1 deletion server/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit acdefdf

Please sign in to comment.