-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathclient.lua
67 lines (54 loc) · 1.67 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
60
61
62
63
64
65
66
67
local hasPhone = false
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
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
exports("HasPhone", function()
return hasPhone
end)
-- 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)
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.
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)