forked from AlterGamingNetwork/mellotrainer
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcl_settings.lua
435 lines (353 loc) · 11.3 KB
/
cl_settings.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
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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
--[[--------------------------------------------------------------------------
*
* Mello Trainer
* (C) Michael Goodwin 2017
* http://github.com/thestonedturtle/mellotrainer/releases
*
* This menu used the Scorpion Trainer as a framework to build off of.
* https://github.com/pongo1231/ScorpionTrainer
* (C) Emre Cürgül 2017
*
* A lot of useful functionality has been converted from the lambda menu.
* https://lambda.menu
* (C) Oui 2017
*
* Additional Contributors:
* WolfKnight (https://forum.fivem.net/u/WolfKnight)
*
---------------------------------------------------------------------------]]
--Not Needed?
--require("map.lua") -- Require map.lua so we can call the toggleMapBlips function.
-- Variables used for this part of the trainer.
local playerdb = {}
-- Creates an empty table of tables to hold the blip/ped information for users.
for i=0, maxPlayers, 1 do
playerdb[i] = {}
end
--[[
_ _ _ _ _____ _____ _ _ _ _
| \ | | | | | | |_ _| / ____| | | | | | | | |
| \| | | | | | | | | | __ _ | | | | | |__ __ _ ___ | | __ ___
| . ` | | | | | | | | | / _` | | | | | | '_ \ / _` | / __| | |/ / / __|
| |\ | | |__| | _| |_ | |____ | (_| | | | | | | |_) | | (_| | | (__ | < \__ \
|_| \_| \____/ |_____| \_____| \__,_| |_| |_| |_.__/ \__,_| \___| |_|\_\ |___/
--]]
RegisterNUICallback("settingtoggle", function(data, cb)
local action = data.action
local newstate = data.newstate
local text,text2
if(newstate) then
text = "~g~ON"
text2 = "~r~OFF"
else
text = "~r~OFF"
text2 = "~g~ON"
end
--Hud Toggle
if(action == "hud")then
featureHideHud = newstate
DisplayHud(not featureHideHud)
drawNotification("Hud Display: "..tostring(text2))
-- Radr Toggle
elseif(action == "radar")then
featureHideMap = newstate
DisplayRadar(not featureHideMap)
drawNotification("Radar Display: "..tostring(text2))
-- Large Map Toggle
elseif(action == "enlarge")then
featureBigHud = newstate
SetRadarBigmapEnabled(featureBigHud, false)
drawNotification("Large Map: "..tostring(text))
-- Player Blip Toggle
elseif(action == "blips")then
featurePlayerBlips = newstate
drawNotification("Player Blips: "..tostring(text))
-- Player Blip Name Toggle
elseif(action == "blipnames")then
featurePlayerBlipNames = newstate
drawNotification("Player Blip Names: "..tostring(text))
-- Player Overhead Name Toggle
elseif(action == "text")then
featurePlayerHeadDisplay = newstate
drawNotification("Overhead Player Names: "..tostring(text))
-- Street Name Toggle
elseif(action == "streets")then
featureAreaStreetNames = newstate
drawNotification("Street Names: "..tostring(text2))
-- Map Location Blips
elseif(action == "mapblips")then
featureMapBlips = newstate
toggleMapBlips(featureMapBlips) -- In maps.lua
drawNotification("Map Blips: "..tostring(text))
-- Radio Always Off
elseif(action=="radiooff")then
featureRadioAlwaysOff = newstate
drawNotification("Radio Always Off: "..text)
-- Mobile Radio
elseif(action=="mobileradio")then
featurePlayerRadio = newstate
SetMobileRadioEnabledDuringGameplay(featurePlayerRadio);
SetUserRadioControlEnabled(not featureRadioAlwaysOff)
drawNotification("Player Radio: "..text)
elseif(action=="skipradio")then
SkipRadioForward();
end
--elseif(action == )then
end)
--[[
______ _ _
| ____| | | (_)
| |__ _ _ _ __ ___ | |_ _ ___ _ __ ___
| __| | | | | | '_ \ / __| | __| | | / _ \ | '_ \ / __|
| | | |_| | | | | | | (__ | |_ | | | (_) | | | | | \__ \
|_| \__,_| |_| |_| \___| \__| |_| \___/ |_| |_| |___/
--]]
-- Toggle Radio Control
function toggleRadio(playerPed)
if(IsPedInAnyVehicle(playerPed, false))then
local veh = GetVehiclePedIsUsing(playerPed)
SetVehicleRadioEnabled(veh, not featureRadioAlwaysOff)
end
SetUserRadioControlEnabled(not featureRadioAlwaysOff)
end
--[[
_______ _ _
|__ __| | | | |
| | | |__ _ __ ___ __ _ __| |
| | | '_ \ | '__| / _ \ / _` | / _` |
| | | | | | | | | __/ | (_| | | (_| |
|_| |_| |_| |_| \___| \__,_| \__,_|
--]]
Citizen.CreateThread(function()
while true do
Wait(0)
-- Street Names
if(featureAreaStreetNames) then
HideHudComponentThisFrame(7)
HideHudComponentThisFrame(9)
end
-- Toggle minimap on keypress
if IsControlJustPressed(0, 20) and not IsPauseMenuActive() and not blockinput then
featureBigHud = not featureBigHud
SetRadarBigmapEnabled( featureBigHud, false)
end
end
end)
-- Update vehicle whenever you entere a new vehicle
RegisterNetEvent('mellotrainer:playerEnteredVehicle')
AddEventHandler('mellotrainer:playerEnteredVehicle', function(veh)
local playerPed = GetPlayerPed(-1)
toggleRadio(playerPed)
UpdateVehicleFeatureVariables(veh)
end)
-- Turn off Radio.
Citizen.CreateThread(function()
local radioToggle = false
while true do
Wait(100)
local playerPed = GetPlayerPed(-1)
-- Radio Always Off
if(featureRadioAlwaysOff)then
if(featurePlayerRadio)then
SetMobileRadioEnabledDuringGameplay(false);
featurePlayerRadio = false;
end
if(not radioToggle)then
toggleRadio(playerPed)
end
radioToggle = true
else
if(radioToggle)then
toggleRadio(playerPed)
radioToggle = false
end
end
end
end)
-- Local Blip/Head Storage for removing on disconnect
local playersDB = {}
for i=0, maxPlayers, 1 do
playersDB[i] = {}
end
--[[----------------------------------------------------------------------
*
* Head Display Stuff
*
------------------------------------------------------------------------]]
-- Remove Head Display from entity
function clearPlayerHead(id)
if(playersDB[id].headId ~= nil and IsMpGamerTagActive(playersDB[id].headId))then
RemoveMpGamerTag(playersDB[id].headId)
end
end
-- Create Head Display for entity
function createPlayerHead(id,ped)
if(featurePlayerHeadDisplay)then
headId = CreateMpGamerTag(ped, GetPlayerName(id), false, false, "", false )
wantedLvl = GetPlayerWantedLevel(id)
-- Wanted Levels
if wantedLvl > 0 then
SetMpGamerTagWantedLevel(headId, wantedLvl)
SetMpGamerTagVisibility(headId, 7, true)
else
SetMpGamerTagWantedLevel(headId, 0)
SetMpGamerTagVisibility(headId, 7, false)
end
-- Speaking Icon
if NetworkIsPlayerTalking(id)then
SetMpGamerTagVisibility(headId, 9, true)
else
SetMpGamerTagVisibility(headId, 9, false)
end
playersDB[id].headId = headId
playersDB[id].wantedLvl = wantedLvl
else
if(playersDB[id].headId ~= nil and IsMpGamerTagActive(playersDB[id].headId))then
RemoveMpGamerTag(playersDB[id].headId)
end
playersDB[id].headId = nil
playersDB[id].wantedLvl = nil
end
end
--[[----------------------------------------------------------------------
*
* Blip Display Stuff
*
------------------------------------------------------------------------]]
-- Remove the player blip from the entity
function clearPlayerBlip(id)
if(playersDB[id].blip ~= nil)then
RemoveBlip(playersDB[id].blip)
end
end
-- Which sprite should be displayed for current vehicle?
function getVehicleSpriteId(veh)
vehClass = GetVehicleClass(veh)
vehModel = GetEntityModel(veh)
local sprite = 1
if(vehClass == 8 or vehClass == 13)then
sprite = 226 -- Bikes
elseif(vehClass == 14)then
sprite = 427 -- Boat
elseif(vehClass == 15)then
sprite = 422 -- Jet
elseif(vehClass == 16)then
sprite = 423 -- Planes
elseif(vehClass == 19)then
sprite = 421 -- Military
else
sprite = 225 -- Car
end
-- Model Specific Icons override Class.
if(vehModel == GetHashKey("besra") or vehModel == GetHashKey("hydra") or vehModel == GetHashKey("lazer"))then
sprite = 424
elseif(vehModel == GetHashKey("insurgent") or vehModel == GetHashKey("insurgent2") or vehModel == GetHashKey("limo2"))then
sprite = 426
elseif(vehModel == GetHashKey("rhino"))then
sprite = 421
end
return sprite
end
-- Create/remove the blip from the player
function createPlayerBlip(id,ped,blip)
if(featurePlayerBlips)then
if(not DoesBlipExist(blip))then -- Create Generic Blip
blip = AddBlipForEntity(ped)
SetBlipSprite(blip, 1)
Citizen.InvokeNative( 0x5FBCA48327B914DF, blip, true)
end
-- Update Blip Information
veh = GetVehiclePedIsIn(ped, false)
blipSprite = GetBlipSprite(blip)
if not GetEntityHealth(ped) then -- Dead
if blipSprite ~= 274 then
SetBlipSprite(blip,274)
Citizen.InvokeNative( 0x5FBCA48327B914DF, blip, false)
end
elseif IsPedInAnyVehicle(ped, false) then -- Inside a vehicle
local sprite = getVehicleSpriteId(veh)
if blipSprite ~= sprite then
SetBlipSprite(blip, sprite)
Citizen.InvokeNative(0x5FBCA48327B914DF, blip, false)
end
passengers = GetVehicleNumberOfPassengers(veh)
if passengers then
if not IsVehicleSeatFree(veh, -1)then
passengers = passengers + 1
end
ShowNumberOnBlip(blip,passengers)
else
HideNumberOnBlip(blip)
end
else -- On foot
HideNumberOnBlip(blip)
if blipSprite ~= 1 then
SetBlipSprite(blip, 1)
Citizen.InvokeNative(0x5FBCA48327B914DF, blip, true)
end
end
SetBlipRotation(blip, math.ceil(GetEntityHeading(veh)))
-- Show Blip Names on Pause Map?
if(featurePlayerBlipNames)then
SetBlipNameToPlayerName(blip, id)
else
BeginTextCommandSetBlipName("STRING")
AddTextComponentString("Player")
EndTextCommandSetBlipName(blip)
end
SetBlipScale(blip, 0.85)
-- Blip Alphas
if IsPauseMenuActive() then
SetBlipAlpha(blip, 255)
else
x1, y1 = table.unpack(GetEntityCoords(GetPlayerPed(-1), true ))
x2, y2 = table.unpack(GetEntityCoords(GetPlayerPed(id), true ))
distance = ( math.floor( math.abs( math.sqrt( ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ) ) ) / -1 ) ) + 900
-- Probably a way easier way to do this but whatever im an idiot -- Credits @Scammer ^
if distance < 0 then
distance = 0
elseif distance > 255 then
distance = 255
end
SetBlipAlpha(blip, distance)
end
playersDB[id].ped = ped
playersDB[id].blip = blip
else
clearPlayerBlip(id)
end
end
-- Faster Method to remove Blips/Names from players who disconnect.
RegisterNetEvent( 'mellotrainer:playerLeft' )
AddEventHandler( 'mellotrainer:playerLeft', function( person )
Citizen.Trace(person.source)
clearPlayerBlip(person.source)
clearPlayerHead(person.source)
playersDB[person.source] = "skip"
-- 30 second skip period to ensure the name/blip don't reappear for a disconnected player.
Wait(30000)
-- After 30 seconds if the source is still active it will recreate blips assuming its a new person.
playersDB[person.source] = {}
end )
-- Blip System
Citizen.CreateThread(function()
while true do
Wait(1)
-- Show Blips/Head Names
for id = 0, maxPlayers do
if NetworkIsPlayerActive(id) and GetPlayerPed(id) ~= GetPlayerPed(-1) and playersDB[id] ~= "skip" then
ped = GetPlayerPed(id)
blip = GetBlipFromEntity(ped)
-- Create Blip/Head depending on feature Toggles
createPlayerHead(id,ped)
createPlayerBlip(id,ped,blip)
elseif(playersDB[id].ped ~= nil)then
-- Remove Blip/Head depending on feature Toggles
clearPlayerHead(id)
clearPlayerBlip(id)
-- Reset the playersDB
playersDB[id] = {}
end
end
end
end)