-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathcoke.lua
493 lines (414 loc) · 13.9 KB
/
coke.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
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
local QBCore = exports['qb-core']:GetCoreObject()
local spawnedCocaLeaf = 0
local CocaPlants = {}
local isPickingUp, isProcessing, CWarehouse = false, false, false
Citizen.CreateThread(function()
while true do
Citizen.Wait(10)
local coords = GetEntityCoords(PlayerPedId())
if GetDistanceBetweenCoords(coords, Config.CircleZones.CokeField.coords, true) < 50 then
SpawnCocaPlants()
Citizen.Wait(500)
else
Citizen.Wait(500)
end
end
end)
RegisterNetEvent('qb-drugprocessing:ProcessCocaFarm')
AddEventHandler('qb-drugprocessing:ProcessCocaFarm', function()
local coords = GetEntityCoords(PlayerPedId(source))
if GetDistanceBetweenCoords(coords, Config.CircleZones.CokeProcessing.coords, true) < 5 then
if not isProcessing then
QBCore.Functions.TriggerCallback('QBCore:HasItem', function(result)
if result then
print('You have this item SA')
hasitem1 = true
else
QBCore.Functions.Notify('You lack the correct item...', 'error')
end
end, 'coca_leaf')
Citizen.Wait(1000) -- BUFFER
QBCore.Functions.TriggerCallback('QBCore:HasItem', function(result)
if result and hasitem1 then
print('You have this item HA')
ProcessCoke()
else
QBCore.Functions.Notify('You lack the correct item...', 'error')
end
end, 'trimming_scissors')
end
end
end)
RegisterNetEvent('qb-drugprocessing:ProcessCocaPowder')
AddEventHandler('qb-drugprocessing:ProcessCocaPowder', function()
local coords = GetEntityCoords(PlayerPedId(source))
local amount = 10
local amount2 = 5
if GetDistanceBetweenCoords(coords, Config.CircleZones.CokePowder.coords, true) < 5 then
if not isProcessing then
QBCore.Functions.TriggerCallback('QBCore:HasItem', function(result)
if result then
print('You have this item SA')
hasitem1 = true
end
end, 'coke', 10)
Citizen.Wait(1000)
if hasitem1 == true then
QBCore.Functions.TriggerCallback('QBCore:HasItem', function(result)
if result then
print('You have this item SA')
hasitem2 = true
end
end, 'bakingsoda', 5)
Citizen.Wait(1000) -- BUFFER
if hasitem2 == true then
QBCore.Functions.TriggerCallback('QBCore:HasItem', function(result)
if result and hasitem2 then
print('You have this item HA')
CutCokePowder()
hasitem1 = false
hasitem2 = false
end
end, 'finescale')
else
QBCore.Functions.Notify('You need ' ..amount2.. ' Baking Soda' , 'error')
Citizen.Wait(1000)
QBCore.Functions.Notify('Get The Right Items and Come Back', 'error')
end
else
QBCore.Functions.Notify('You need ' ..amount.. ' Piles of Cocaine' , 'error')
Citizen.Wait(1000)
QBCore.Functions.Notify('Get The Right Items and Come Back', 'error')
end
end
else
QBCore.Functions.Notify('You are already processing something', 'error')
end
end)
RegisterNetEvent('qb-drugprocessing:ProcessBricks')
AddEventHandler('qb-drugprocessing:ProcessBricks', function()
local coords = GetEntityCoords(PlayerPedId(source))
local amount = 4
if GetDistanceBetweenCoords(coords, Config.CircleZones.CokeBrick.coords, true) < 5 then
if not isProcessing then
QBCore.Functions.TriggerCallback('QBCore:HasItem', function(result)
if result then
print('You have this item SA')
hasitem1 = true
end
end, 'coke_small_brick', 4)
Citizen.Wait(1000)
if hasitem1 == true then
QBCore.Functions.TriggerCallback('QBCore:HasItem', function(result)
if result and hasitem1 then
print('You have this item HA')
ProcessBricks()
hasitem1 = false
end
end, 'finescale')
else
QBCore.Functions.Notify('You need ' ..amount.. ' Small Bricks' , 'error')
Citizen.Wait(1000)
QBCore.Functions.Notify('Get The Right Items and Come Back', 'error')
end
end
else
QBCore.Functions.Notify('You are already processing something', 'error')
end
end)
RegisterNetEvent('qb-drugprocessing:EnterCWarehouse')
AddEventHandler('qb-drugprocessing:EnterCWarehouse', function()
local ped = PlayerPedId()
local pos = GetEntityCoords(ped)
local dist = #(pos - vector3(Config.CokeLab["enter"].coords.x, Config.CokeLab["enter"].coords.y, Config.CokeLab["enter"].coords.z))
if dist < 2 then
QBCore.Functions.TriggerCallback('QBCore:HasItem', function(result)
if result then
print('You have the key')
EnterCWarehouse()
print('Entering Warehouse')
else
print('No Key Stupid')
QBCore.Functions.Notify('You lack the required items', 'error')
end
end, 'cocainekey')
end
end)
RegisterNetEvent('qb-drugprocessing:ExitCWarehouse')
AddEventHandler('qb-drugprocessing:ExitCWarehouse', function()
local ped = PlayerPedId()
local pos = GetEntityCoords(ped)
local dist = #(pos - vector3(Config.CokeLab["exit"].coords.x, Config.CokeLab["exit"].coords.y, Config.CokeLab["exit"].coords.z))
if dist < 2 then
ExitCWarehouse()
print('Exiting Warehouse')
end
end)
function EnterCWarehouse()
local ped = PlayerPedId()
OpenDoorAnimation()
CWarehouse = true
Citizen.Wait(500)
DoScreenFadeOut(250)
Citizen.Wait(250)
SetEntityCoords(ped, Config.CokeLab["exit"].coords.x, Config.CokeLab["exit"].coords.y, Config.CokeLab["exit"].coords.z - 0.98)
SetEntityHeading(ped, Config.CokeLab["exit"].coords.w)
Citizen.Wait(1000)
DoScreenFadeIn(250)
end
function ExitCWarehouse()
local ped = PlayerPedId()
OpenDoorAnimation()
CWarehouse = true
Citizen.Wait(500)
DoScreenFadeOut(250)
Citizen.Wait(250)
SetEntityCoords(ped, Config.CokeLab["enter"].coords.x, Config.CokeLab["enter"].coords.y, Config.CokeLab["enter"].coords.z - 0.98)
SetEntityHeading(ped, Config.CokeLab["enter"].coords.w)
Citizen.Wait(1000)
DoScreenFadeIn(250)
CWarehouse = false
end
function ProcessCoke()
isProcessing = true
local playerPed = PlayerPedId()
TaskStartScenarioInPlace(playerPed, "PROP_HUMAN_PARKING_METER", 0, true)
QBCore.Functions.Progressbar("search_register", "Processing Leaves...", 15000, false, true, {
disableMovement = true,
disableCarMovement = true,
disableMouse = false,
disableCombat = true,
}, {}, {}, {}, function()
TriggerServerEvent('qb-drugtrafficking:processCocaLeaf')
local timeLeft = Config.Delays.CokeProcessing / 1000
while timeLeft > 0 do
Citizen.Wait(1000)
timeLeft = timeLeft - 1
if GetDistanceBetweenCoords(GetEntityCoords(playerPed), Config.CircleZones.CokeProcessing.coords, false) > 4 then
TriggerServerEvent('qb-drugtrafficking:cancelProcessing')
break
end
end
ClearPedTasks(PlayerPedId())
end, function()
ClearPedTasks(PlayerPedId())
end)
isProcessing = false
end
function CutCokePowder()
isProcessing = true
local playerPed = PlayerPedId()
TaskStartScenarioInPlace(playerPed, "PROP_HUMAN_PARKING_METER", 0, true)
QBCore.Functions.Progressbar("search_register", "Cutting Cocaine...", 15000, false, true, {
disableMovement = true,
disableCarMovement = true,
disableMouse = false,
disableCombat = true,
}, {}, {}, {}, function()
TriggerServerEvent('qb-drugtrafficking:processCocaPowder')
local timeLeft = Config.Delays.CokeProcessing / 1000
while timeLeft > 0 do
Citizen.Wait(1000)
timeLeft = timeLeft - 1
if GetDistanceBetweenCoords(GetEntityCoords(playerPed), Config.CircleZones.CokeProcessing.coords, false) > 4 then
TriggerServerEvent('qb-drugtrafficking:cancelProcessing')
break
end
end
ClearPedTasks(PlayerPedId())
end, function()
ClearPedTasks(PlayerPedId())
end)
isProcessing = false
end
function ProcessBricks()
isProcessing = true
local playerPed = PlayerPedId()
TaskStartScenarioInPlace(playerPed, "PROP_HUMAN_PARKING_METER", 0, true)
QBCore.Functions.Progressbar("search_register", "Bricking Up Cocaine...", 15000, false, true, {
disableMovement = true,
disableCarMovement = true,
disableMouse = false,
disableCombat = true,
}, {}, {}, {}, function()
TriggerServerEvent('qb-drugtrafficking:processCocaBrick')
local timeLeft = Config.Delays.CokeProcessing / 1000
while timeLeft > 0 do
Citizen.Wait(1000)
timeLeft = timeLeft - 1
if GetDistanceBetweenCoords(GetEntityCoords(playerPed), Config.CircleZones.CokeBrick.coords, false) > 4 then
TriggerServerEvent('qb-drugtrafficking:cancelProcessing')
break
end
end
ClearPedTasks(PlayerPedId())
end, function()
ClearPedTasks(PlayerPedId())
end)
isProcessing = false
end
RegisterNetEvent('qb-drugprocessing:pickCocaLeaves')
AddEventHandler('qb-drugprocessing:pickCocaLeaves', function()
local playerPed = PlayerPedId()
local coords = GetEntityCoords(playerPed)
local nearbyObject, nearbyID
for i=1, #CocaPlants, 1 do
if GetDistanceBetweenCoords(coords, GetEntityCoords(CocaPlants[i]), false) < 1 then
nearbyObject, nearbyID = CocaPlants[i], i
end
end
if nearbyObject and IsPedOnFoot(playerPed) then
if not isPickingUp then
isPickingUp = true
TaskStartScenarioInPlace(playerPed, 'world_human_gardener_plant', 0, false)
QBCore.Functions.Progressbar("search_register", "Picking cocaine leaves..", 10000, false, true, {
disableMovement = true,
disableCarMovement = true,
disableMouse = false,
disableCombat = true,
}, {}, {}, {}, function() -- Done
ClearPedTasks(PlayerPedId())
SetEntityAsMissionEntity(nearbyObject, false, true)
DeleteObject(nearbyObject)
table.remove(CocaPlants, nearbyID)
spawnedCocaLeaf = spawnedCocaLeaf - 1
TriggerServerEvent('qb-drugtrafficking:pickedUpCocaLeaf')
end, function()
ClearPedTasks(PlayerPedId())
end)
isPickingUp = false
end
else
Citizen.Wait(500)
end
end)
--[[Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
local playerPed = PlayerPedId()
local coords = GetEntityCoords(playerPed)
local nearbyObject, nearbyID
for i=1, #CocaPlants, 1 do
if GetDistanceBetweenCoords(coords, GetEntityCoords(CocaPlants[i]), false) < 1 then
nearbyObject, nearbyID = CocaPlants[i], i
end
end
if nearbyObject and IsPedOnFoot(playerPed) then
if not isPickingUp then
QBCore.Functions.Draw2DText(0.5, 0.88, 'Press [~g~ E ~w~] to pick cocaine leaves', 0.5)
end
if IsControlJustReleased(0, 38) and not isPickingUp then
isPickingUp = true
TaskStartScenarioInPlace(playerPed, 'world_human_gardener_plant', 0, false)
QBCore.Functions.Progressbar("search_register", "Picking cocaine leaves..", 10000, false, true, {
disableMovement = true,
disableCarMovement = true,
disableMouse = false,
disableCombat = true,
}, {}, {}, {}, function() -- Done
ClearPedTasks(PlayerPedId())
SetEntityAsMissionEntity(nearbyObject, false, true)
DeleteObject(nearbyObject)
table.remove(CocaPlants, nearbyID)
spawnedCocaLeaf = spawnedCocaLeaf - 1
TriggerServerEvent('qb-drugtrafficking:pickedUpCocaLeaf')
end, function()
ClearPedTasks(PlayerPedId())
end)
isPickingUp = false
end
else
Citizen.Wait(500)
end
end
end)]]--
AddEventHandler('onResourceStop', function(resource)
if resource == GetCurrentResourceName() then
for k, v in pairs(CocaPlants) do
SetEntityAsMissionEntity(v, false, true)
DeleteObject(v)
end
end
end)
function SpawnCocaPlants()
while spawnedCocaLeaf < 15 do
Citizen.Wait(0)
local weedCoords = GenerateCocaLeafCoords()
RequestModel(`mw_coke_plant`)
while not HasModelLoaded(`mw_coke_plant`) do
Wait(100)
end
local obj = CreateObject(`mw_coke_plant`, weedCoords.x, weedCoords.y, weedCoords.z, true, true, false)
PlaceObjectOnGroundProperly(obj)
FreezeEntityPosition(obj, true)
table.insert(CocaPlants, obj)
spawnedCocaLeaf = spawnedCocaLeaf + 1
end
end
function ValidateCocaLeafCoord(plantCoord)
if spawnedCocaLeaf > 0 then
local validate = true
for k, v in pairs(CocaPlants) do
if GetDistanceBetweenCoords(plantCoord, GetEntityCoords(v), true) < 5 then
validate = false
end
end
if GetDistanceBetweenCoords(plantCoord, Config.CircleZones.CokeField.coords, false) > 50 then
validate = false
end
return validate
else
return true
end
end
function GenerateCocaLeafCoords()
while true do
Citizen.Wait(1)
local weedCoordX, weedCoordY
math.randomseed(GetGameTimer())
local modX = math.random(-35, 35)
Citizen.Wait(100)
math.randomseed(GetGameTimer())
local modY = math.random(-35, 35)
weedCoordX = Config.CircleZones.CokeField.coords.x + modX
weedCoordY = Config.CircleZones.CokeField.coords.y + modY
local coordZ = GetCoordZCoke(weedCoordX, weedCoordY)
local coord = vector3(weedCoordX, weedCoordY, coordZ)
if ValidateCocaLeafCoord(coord) then
return coord
end
end
end
function GetCoordZCoke(x, y)
local groundCheckHeights = { 1.0, 25.0, 50.0, 73.0, 74.0, 75.0, 76.0, 77.0, 78.0, 79.0, 80.0 }
for i, height in ipairs(groundCheckHeights) do
local foundGround, z = GetGroundZFor_3dCoord(x, y, height)
if foundGround then
return z
end
end
return 77
end
function LoadAnimationDict(dict)
RequestAnimDict(dict)
while not HasAnimDictLoaded(dict) do
RequestAnimDict(dict)
Citizen.Wait(1)
end
end
function OpenDoorAnimation()
local ped = PlayerPedId()
LoadAnimationDict("anim@heists@keycard@")
TaskPlayAnim(ped, "anim@heists@keycard@", "exit", 5.0, 1.0, -1, 16, 0, 0, 0, 0)
Citizen.Wait(400)
ClearPedTasks(ped)
end
RegisterCommand('propfix', function()
for k, v in pairs(GetGamePool('CObject')) do
if IsEntityAttachedToEntity(PlayerPedId(), v) then
SetEntityAsMissionEntity(v, true, true)
DeleteObject(v)
DeleteEntity(v)
end
end
end)