-
Notifications
You must be signed in to change notification settings - Fork 4
/
client.lua
195 lines (151 loc) · 6.48 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
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
local isActivated = false
local Blips, activeBlips = {}, {}
AddEventHandler('esx:onPlayerDeath', function()
TriggerServerEvent('msk_jobGPS:setDeath')
end)
AddEventHandler('msk_jobGPS:activateGPS', function(GPS)
isActivated = true
end)
AddEventHandler('msk_jobGPS:deactivateGPS', function()
isActivated = false
end)
if Config.Panicbutton.enable and Config.Commands.panicbutton.enable then
RegisterCommand(Config.Commands.panicbutton.command, function()
if not Config.allowedJobs[ESX.PlayerData.job.name] then return end
if not Config.allowedJobs[ESX.PlayerData.job.name].panicbutton then return end
TriggerServerEvent('msk_jobGPS:togglePanicbutton')
if Config.Panicbutton.notifyNearestPlayers then
local players = ESX.Game.GetPlayersInArea(GetEntityCoords(PlayerPedId()), 8.0)
for k, player in pairs(players) do
TriggerServerEvent('msk_jobGPS:notifyNearestPlayers', GetPlayerServerId(player))
end
end
end)
if Config.Panicbutton.hotkey.enable then
RegisterKeyMapping(Config.Commands.panicbutton.command, 'Panicbutton', 'keyboard', Config.Panicbutton.hotkey.key)
end
end
RegisterNetEvent('msk_jobGPS:activatePanicbutton')
AddEventHandler('msk_jobGPS:activatePanicbutton', function(xPlayer)
local playerId = tonumber(xPlayer.source)
if activeBlips[playerId] then SetBlipColour(activeBlips[playerId].blip, Config.Panicbutton.blipColor) end
SetNewWaypoint(xPlayer.coords.x, xPlayer.coords.y)
end)
addBlips = function(GPS)
for playerId, v in pairs(GPS) do
logging('debug', playerId, v)
-- v = xPlayer, netId, coords, heading
local xPlayer = v.xPlayer
if ESX.PlayerData.identifier ~= xPlayer.identifier then
local blip = AddBlipForCoord(xPlayer.coords.x, xPlayer.coords.y, xPlayer.coords.z)
SetBlipRotation(blip, v.heading)
SetBlipSprite(blip, Config.GPS.blip.id)
SetBlipScale(blip, Config.GPS.blip.scale)
SetBlipColour(blip, Config.GPS.blip.color)
SetBlipDisplay(blip, 2)
SetBlipAsShortRange(blip, true)
AddTextEntry("BLIP_OTHPLYR", Config.GPS.blip.prefix)
SetBlipCategory(blip, 7)
ShowOutlineIndicatorOnBlip(blip, true)
SetBlipSecondaryColour(blip, 255, 0, 0)
ShowHeadingIndicatorOnBlip(blip, true)
AddTextEntry("NAME_" .. xPlayer.name, "~a~")
BeginTextCommandSetBlipName("NAME_" .. xPlayer.name)
AddTextComponentString(xPlayer.name)
EndTextCommandSetBlipName(blip)
Blips[#Blips + 1] = blip
activeBlips[playerId] = {isActive = false, blip = blip}
end
end
end
RegisterNetEvent('msk_jobGPS:activateGPS', addBlips)
addBlip = function(GPS, xPlayer, heading)
logging('debug', 'Add Blip for ' .. xPlayer.source)
local blip = AddBlipForCoord(xPlayer.coords.x, xPlayer.coords.y, xPlayer.coords.z)
SetBlipRotation(blip, heading)
SetBlipSprite(blip, Config.GPS.blip.id)
SetBlipScale(blip, Config.GPS.blip.scale)
SetBlipColour(blip, Config.GPS.blip.color)
SetBlipDisplay(blip, 2)
SetBlipAsShortRange(blip, true)
AddTextEntry("BLIP_OTHPLYR", Config.GPS.blip.prefix)
SetBlipCategory(blip, 7)
ShowOutlineIndicatorOnBlip(blip, true)
SetBlipSecondaryColour(blip, 255, 0, 0)
ShowHeadingIndicatorOnBlip(blip, true)
AddTextEntry("NAME_" .. xPlayer.name, "~a~")
BeginTextCommandSetBlipName("NAME_" .. xPlayer.name)
AddTextComponentString(xPlayer.name)
EndTextCommandSetBlipName(blip)
Blips[#Blips + 1] = blip
activeBlips[tonumber(xPlayer.source)] = {isActive = false, blip = blip}
end
refreshBlips = function(GPS)
logging('debug', 'refreshBlips')
for playerId, v in pairs(GPS) do
-- v = xPlayer, netId, coords, heading
local xPlayer = v.xPlayer
if ESX.PlayerData.identifier ~= xPlayer.identifier then
if not activeBlips[playerId] then addBlip(GPS, xPlayer, v.heading) end
logging('debug', 'Blip is active')
local OneSync = inOneSync(v.netId)
if OneSync and not activeBlips[playerId].isActive then
logging('debug', 'inOneSync')
CreateThread(function()
activeBlips[playerId].isActive = true
while activeBlips[playerId] and activeBlips[playerId].isActive and DoesEntityExist(OneSync.ped) do
local coords = GetEntityCoords(OneSync.ped)
local heading = math.ceil(GetEntityHeading(OneSync.ped))
SetBlipCoords(activeBlips[playerId].blip, coords.x, coords.y, coords.z)
SetBlipRotation(activeBlips[playerId].blip, heading)
Wait(0)
end
end)
elseif not OneSync then
logging('debug', 'not inOneSync')
activeBlips[playerId].isActive = false
SetBlipCoords(activeBlips[playerId].blip, v.coords.x, v.coords.y, v.coords.z)
SetBlipRotation(activeBlips[playerId].blip, v.heading)
end
end
end
end
RegisterNetEvent('msk_jobGPS:refreshBlips', refreshBlips)
removeBlips = function()
logging('debug', 'removeBlips')
for k, blip in pairs(Blips) do
RemoveBlip(blip)
end
Blips = {}
activeBlips = {}
end
RegisterNetEvent('msk_jobGPS:deactivateGPS', removeBlips)
removeBlipById = function(playerId, reason)
if not activeBlips[playerId] then return end
if Config.StayActivated.enable then
activeBlips[playerId].isActive = false
if Config.StayActivated[reason] then
SetBlipColour(activeBlips[playerId].blip, 40)
Wait(Config.StayActivated.seconds * 1000)
end
end
logging('debug', 'Deactivating Blip by ID for ID: ' .. playerId)
for k, blip in pairs(Blips) do
if activeBlips[playerId].blip == blip then
Blips[k] = nil
break
end
end
RemoveBlip(activeBlips[playerId].blip)
activeBlips[playerId] = nil
end
RegisterNetEvent('msk_jobGPS:deactivateGPSById', removeBlipById)
inOneSync = function(netId)
local playerPed = NetworkDoesNetworkIdExist(netId) and NetworkGetEntityFromNetworkId(netId)
if DoesEntityExist(playerPed) then return {ped = playerPed} end
return false
end
logging = function(code, ...)
if not Config.Debug then return end
MSK.Logging(code, ...)
end