-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathclient.lua
More file actions
173 lines (156 loc) · 4.51 KB
/
Copy pathclient.lua
File metadata and controls
173 lines (156 loc) · 4.51 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
local QBCore = exports["qb-core"]:GetCoreObject()
local ACTIVE = false
local currentBlips = {}
local PlayerData = QBCore.Functions.GetPlayerData() -- Just for resource restart (same as event handler)
local onGPS = false
local gpsProp = 0
local function isPolice()
PlayerData = QBCore.Functions.GetPlayerData()
if PlayerData ~= nil then
local isPolice = false
if PlayerData.job ~= nil and PlayerData.job.name == 'police' then
isPolice = true
end
return isPolice
end
end
local function LoadAnimDic(dict)
if not HasAnimDictLoaded(dict) then
RequestAnimDict(dict)
while not HasAnimDictLoaded(dict) do
Wait(0)
end
end
end
local function GpsToggle(toggle)
if not isPolice() then return end
onGPS = toggle
TriggerServerEvent("tnj-polgps:server:ToggleGPS", toggle)
end
local function RemoveAnyExistingEmergencyBlips()
for i = #currentBlips, 1, -1 do
local b = currentBlips[i]
if b ~= 0 then
RemoveBlip(b)
table.remove(currentBlips, i)
end
end
end
local function RefreshBlips(activeEmergencyPersonnel)
local myServerId = GetPlayerServerId(PlayerId())
if isPolice() then
for src, info in pairs(activeEmergencyPersonnel) do
if src ~= myServerId then
if info and info.coords then
local blip = AddBlipForCoord(info.coords.x, info.coords.y, info.coords.z)
SetBlipSprite(blip, 1)
SetBlipColour(blip, info.color)
SetBlipAsShortRange(blip, true)
SetBlipDisplay(blip, 4)
SetBlipShowCone(blip, true)
BeginTextCommandSetBlipName("STRING")
AddTextComponentString(info.name)
EndTextCommandSetBlipName(blip)
table.insert(currentBlips, blip)
end
end
end
end
end
local function toggleGpsAnimation(pState)
if not isPolice() then return end
LoadAnimDic("cellphone@")
if pState then
TaskPlayAnim(PlayerPedId(), "cellphone@", "cellphone_text_read_base", 2.0, 3.0, -1, 49, 0, 0, 0, 0)
gpsProp = CreateObject(`prop_cs_hand_radio`, 1.0, 1.0, 1.0, 1, 1, 0)
AttachEntityToEntity(gpsProp, PlayerPedId(), GetPedBoneIndex(PlayerPedId(), 57005), 0.14, 0.01, -0.02, 110.0, 120.0, -15.0, 1, 0, 0, 0, 2, 1)
else
StopAnimTask(PlayerPedId(), "cellphone@", "cellphone_text_read_base", 1.0)
ClearPedTasks(PlayerPedId())
if gpsProp ~= 0 then
DeleteObject(gpsProp)
gpsProp = 0
end
end
end
local function toggleGps(toggle)
if not isPolice() then return end
gpsMenu = toggle
SetNuiFocus(gpsMenu, gpsMenu)
if gpsMenu then
toggleGpsAnimation(true)
SendNUIMessage({type = "open"})
else
toggleGpsAnimation(false)
SendNUIMessage({type = "close"})
end
end
local function IsGpsOn()
return onGPS
end
exports("IsGpsOn", IsGpsOn)
RegisterNetEvent('QBCore:Client:OnPlayerUnload', function()
PlayerData = {}
GpsToggle(false)
end)
RegisterNetEvent('tnj-polgps:use', function()
if isPolice() then
toggleGps(not gpsMenu)
end
end)
RegisterNetEvent('tnj-polgps:onGpsDrop', function()
if isPolice() then
GpsToggle(false)
end
end)
RegisterNUICallback('escape', function(data, cb)
toggleGps(false)
end)
RegisterNUICallback('GPSON', function(data, cb)
if not isPolice() then return end
if not onGPS then
onGPS = true
GpsToggle(true)
else
TriggerEvent("QBCore:Notify", "GPS is already on", 'error')
end
end)
RegisterNUICallback('GPSOFF', function(data, cb)
if not isPolice() then return end
if onGPS then
onGPS = false
GpsToggle(false)
else
TriggerEvent("QBCore:Notify", "GPS Isnt on yet", 'error')
end
end)
CreateThread(function()
while true do
Wait(1000)
if LocalPlayer.state.isLoggedIn and onGPS and isPolice() then
QBCore.Functions.TriggerCallback('tnj-polgps:server:GetItem', function(hasItem)
if not hasItem then
if not isPolice() then return end
onGPS = false
GpsToggle(false)
end
end, "gps")
end
end
end)
RegisterNetEvent("tnj-polgps:toggle", function(on)
if isPolice() then
ACTIVE = on
if not ACTIVE then
RemoveAnyExistingEmergencyBlips()
end
end
end)
RegisterNetEvent("tnj-polgps:updateAll", function(data)
if isPolice() then
if ACTIVE then
RemoveAnyExistingEmergencyBlips()
RefreshBlips(data)
end
end
end)