forked from Qbox-project/qbx_npwd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.lua
59 lines (46 loc) · 1.51 KB
/
client.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
local hasPhone = false
local function DoPhoneCheck(isUnload)
hasPhone = false
if isUnload then
exports.npwd:setPhoneDisabled(true)
return
end
local items = exports.ox_inventory:Search('count', Config.PhoneList)
if type(items) == 'number' then
hasPhone = items > 0
else
for _, v in pairs(items) do
if v > 0 then
hasPhone = true
break
end
end
end
exports.npwd:setPhoneDisabled(not hasPhone)
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()
end)
-- Resets state on logout, in case of character change.
RegisterNetEvent('QBCore:Client:OnPlayerUnload', function()
DoPhoneCheck(true)
TriggerServerEvent("qbx-npwd:server:UnloadPlayer")
end)
-- Handles state when PlayerData is changed. We're just looking for inventory updates.
RegisterNetEvent('QBCore:Player:SetPlayerData', function(PlayerData)
DoPhoneCheck()
end)
-- Handles state if resource is restarted live.
AddEventHandler('onResourceStart', function(resource)
if GetCurrentResourceName() ~= resource or GetResourceState('npwd') ~= 'started' then return end
DoPhoneCheck()
end)
-- Allows use of phone as an item.
RegisterNetEvent('qbx-npwd:client:setPhoneVisible', function(isPhoneVisible)
exports.npwd:setPhoneVisible(isPhoneVisible)
end)