forked from MrEvilGamer/qb-pizzajob
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.lua
493 lines (465 loc) · 14.7 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
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
Config = {}
Config.Zones = {
Vehicle = {
Pos = {x = 538.17, y = 101.61, z = 95.63}
},
Spawn = {
Pos = {x = 548.39, y = 125.23, z = 96.47, h = 70.0},
Heading = 70.0
},
}
RegisterNetEvent('QBCore:Client:OnPlayerLoaded')
AddEventHandler('QBCore:Client:OnPlayerLoaded', function()
isLoggedIn = true
PlayerData = QBCore.Functions.GetPlayerData()
end)
local InService = false
local Hired = true
local BlipSell = nil
local BlipEnd = nil
local BlipCancel = nil
local TargetPos = nil
local HasPizza = false
local NearVan = false
local LastGoal = 0
local DeliveriesCount = 0
local Delivered = false
local xxx = nil
local yyy = nil
local zzz = nil
local Blipy = {}
local JuzBlip = false
local PizzaDelivered = false
local ownsVan = false
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
if not JuzBlip then
Blipy['praca'] = AddBlipForCoord(538.17, 101.61, 96.53)
SetBlipSprite(Blipy['praca'], 488)
SetBlipDisplay(Blipy['praca'], 4)
SetBlipScale(Blipy['praca'], 0.8)
SetBlipAsShortRange(Blipy['praca'], true)
BeginTextCommandSetBlipName("STRING")
AddTextComponentString('Pizza Boy')
EndTextCommandSetBlipName(Blipy['praca'])
JuzBlip = true
end
end
end)
function PullOutVehicle()
if ownsVan == true then
QBCore.Functions.Notify("You already have a van! Go and collect it or end your job.", "error")
elseif ownsVan == false then
coords = Config.Zones.Spawn.Pos
QBCore.Functions.SpawnVehicle('blazer3', function(veh)
SetVehicleNumberPlateText(veh, "PIZZA"..tostring(math.random(1000, 9999)))
SetEntityHeading(veh, coords.h)
exports['LegacyFuel']:SetFuel(veh, 100.0)
TaskWarpPedIntoVehicle(GetPlayerPed(-1), veh, -1)
TriggerEvent("vehiclekeys:client:SetOwner", GetVehicleNumberPlateText(veh))
SetVehicleEngineOn(veh, true, true)
plaquevehicule = GetVehicleNumberPlateText(veh)
end, coords, true)
InService = true
DrawTarget()
AddCancelBlip()
ownsVan = true
TriggerServerEvent("qb-pizzajob:TakeDeposit")
end
end
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
if Hired then
local ped = GetPlayerPed(-1)
local pos = GetEntityCoords(ped)
local dist = GetDistanceBetweenCoords(pos, Config.Zones.Vehicle.Pos.x, Config.Zones.Vehicle.Pos.y, Config.Zones.Vehicle.Pos.z, true)
if dist <= 2.5 then
local GaragePos = {
["x"] = Config.Zones.Vehicle.Pos.x,
["y"] = Config.Zones.Vehicle.Pos.y,
["z"] = Config.Zones.Vehicle.Pos.z + 1
}
DrawText3Ds(GaragePos["x"],GaragePos["y"],GaragePos["z"], "Press [~g~E~s~] to start work as a Pizza Boy")
if dist <= 3.0 then
if IsControlJustReleased(0, 38) then
PullOutVehicle()
end
end
end
end
end
end)
function DrawTarget()
local RandomPoint = math.random(1, 21)
if DeliveriesCount == 4 then
QBCore.Functions.Notify("All Pizzas have been delivered","success")
RemoveCancelBlip()
SetBlipRoute(BlipSell, false)
AddFinnishBlip()
Delivered = true
xxx = nil
yyy = nil
zzz = nil
else
local pizza = 4 - DeliveriesCount
if pizza == 1 then
QBCore.Functions.Notify("You have one pizza","success")
else
if pizza == 4 then
pizza = 'Four'
elseif pizza == 3 then
pizza = 'Three'
elseif pizza == 2 then
pizza = 'Two'
end
QBCore.Functions.Notify("You have "..pizza.." pizzas","success")
end
if LastGoal == RandomPoint then
DrawTarget()
else
if RandomPoint == 1 then
xxx =3.45
yyy =36.74
zzz =71.53
LastGoal = 1
elseif RandomPoint == 2 then
xxx =-273.58
yyy =28.33
zzz =54.75
LastGoal = 2
elseif RandomPoint == 3 then
xxx =-345.05
yyy =18.23
zzz =47.85
LastGoal = 3
elseif RandomPoint == 4 then
xxx =-549.89
yyy =37.7
zzz =43.6
LastGoal = 4
elseif RandomPoint == 5 then
xxx =-842.22
yyy =-25.07
zzz =40.39
LastGoal = 5
elseif RandomPoint == 6 then
xxx =-902.37
yyy =191.56
zzz =69.44
LastGoal = 6
elseif RandomPoint == 7 then
xxx =-1116.81
yyy =304.54
zzz =66.52
LastGoal = 7
elseif RandomPoint == 8 then
xxx =-637.01
yyy =180.39
zzz =61.75
LastGoal = 8
elseif RandomPoint == 9 then
xxx =-1905.66
yyy =252.95
zzz =86.45
LastGoal = 9
elseif RandomPoint == 10 then
xxx =-1961.23
yyy =212.01
zzz =86.8
LastGoal = 10
elseif RandomPoint == 11 then -- zrobione
xxx =-1447.51
yyy =-537.6
zzz =34.74
LastGoal = 11
elseif RandomPoint == 12 then
xxx =126.678
yyy =-1929.798
zzz =21.382
LastGoal = 12
elseif RandomPoint == 13 then
xxx =-5.0513
yyy =-1872.062
zzz =24.151
LastGoal = 13
elseif RandomPoint == 14 then
xxx =-80.589
yyy =-1608.237
zzz =31.480
LastGoal = 14
elseif RandomPoint == 15 then
xxx =-38.55
yyy =-1108.92
zzz =26.44
LastGoal = 15
elseif RandomPoint == 16 then
xxx =344.731
yyy =-205.027
zzz =58.019
LastGoal = 16
elseif RandomPoint == 17 then
xxx =340.956
yyy =-214.876
zzz =58.019
LastGoal = 17
elseif RandomPoint == 18 then
xxx =337.132
yyy =-224.712
zzz =58.019
LastGoal = 18
elseif RandomPoint == 19 then
xxx =331.373
yyy =-225.865
zzz =58.019
LastGoal = 19
elseif RandomPoint == 20 then
xxx =337.158
yyy =-224.729
zzz =54.221
LastGoal = 20
elseif RandomPoint == 21 then
xxx =-386.907
yyy =504.108
zzz =120.412
LastGoal = 21
end
AddObjBlip(TargetPos)
QBCore.Functions.Notify("Take the Pizza to the customer","success")
end
end
end
function AddObjBlip(TargetPos)
Blipy['obj'] = AddBlipForCoord(xxx, yyy, zzz)
SetBlipRoute(Blipy['obj'], true)
BeginTextCommandSetBlipName("STRING")
AddTextComponentString('Customer')
EndTextCommandSetBlipName(Blipy['obj'])
end
-- Blip anulowania pracy
function AddCancelBlip()
Blipy['cancel'] = AddBlipForCoord(558.52, 121.27, 97.37)
SetBlipColour(Blipy['cancel'], 59)
BeginTextCommandSetBlipName("STRING")
AddTextComponentString('cancel orders')
EndTextCommandSetBlipName(Blipy['cancel'])
end
function AddFinnishBlip()
Blipy['end'] = AddBlipForCoord(571.25, 116.78, 97.36)
SetBlipColour(Blipy['end'], 2)
SetBlipRoute(Blipy['end'], true)
BeginTextCommandSetBlipName("STRING")
AddTextComponentString('finnish job')
EndTextCommandSetBlipName(Blipy['end'])
end
function RemoveBlipObj()
RemoveBlip(Blipy['obj'])
end
function RemoveCancelBlip()
RemoveBlip(Blipy['cancel'])
end
function RemoveAllBlips()
RemoveBlip(Blipy['obj'])
RemoveBlip(Blipy['cancel'])
RemoveBlip(Blipy['end'])
end
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
local ped = GetPlayerPed(-1)
local pos = GetEntityCoords(ped)
local dist = GetDistanceBetweenCoords(pos, xxx, yyy, zzz, true)
if dist <= 20.0 and Hired and (not HasPizza) then
local DeliveryPoint = {
["x"] = xxx,
["y"] = yyy,
["z"] = zzz
}
DrawText3Ds(DeliveryPoint["x"],DeliveryPoint["y"],DeliveryPoint["z"], "Take ~y~Pizza~s~ from ~b~blazer3~s~!")
local Vehicle = GetClosestVehicle(pos, 6.0, 0, 70)
if IsVehicleModel(Vehicle, GetHashKey('blazer3')) then
local VehPos = GetEntityCoords(Vehicle)
local distance = GetDistanceBetweenCoords(pos, VehPos, true)
DrawText3Ds(VehPos.x,VehPos.y,VehPos.z, "Press [~g~E~s~] to pull out ~y~Pizza")
if dist >= 4 and distance <= 5 then
NearVan = true
end
end
elseif dist <= 25 and HasPizza and Hired then
local DeliveryPoint = {
["x"] = xxx,
["y"] = yyy,
["z"] = zzz
}
DrawText3Ds(DeliveryPoint["x"],DeliveryPoint["y"],DeliveryPoint["z"], "Press [~g~E~s~] to deliver ~y~Pizza")
if dist <= 3 then
if IsControlJustReleased(0, 38) then
TakePizza()
DeliverPizza()
end
end
end
end
end)
Citizen.CreateThread(function()
while true do
Citizen.Wait(10)
if (not HasPizza) and NearVan then
if IsControlJustReleased(0, 38) then
TakePizza()
NearVan = false
end
end
end
end)
function loadAnimDict(dict)
while ( not HasAnimDictLoaded(dict)) do
RequestAnimDict(dict)
Citizen.Wait(0)
end
end
function TakePizza()
local player = GetPlayerPed(-1)
if not IsPedInAnyVehicle(player, false) then
local ad = "anim@heists@box_carry@"
local prop_name = 'prop_pizza_box_01'
if ( DoesEntityExist( player ) and not IsEntityDead( player )) then
loadAnimDict( ad )
if HasPizza then
TaskPlayAnim( player, ad, "exit", 3.0, 1.0, -1, 49, 0, 0, 0, 0 )
DetachEntity(prop, 1, 1)
DeleteObject(prop)
Wait(1000)
ClearPedSecondaryTask(PlayerPedId())
HasPizza = false
else
local x,y,z = table.unpack(GetEntityCoords(player))
prop = CreateObject(GetHashKey(prop_name), x, y, z+0.2, true, true, true)
AttachEntityToEntity(prop, player, GetPedBoneIndex(player, 60309), 0.2, 0.08, 0.2, -45.0, 290.0, 0.0, true, true, false, true, 1, true)
TaskPlayAnim( player, ad, "idle", 3.0, -8, -1, 63, 0, 0, 0, 0 )
HasPizza = true
end
end
end
end
function DeliverPizza()
if not PizzaDelivered then
PizzaDelivered = true
DeliveriesCount = DeliveriesCount + 1
RemoveBlipObj()
SetBlipRoute(BlipSell, false)
HasPizza = false
NextDelivery()
TriggerServerEvent('qb-mining:pizza')
Citizen.Wait(2500)
PizzaDelivered = false
end
end
function NextDelivery()
TriggerServerEvent('qb-pizzajob:Payment')
Citizen.Wait(300)
DrawTarget()
end
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
local ped = GetPlayerPed(-1)
local pos = GetEntityCoords(ped)
local DistanceFromEndZone = GetDistanceBetweenCoords(pos, 571.25, 116.78, 97.36, true)
local DistanceFromCancelZone = GetDistanceBetweenCoords(pos, 558.52, 121.27, 97.37, true)
if InService then
if Delivered then
if DistanceFromEndZone <= 2.5 then
local endPoint = { --x = 571.25, y = 116.78, z = 97.36
["x"] = 571.25,
["y"] = 116.78,
["z"] = 97.36
}
DrawText3Ds(endPoint["x"],endPoint["y"],endPoint["z"], "Press [~g~E~s~] to ~r~complete~s~ work")
if DistanceFromEndZone <= 7 then
if IsControlJustReleased(0, 38) then
QBCore.Functions.Notify("The work is finished! Rest a while, the next orders are already waiting!", "success")
EndOfWork()
end
end
end
else
if DistanceFromCancelZone <= 2.5 then
local cancel = { --x = 558.52, y = 121.27, z = 97.37
["x"] = 558.52,
["y"] = 121.27,
["z"] = 97.37
}
DrawText3Ds(cancel["x"],cancel["y"],cancel["z"], "Press [~g~E~s~] to ~r~cancel~s~ orders")
if DistanceFromCancelZone <= 7 then
if IsControlJustReleased(0, 38) then
QBCore.Functions.Notify("Orders Canceled!", "error")
EndOfWork()
end
end
end
end
end
end
end)
function EndOfWork()
RemoveAllBlips()
local ped = GetPlayerPed(-1)
if IsPedInAnyVehicle(ped, false) then
local Van = GetVehiclePedIsIn(ped, false)
if IsVehicleModel(Van, GetHashKey('blazer3')) then
QBCore.Functions.DeleteVehicle(Van)
if Delivered == true then
TriggerServerEvent("qb-pizzajob:ReturnDeposit", 'end')
end
InService = false
BlipSell = nil
BlipEnd = nil
BlipCancel = nil
TargetPos = nil
HasPizza = false
LastGoal = nil
DeliveriesCount = 0
xxx = nil
yyy = nil
zzz = nil
ownsVan = false
Delivered = false
else
QBCore.Functions.Notify("You must return to pizza blazer3!", "error")
QBCore.Functions.Notify("If you lost the blazer3 cancel the job on foot", "error")
end
else
InService = false
BlipSell = nil
BlipEnd = nil
BlipCancel = nil
TargetPos = nil
HasPizza = false
LastGoal = nil
DeliveriesCount = 0
xxx = nil
yyy = nil
zzz = nil
ownsVan = false
Delivered = false
end
end
----------------------
-- 3D text function --
----------------------
DrawText3Ds = function(x,y,z, text)
local onScreen,_x,_y=World3dToScreen2d(x,y,z)
local factor = #text / 370
local px,py,pz=table.unpack(GetGameplayCamCoords())
SetTextScale(0.35, 0.35)
SetTextFont(4)
SetTextProportional(1)
SetTextColour(255, 255, 255, 215)
SetTextEntry("STRING")
SetTextCentre(1)
AddTextComponentString(text)
DrawText(_x,_y)
DrawRect(_x,_y + 0.0125, 0.015 + factor, 0.03, 0, 0, 0, 120)
end