-
Notifications
You must be signed in to change notification settings - Fork 56
/
client.lua
50 lines (40 loc) · 1.46 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
local QBCore = exports['qb-core']:GetCoreObject()
local hasPhone = false
local function DoPhoneCheck(PlayerItems)
local _hasPhone = false
for _,item in pairs(PlayerItems) do
if Config.PhoneList[item.name] then
_hasPhone = true
break;
end
end
hasPhone = _hasPhone
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(QBCore.Functions.GetPlayerData().items)
end)
-- Resets state on logout, in case of character change.
RegisterNetEvent('QBCore:Client:OnPlayerUnload', function()
DoPhoneCheck({})
TriggerServerEvent("qb-npwd:server:UnloadPlayer")
end)
-- Handles state when PlayerData is changed. We're just looking for inventory updates.
RegisterNetEvent('QBCore:Player:SetPlayerData', function(PlayerData)
DoPhoneCheck(PlayerData.items)
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)
end
end)
-- Allows use of phone as an item.
RegisterNetEvent('qb-npwd:client:setPhoneVisible', function(isPhoneVisible)
exports['npwd']:setPhoneVisible(isPhoneVisible)
end)