-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclient.lua
More file actions
361 lines (275 loc) · 10.1 KB
/
client.lua
File metadata and controls
361 lines (275 loc) · 10.1 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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
Citizen.CreateThread(function()
SetMapZoomDataLevel(0, 0.96, 0.9, 0.08, 0.0, 0.0)
SetMapZoomDataLevel(1, 1.6, 0.9, 0.08, 0.0, 0.0)
SetMapZoomDataLevel(2, 8.6, 0.9, 0.08, 0.0, 0.0)
SetMapZoomDataLevel(3, 12.3, 0.9, 0.08, 0.0, 0.0)
SetMapZoomDataLevel(4, 22.3, 0.9, 0.08, 0.0, 0.0)
end)
local radarLoopActive = true
Citizen.CreateThread(function()
while radarLoopActive do
Citizen.Wait(0)
if IsPedOnFoot(GetPlayerPed(-1)) then
SetRadarZoom(1100)
elseif IsPedInAnyVehicle(GetPlayerPed(-1), true) then
SetRadarZoom(1100)
end
end
end)
-- DO NOT MODIFY!
vBitmapTileSizeX = 4500.0
vBitmapTileSizeY = 4500.0
vBitmapStartX = -4140.0
vBitmapStartY = 8400.0
-- Overlay ID.
overlay = 0
-- Will store the keys of the currently drawn tiles.
drawnTiles = {}
-- List to store the dummy blip handles.
dummyBlips = {}
-- Function that will create a new tile.
function createTile(tileName)
-- Early exit for invalid tile name.
if extraTiles[tileName] == nil then
return
end
-- Get the tile's object.
local extraTile = extraTiles[tileName]
if extraTile.txd == nil or extraTile.txn == nil then
return
end
-- Get the texture info, alpha, centering and rotation.
local textureDictionary = extraTile.txd
local textureName = extraTile.txn
local alpha = extraTile.alpha or defaultAlpha
local centered = extraTile.centered or false
local rotation = extraTile.rotation or 0.0
-- Load the required texture.
loadTextureDictionary(textureDictionary)
-- Get the width and height of the texture.
local xTexture, yTexture, _ = table.unpack(GetTextureResolution(textureDictionary, textureName))
-- Compute the scale ratios.
local xScale = vBitmapTileSizeX / xTexture * 100
local yScale = vBitmapTileSizeY / yTexture * 100
-- Tile was configurated to use XY coordinates.
if extraTile.x ~= nil and extraTile.y ~= nil then
-- Compute offsets from given coordinates since other functionalities
-- such as extendPauseMenuMapBounds() work with offsets, not with XY coords directly.
extraTile.xOffset = (extraTile.x - vBitmapStartX) / vBitmapTileSizeX
extraTile.yOffset = (extraTile.y - vBitmapStartY) / vBitmapTileSizeY
end
-- Get the offsets, convert to float.
local xOffset = extraTile.xOffset * 1.0
local yOffset = extraTile.yOffset * (-1.0)
-- Compute X and Y coordinates based on the offsets.
local x = vBitmapStartX + xOffset * vBitmapTileSizeX
local y = vBitmapStartY - yOffset * vBitmapTileSizeY
-- Convert alpha to an INT.
alpha = math.floor(math.abs(alpha))
-- Convert rotation to FLOAT.
rotation = rotation * 1.0
-- Call the Scaleform function.
CallMinimapScaleformFunction(overlay, "ADD_SCALED_OVERLAY")
-- Push the parameters onto the stack.
ScaleformMovieMethodAddParamTextureNameString(textureDictionary)
ScaleformMovieMethodAddParamTextureNameString(textureName)
ScaleformMovieMethodAddParamFloat(x)
ScaleformMovieMethodAddParamFloat(y)
ScaleformMovieMethodAddParamFloat(rotation)
ScaleformMovieMethodAddParamFloat(xScale)
ScaleformMovieMethodAddParamFloat(yScale)
ScaleformMovieMethodAddParamInt(alpha)
ScaleformMovieMethodAddParamBool(centered)
EndScaleformMovieMethod()
-- Mark the texture as no longer needed.
SetStreamedTextureDictAsNoLongerNeeded(textureDictionary)
-- Add it to the drawn tiles table.
table.insert(drawnTiles, tileName)
end
-- Function that deletes a tile.
function deleteTile(tileName)
local id = -1
for i = 1, #drawnTiles do
if drawnTiles[i] == tileName then
id = i
table.remove(drawnTiles, id)
break
end
end
if id == -1 then
return
end
-- Call the remove scaleform function.
CallMinimapScaleformFunction(overlay, "REM_OVERLAY");
-- Push the parameter onto the stack.
ScaleformMovieMethodAddParamInt(id - 1)
EndScaleformMovieMethod()
end
-- Function that will draw all tiles in the extraTiles table.
function createAllTiles()
local extraTilesNames = getTableKeys(extraTiles)
if extraTilesNames == nil then
return
end
-- Iterate all extra tiles.
for i = 1, #extraTilesNames do
-- Get the current tile's key.
local tileName = extraTilesNames[i]
-- Create the new tile.
createTile(tileName)
end
if #dummyBlips == 0 and #drawnTiles > 0 then
extendPauseMenuMapBounds()
end
end
-- Function that will delete all tiles that are currently drawn.
function deleteAllTiles()
-- Delete the tile at index 1. The table will shift the remaining
-- elements' indices.
for i = 1, #drawnTiles do
deleteTile(drawnTiles[1])
end
if #dummyBlips ~= 0 then
resetPauseMenuMapBounds()
end
end
-- Function that returns true if the tile with the specified name is currently drawn
-- or false otherwise.
function isTileDrawn(tileName)
if tileName == nil then
return false
end
for i = 1, #drawnTiles do
if drawnTiles[i] == tileName then
return true
end
end
return false
end
-- Function that will let you move outside the normal bounds of the
-- pause menu map.
function extendPauseMenuMapBounds()
if #dummyBlips ~= 0 then
resetPauseMenuMapBounds()
end
local extraTilesNames = drawnTiles
if extraTilesNames == nil or #extraTilesNames == 0 then
return
end
-- Set starting values.
local xMinOffset = extraTiles[extraTilesNames[1]].xOffset or 0
local xMaxOffset = extraTiles[extraTilesNames[1]].xOffset or 0
local yMinOffset = extraTiles[extraTilesNames[1]].yOffset or 0
local yMaxOffset = extraTiles[extraTilesNames[1]].yOffset or 0
-- Find min and max values for xOffset and yOffset.
for i = 1, #extraTilesNames do
local extraTile = extraTiles[extraTilesNames[i]]
if extraTile.xOffset < xMinOffset then
xMinOffset = extraTile.xOffset
end
if extraTile.xOffset > xMaxOffset then
xMaxOffset = extraTile.xOffset
end
if extraTile.yOffset < yMinOffset then
yMinOffset = extraTile.yOffset
end
if extraTile.yOffset > yMaxOffset then
yMaxOffset = extraTile.yOffset
end
end
-- Create 4 invisible blips at the corners of the furthest tiles
-- to create something like a bounding box in which all other
-- tiles are included. This could possibly be improved to use 2
-- blips instead of 4.
createDummyBlip(vBitmapStartX + xMinOffset * vBitmapTileSizeX - vBitmapTileSizeX / 2,
vBitmapStartY + yMaxOffset * vBitmapTileSizeY + vBitmapTileSizeY / 2)
createDummyBlip(vBitmapStartX + xMinOffset * vBitmapTileSizeX - vBitmapTileSizeX / 2,
vBitmapStartY + (yMinOffset - 1) * vBitmapTileSizeY - vBitmapTileSizeY / 2)
createDummyBlip(vBitmapStartX + (xMaxOffset + 1) * vBitmapTileSizeX + vBitmapTileSizeX / 2,
vBitmapStartY + (yMinOffset - 1) * vBitmapTileSizeY - vBitmapTileSizeY / 2)
createDummyBlip(vBitmapStartX + (xMaxOffset + 1) * vBitmapTileSizeX + vBitmapTileSizeX / 2,
vBitmapStartY + yMaxOffset * vBitmapTileSizeY + vBitmapTileSizeY / 2)
end
-- This function will reset the pause menu map's bounds to the default.
function resetPauseMenuMapBounds()
for i = 1, #dummyBlips do
RemoveBlip(dummyBlips[i])
end
dummyBlips = {}
end
-- Function that will create an invisible blip.
function createDummyBlip(x, y)
local dummyBlip = AddBlipForCoord(x, y, 1.0)
SetBlipDisplay(dummyBlip, 4)
SetBlipAlpha(dummyBlip, 0)
table.insert(dummyBlips, dummyBlip)
end
-- Loads a minimap overlay from a given path.
function loadMinimapOverlay(gfxFilePath)
local _overlay = AddMinimapOverlay(gfxFilePath)
while not HasMinimapOverlayLoaded(_overlay) do
Citizen.Wait(0)
end
SetMinimapOverlayDisplay(_overlay, 0.0, 0.0, 100.0, 100.0, 100.0)
return _overlay
end
-- Loads a texture dictionary into memory.
function loadTextureDictionary(textureDictionary)
if not HasStreamedTextureDictLoaded(textureDictionary) then
RequestStreamedTextureDict(textureDictionary, false)
while not HasStreamedTextureDictLoaded(textureDictionary) do
Citizen.Wait(0)
end
end
end
-- Function that converts the keys of a dictionary to an alphabetically-sorted list.
function getTableKeys(keyset)
local list = {}
for key, _ in pairs(keyset) do
table.insert(list, key)
end
table.sort(list)
return list
end
exports("createAllTiles", createAllTiles)
exports("deleteAllTiles", deleteAllTiles)
exports("createTile", createTile)
exports("deleteTile", deleteTile)
exports("extendPauseMenuMapBounds", extendPauseMenuMapBounds)
exports("resetPauseMenuMapBounds", resetPauseMenuMapBounds)
exports("isTileDrawn", isTileDrawn)
Citizen.CreateThread(function()
while not (NetworkIsGameInProgress() and IsMinimapRendering()) do
Citizen.Wait(0)
end
-- Extra delay to ensure the streaming system has fully settled after RELOAD_MAP_STORE.
Citizen.Wait(3000)
-- Load the minimap overlay.
overlay = loadMinimapOverlay("MINIMAP_LOADER.gfx")
-- Draw all tiles.
createAllTiles()
end)
-- Cleanup on resource stop to prevent client crash on reconnect.
AddEventHandler('onClientResourceStop', function(resourceName)
if GetCurrentResourceName() ~= resourceName then
return
end
-- Stop the radar zoom loop.
radarLoopActive = false
-- Remove the minimap overlay. Without this, reconnecting causes a crash
-- because AddMinimapOverlay is called again for the same GFX file.
if overlay ~= 0 then
RemoveMinimapOverlay(overlay)
overlay = 0
end
-- Remove dummy blips.
for i = 1, #dummyBlips do
RemoveBlip(dummyBlips[i])
end
dummyBlips = {}
drawnTiles = {}
-- Reset map zoom data levels to default.
for i = 0, 4 do
ResetMapZoomDataLevel(i)
end
end)