-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathcl_pizzajob.lua
373 lines (344 loc) · 12.9 KB
/
cl_pizzajob.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
local Config = lib.require('config')
local isHired, holdingPizza, pizzaDelivered, activeOrder = false, false, false, false
local pizzaProp, pizzaBoss, startZone, pizzaCar, currZone
local oxtarget = GetResourceState('ox_target') == 'started'
local pizzajobBlip = AddBlipForCoord(vec3(Config.BossCoords.x, Config.BossCoords.y, Config.BossCoords.z))
SetBlipSprite(pizzajobBlip, 267)
SetBlipAsShortRange(pizzajobBlip, true)
SetBlipScale(pizzajobBlip, 0.6)
SetBlipColour(pizzajobBlip, 2)
BeginTextCommandSetBlipName('STRING')
AddTextComponentString('Pizza Job')
EndTextCommandSetBlipName(pizzajobBlip)
local function doEmote(bool)
if bool then
local model = `prop_pizza_box_02`
lib.requestModel(model)
local coords = GetEntityCoords(cache.ped)
pizzaProp = CreateObject(model, coords.x, coords.y, coords.z, true, true, true)
AttachEntityToEntity(pizzaProp, cache.ped, GetPedBoneIndex(cache.ped, 28422), 0.0100,-0.1000, -0.1590, 20.0000007, 0.0, 0.0, true, true, false, true, 0, true)
lib.requestAnimDict('anim@heists@box_carry@')
TaskPlayAnim(cache.ped, 'anim@heists@box_carry@', 'idle', 5.0, 5.0, -1, 51, 0, 0, 0, 0)
SetModelAsNoLongerNeeded(model)
CreateThread(function()
while DoesEntityExist(pizzaProp) do
if not IsEntityPlayingAnim(cache.ped, 'anim@heists@box_carry@', 'idle', 3) then
TaskPlayAnim(cache.ped, 'anim@heists@box_carry@', 'idle', 5.0, 5.0, -1, 51, 0, 0, 0, 0)
end
Wait(1000)
end
RemoveAnimDict('anim@heists@box_carry@')
end)
else
if DoesEntityExist(pizzaProp) then
DetachEntity(cache.ped, true, false)
DeleteEntity(pizzaProp)
pizzaProp = nil
ClearPedTasksImmediately(cache.ped)
end
end
holdingPizza = bool
end
local function resetJob()
if oxtarget then
exports.ox_target:removeZone(currZone)
else
exports['qb-target']:RemoveZone(currZone)
end
currZone = nil
RemoveBlip(JobBlip)
isHired = false
holdingPizza = false
pizzaDelivered = false
activeOrder = false
if DoesEntityExist(pizzaBoss) then
if oxtarget then
exports.ox_target:removeLocalEntity(pizzaBoss, {'Start Work', 'Finish Work'})
else
exports['qb-target']:RemoveTargetEntity(pizzaBoss, {'Start Work', 'Finish Work'})
end
DeleteEntity(pizzaBoss)
pizzaBoss = nil
end
if startZone then startZone:remove() startZone = nil end
end
local function TakePizza()
if IsPedInAnyVehicle(cache.ped, false) or IsEntityDead(cache.ped) or holdingPizza then
return
end
local pos = GetEntityCoords(cache.ped)
if #(pos - vec3(currentDelivery.x, currentDelivery.y, currentDelivery.z)) >= 30.0 then
return DoNotification('You\'re not close enough to the customer\'s house!', 'error')
end
doEmote(true)
end
local function PullOutVehicle(netid, data)
pizzaCar = lib.waitFor(function()
if NetworkDoesEntityExistWithNetworkId(netid) then
return NetToVeh(netid)
end
end, 'Could not load entity in time.', 1000)
if pizzaCar == 0 then
return DoNotification('Error spawning the vehicle.', 'error')
end
SetVehicleNumberPlateText(pizzaCar, 'PIZZA'..tostring(math.random(1000, 9999)))
SetVehicleColours(pizzaCar, 111, 111)
SetVehicleDirtLevel(pizzaCar, 1)
handleVehicleKeys(pizzaCar)
SetVehicleEngineOn(pizzaCar, true, true)
isHired = true
NextDelivery(data)
Wait(500)
if Config.FuelScript.enable then
exports[Config.FuelScript.script]:SetFuel(pizzaCar, 100.0)
else
Entity(pizzaCar).state.fuel = 100
end
if oxtarget then
exports.ox_target:addEntity(netid, {
{
icon = 'fa-solid fa-pizza-slice',
label = 'Take Pizza',
onSelect = TakePizza,
canInteract = function()
return isHired and activeOrder and not holdingPizza
end,
distance = 2.5
},
{
icon = 'fa-solid fa-pizza-slice',
label = 'Return Pizza',
onSelect = function(entity)
doEmote(false)
end,
canInteract = function()
return isHired and activeOrder and holdingPizza
end,
distance = 2.5
},
})
else
exports['qb-target']:AddTargetEntity(pizzaCar, {
options = {
{
icon = 'fa-solid fa-pizza-slice',
label = 'Take Pizza',
action = TakePizza,
canInteract = function()
return isHired and activeOrder and not holdingPizza
end,
},
{
icon = 'fa-solid fa-pizza-slice',
label = 'Return Pizza',
action = function(entity)
doEmote(false)
end,
canInteract = function()
return isHired and activeOrder and holdingPizza
end,
},
},
distance = 2.5
})
end
end
local function finishWork()
local ped = cache.ped
local pos = GetEntityCoords(ped)
local finishspot = vec3(Config.BossCoords.x, Config.BossCoords.y, Config.BossCoords.z)
if #(pos - finishspot) > 10.0 or not isHired then return end
if oxtarget then
exports.ox_target:removeEntity(NetworkGetNetworkIdFromEntity(pizzaCar), {'Take Pizza', 'Return Pizza'})
else
exports['qb-target']:RemoveTargetEntity(pizzaCar, {'Take Pizza', 'Return Pizza'})
end
local success = lib.callback.await('randol_pizzajob:server:clockOut', false)
if success then
RemoveBlip(JobBlip)
doEmote(false)
isHired, activeOrder = false, false
DoNotification('You ended your shift.', 'success')
pizzaCar = nil
end
end
local function yeetPed()
if DoesEntityExist(pizzaBoss) then
if oxtarget then
exports.ox_target:removeLocalEntity(pizzaBoss, {'Start Work', 'Finish Work'})
else
exports['qb-target']:RemoveTargetEntity(pizzaBoss, {'Start Work', 'Finish Work'})
end
DeleteEntity(pizzaBoss)
pizzaBoss = nil
end
end
local function spawnPed()
if DoesEntityExist(pizzaBoss) then return end
lib.requestModel(Config.BossModel)
pizzaBoss = CreatePed(0, Config.BossModel, Config.BossCoords, false, false)
SetEntityAsMissionEntity(pizzaBoss)
SetPedFleeAttributes(pizzaBoss, 0, 0)
SetBlockingOfNonTemporaryEvents(pizzaBoss, true)
SetEntityInvincible(pizzaBoss, true)
FreezeEntityPosition(pizzaBoss, true)
lib.requestAnimDict('amb@world_human_leaning@female@wall@back@holding_elbow@idle_a')
TaskPlayAnim(pizzaBoss, 'amb@world_human_leaning@female@wall@back@holding_elbow@idle_a', 'idle_a', 8.0, 1.0, -1, 01, 0, 0, 0, 0)
RemoveAnimDict('amb@world_human_leaning@female@wall@back@holding_elbow@idle_a')
SetModelAsNoLongerNeeded(Config.BossModel)
if oxtarget then
exports.ox_target:addLocalEntity(pizzaBoss, {
{
icon = 'fa-solid fa-pizza-slice',
label = 'Start Work',
onSelect = function()
local netid, data = lib.callback.await('randol_pizzajob:server:spawnVehicle', false)
if netid and data then
PullOutVehicle(netid, data)
end
end,
canInteract = function()
return not isHired
end,
distance = 1.5,
},
{
icon = 'fa-solid fa-pizza-slice',
label = 'Finish Work',
onSelect = finishWork,
canInteract = function()
return isHired
end,
distance = 1.5,
},
})
else
exports['qb-target']:AddTargetEntity(pizzaBoss, {
options = {
{
icon = 'fa-solid fa-pizza-slice',
label = 'Start Work',
action = function()
local netid, data = lib.callback.await('randol_pizzajob:server:spawnVehicle', false)
if netid and data then
PullOutVehicle(netid, data)
end
end,
canInteract = function()
return not isHired
end,
},
{
icon = 'fa-solid fa-pizza-slice',
label = 'Finish Work',
action = finishWork,
canInteract = function() return isHired end,
},
},
distance = 1.5,
})
end
end
local function deliverPizza()
if holdingPizza and isHired and not pizzaDelivered then
lib.requestAnimDict('timetable@jimmy@doorknock@')
TaskPlayAnim(cache.ped, 'timetable@jimmy@doorknock@', 'knockdoor_idle', 3.0, 1.0, -1, 49, 0, true, true, true)
RemoveAnimDict('timetable@jimmy@doorknock@')
pizzaDelivered = true
if lib.progressCircle({
duration = 7000,
position = 'bottom',
label = 'Delivering pizza',
useWhileDead = true,
canCancel = false,
disable = { move = true, car = true, mouse = false, combat = true, },
}) then
local success, data = lib.callback.await('randol_pizzajob:server:Payment', false)
if not success then return end
RemoveBlip(JobBlip)
if oxtarget then
exports.ox_target:removeZone(currZone)
else
exports['qb-target']:RemoveZone(currZone)
end
currZone = nil
activeOrder = false
pizzaDelivered = false
doEmote(false)
if data then
NextDelivery(data)
end
end
else
DoNotification('You need the pizza from the car dummy.', 'error')
end
end
function NextDelivery(data)
if activeOrder then return end
currentDelivery = data.current
JobBlip = AddBlipForCoord(currentDelivery.x, currentDelivery.y, currentDelivery.z)
SetBlipSprite(JobBlip, 1)
SetBlipDisplay(JobBlip, 4)
SetBlipScale(JobBlip, 0.8)
SetBlipFlashes(JobBlip, true)
SetBlipAsShortRange(JobBlip, true)
SetBlipColour(JobBlip, 2)
SetBlipRoute(JobBlip, true)
SetBlipRouteColour(JobBlip, 2)
BeginTextCommandSetBlipName('STRING')
AddTextComponentSubstringPlayerName('Next Customer')
EndTextCommandSetBlipName(JobBlip)
if oxtarget then
currZone = exports.ox_target:addSphereZone({
coords = vec3(currentDelivery.x, currentDelivery.y, currentDelivery.z),
radius = 1.3,
debug = false,
options = {
{
icon = 'fa-solid fa-pizza-slice',
label = 'Deliver Pizza',
onSelect = deliverPizza,
distance = 1.5,
},
}
})
else
exports['qb-target']:AddCircleZone('deliverZone', vec3(currentDelivery.x, currentDelivery.y, currentDelivery.z), 1.3,{
name = 'deliverZone',
debugPoly = false,
useZ=true,
}, { options = {
{
icon = 'fa-solid fa-pizza-slice',
label = 'Deliver Pizza',
action = deliverPizza,
},},
distance = 1.5
})
currZone = 'deliverZone'
end
activeOrder = true
DoNotification('You have a new delivery!', 'success')
end
local function startJobPoint()
startZone = lib.points.new({
coords = Config.BossCoords.xyz,
distance = 50,
onEnter = spawnPed,
onExit = yeetPed,
})
end
function OnPlayerLoaded()
startJobPoint()
end
function OnPlayerUnload()
resetJob()
end
AddEventHandler('onResourceStart', function(resource)
if GetCurrentResourceName() ~= resource or not hasPlyLoaded() then return end
startJobPoint()
end)
AddEventHandler('onResourceStop', function(resourceName)
if GetCurrentResourceName() ~= resourceName then return end
resetJob()
end)