Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add death and handcuff checks, hide phone #17

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions client.lua
Original file line number Diff line number Diff line change
@@ -1,29 +1,42 @@
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;
end
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.
Expand All @@ -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)

Expand Down
6 changes: 5 additions & 1 deletion config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ Config = {}
-- List the items you want to register as a phone here.
Config.PhoneList = {
['phone'] = true,
}
}

Config.UseWhileDead = false

Config.UseWhileCuffed = false