Skip to content

Commit

Permalink
fix(client): trigger doPhoneCheck() on inventory change
Browse files Browse the repository at this point in the history
* fix(client): Trigger doPhoneCheck() on inventory change

Previously doPhoneCheck() was triggered from listening to the playerData change in QBCore however with the use of ox_inventory that isn't updated on inventory change, so utilising https://overextended.dev/ox_inventory/Events/Client#ox_inventoryitemcount we can listen to specifically when the phone count changes

* feat(client): use PhoneList

* chore(client): remove whitespace
  • Loading branch information
SamShanks1 authored May 22, 2024
1 parent 0c576fe commit 7fd5159
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions client.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
local hasPhone = false

local function doPhoneCheck(isUnload)
local function doPhoneCheck(isUnload, totalCount)
hasPhone = false

if isUnload then
exports.npwd:setPhoneDisabled(true)
return
end

if totalCount then
hasPhone = totalCount > 0
exports.npwd:setPhoneDisabled(not hasPhone)
return
end

local items = exports.ox_inventory:Search('count', PhoneList)

if type(items) == 'number' then
Expand Down Expand Up @@ -39,9 +45,13 @@ RegisterNetEvent('QBCore:Client:OnPlayerUnload', function()
TriggerServerEvent('qbx_npwd:server:UnloadPlayer')
end)

-- Handles state when PlayerData is changed. We're just looking for inventory updates.
RegisterNetEvent('QBCore:Player:SetPlayerData', function()
doPhoneCheck()
AddEventHandler('ox_inventory:itemCount', function(itemName, totalCount)
for i = 1, #PhoneList do
if PhoneList[i] == itemName then
doPhoneCheck(false, totalCount)
break
end
end
end)

-- Handles state if resource is restarted live.
Expand Down

0 comments on commit 7fd5159

Please sign in to comment.