diff --git a/client.lua b/client.lua index a88480a..ea9aec9 100644 --- a/client.lua +++ b/client.lua @@ -1,10 +1,11 @@ local QBCore = exports['qb-core']:GetCoreObject() local hasPhone = false -local function DoPhoneCheck(PlayerItems) +local function DoPhoneCheck(PlayerData) local _hasPhone = false - - for _,item in pairs(PlayerItems) do + local PlayerItems = PlayerData.items or {} + local metadata = PlayerData.metadata or {} + for _, item in pairs(PlayerItems) do if Config.PhoneList[item.name] then _hasPhone = true break; @@ -12,18 +13,30 @@ local function DoPhoneCheck(PlayerItems) end hasPhone = _hasPhone - exports['npwd']:setPhoneDisabled(not hasPhone) + local isDead = (metadata["isdead"] or metadata['inlaststand']) or false + local isCuffed = metadata["ishandcuffed"] or false + local disabled = false + if not Config.UseWhileDead and isDead then + disabled = true + end + if not Config.UseWhileCuffed and isCuffed then + disabled = true + end + if exports['npwd']:isPhoneVisible() and disabled then + exports['npwd']:setPhoneVisible(false) + end + exports['npwd']:setPhoneDisabled(disabled) end local function HasPhone() return hasPhone end - + exports("HasPhone", HasPhone) -- Handles state right when the player selects their character and location. RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function() - DoPhoneCheck(QBCore.Functions.GetPlayerData().items) + DoPhoneCheck(QBCore.Functions.GetPlayerData()) end) -- Resets state on logout, in case of character change. @@ -34,13 +47,13 @@ end) -- Handles state when PlayerData is changed. We're just looking for inventory updates. RegisterNetEvent('QBCore:Player:SetPlayerData', function(PlayerData) - DoPhoneCheck(PlayerData.items) + DoPhoneCheck(PlayerData) end) -- Handles state if resource is restarted live. AddEventHandler('onResourceStart', function(resource) if GetCurrentResourceName() == resource and GetResourceState('npwd') == 'started' then - DoPhoneCheck(QBCore.Functions.GetPlayerData().items) + DoPhoneCheck(QBCore.Functions.GetPlayerData()) end end) diff --git a/config.lua b/config.lua index 56e9a57..84bfb49 100644 --- a/config.lua +++ b/config.lua @@ -3,4 +3,8 @@ Config = {} -- List the items you want to register as a phone here. Config.PhoneList = { ['phone'] = true, -} \ No newline at end of file +} + +Config.UseWhileDead = false + +Config.UseWhileCuffed = false \ No newline at end of file