-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathclient.lua
472 lines (391 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
local buying = false -- Variable to prevent multiple purchases
local LastWaterCoolerUse = 0 -- Variable to prevent multiple uses of the water cooler
local TimeoutDuration = Config.WaterCoolerTimeout * 1000 -- Timeout duration for water coolers in milliseconds
local DrinkCount = 0 -- Variable to count the number of drinks
if Config.Framework == "esx" then
ESX = exports['es_extended']:getSharedObject()
elseif Config.Framework == "qb" then
QBCore = exports['qb-core']:GetCoreObject()
elseif Config.Framework == "ox" then
Ox = require '@ox_core.lib.init'
else
ESX = exports['es_extended']:getSharedObject()
end
function DebugPrint(...) -- Debug print function
if Config.DebugMode then
print(...)
end
end
function Notify(msgtitle, msg, time, type2) -- Notification function
if Config.UseOXNotifications then
lib.notify({
title = msgtitle,
description = msg,
showDuration = true,
type = type2,
style = {
backgroundColor = 'rgba(0, 0, 0, 0.75)',
color = 'rgba(255, 255, 255, 1)',
['.description'] = {
color = '#909296',
backgroundColor = 'transparent'
}
}
})
else
if Config.Framework == 'qb' then
QBCore.Functions.Notify(msg, type2, time)
elseif Config.Framework == 'esx' then
TriggerEvent('esx:showNotification', msg, type2, time)
elseif Config.Framework == 'ox' then
lib.notify({
title = msgtitle,
description = msg,
showDuration = true,
type = type2,
style = {
backgroundColor = 'rgba(0, 0, 0, 0.75)',
color = 'rgba(255, 255, 255, 1)',
['.description'] = {
color = '#909296',
backgroundColor = 'transparent'
}
}
})
end
end
end
RegisterNetEvent("muhaddil-machines:Notify")
AddEventHandler("muhaddil-machines:Notify", function(msgtitle, msg, time, type)
Notify(msgtitle, msg, time, type)
end)
local function loadAnimDict(animDict)
RequestAnimDict(animDict)
while not HasAnimDictLoaded(animDict) do
Citizen.Wait(0)
end
end
local function playAnimation(ped, animDict, animName)
loadAnimDict(animDict)
TaskPlayAnim(ped, animDict, animName, 8.0, 5.0, -1, 1, 1, false, false, false)
Citizen.Wait(4500)
ClearPedTasks(ped)
RemoveAnimDict(animDict)
end
local function vendingAnimation(entity)
local ped = PlayerPedId()
local position = GetOffsetFromEntityInWorldCoords(entity, 0.0, -0.97, 0.05)
local heading = GetEntityHeading(entity)
local prop_name = 'ng_proc_sodacan_01a'
buying = true
TaskTurnPedToFaceEntity(ped, entity, -1)
if not IsEntityAtCoord(ped, position.x, position.y, position.z, 0.1, 0.0, 0.1, false, true, 0) then
TaskGoStraightToCoord(ped, position.x, position.y, position.z, 1.0, 20000, heading, 0.1)
Citizen.Wait(1000)
end
TaskTurnPedToFaceEntity(ped, entity, -1)
Citizen.Wait(1000)
Citizen.CreateThread(function()
local playerPed = PlayerPedId()
local x, y, z = table.unpack(GetEntityCoords(playerPed))
if Config.VisibleProp then
local prop = CreateObject(GetHashKey(prop_name), x, y, z + 0.2, true, true, true)
local boneIndex = GetPedBoneIndex(playerPed, 18905)
end
RequestAmbientAudioBank("VENDING_MACHINE", false)
HintAmbientAudioBank("VENDING_MACHINE", 0)
if Config.VisibleProp then
AttachEntityToEntity(prop, playerPed, boneIndex, 0.12, 0.008, 0.03, 240.0, -60.0, 0.0, true, true, false,
true, 1, true)
end
playAnimation(playerPed, Config.Animations.sodamachines[1], Config.Animations.sodamachines[2])
Citizen.Wait(1000)
ClearPedSecondaryTask(playerPed)
if DoesEntityExist(prop) then
DeleteObject(prop)
end
ReleaseAmbientAudioBank()
buying = false
end)
end
local function showQuantityDialog(item, vendingMachineName, entity)
local input = lib.inputDialog("Selecciona la cantidad", {
{ type = 'number', label = 'Cantidad', min = 1, max = Config.InputMaxValue, default = 1 }
})
if not input then return end
local cantidad = input[1]
if cantidad and cantidad > 0 then
local ped = PlayerPedId()
if buying then return end
buying = true
vendingAnimation(entity)
Citizen.Wait(4500)
TriggerServerEvent('muhaddil-machines:buy', 'machine', vendingMachineName, item.name, cantidad)
else
Notify('Error', 'Cantidad no válida', 5000, "error")
end
buying = false
end
local function replacePrice(inputString, price)
return inputString:gsub("%%price%%", tostring(price))
end
local function showVendingMenu(vendingMachineName, entity, items)
local options = {}
for _, item in pairs(items) do
table.insert(options, {
title = replacePrice(item.label, item.price),
icon = item.icon or 'fa-solid fa-bottle-water',
onSelect = function()
if buying then return end
showQuantityDialog(item, vendingMachineName, entity)
end
})
end
lib.registerContext({
id = 'vending_menu_' .. vendingMachineName,
title = 'Máquina expendedora',
canClose = true,
options = options
})
lib.showContext('vending_menu_' .. vendingMachineName)
end
local function interactWithWaterCooler(entity)
local currentTime = GetGameTimer()
if Config.ShowWaitNotification then
if currentTime - LastWaterCoolerUse < TimeoutDuration then
DebugPrint("Debes esperar antes de usar nuevamente la fuente de agua.")
Notify('¡Echa el freno madaleno!', 'Relaja, espera un poco antes de volver a usar la máquina', 5000, "error")
return
end
end
if IsAnimated then return end
IsAnimated = true
LastWaterCoolerUse = currentTime
local prop_name = 'prop_cs_paper_cup'
local ped = PlayerPedId()
local position = GetOffsetFromEntityInWorldCoords(entity, 0.0, -0.97, 0.05)
local heading = GetEntityHeading(entity)
if not IsEntityAtCoord(ped, position.x, position.y, position.z, 0.1, 0.1, 0.1, false, true, 0) then
TaskGoStraightToCoord(ped, position.x, position.y, position.z, 1.0, 20000, heading, 0.1)
Wait(1000)
end
TaskTurnPedToFaceEntity(ped, entity, -1)
lib.progressBar({
duration = 2000,
label = 'Llenado Vaso',
})
Citizen.CreateThread(function()
local playerPed = PlayerPedId()
local x, y, z = table.unpack(GetEntityCoords(playerPed))
local prop = CreateObject(GetHashKey(prop_name), x, y, z + 0.2, true, true, true)
local boneIndex = GetPedBoneIndex(playerPed, 18905)
AttachEntityToEntity(prop, playerPed, boneIndex, 0.12, 0.008, 0.03, 240.0, -60.0, 0.0, true, true, false, true, 1,
true)
local animDict = 'mp_player_intdrink'
local animName = 'loop_bottle'
playAnimation(playerPed, animDict, animName)
if Config.CountDrinksPlace == 'before' then
DrinkCount = DrinkCount + 1
end
if Config.KillPlayerOnExcess then
local warningThreshold = math.ceil(Config.MaxDrinksBeforeKill / 2)
print(warningThreshold)
if DrinkCount >= Config.MaxDrinksBeforeKill then
SetEntityHealth(playerPed, 0)
Notify('Demasiada agua', 'Has bebido demasiada agua y has muerto.', 5000, "error")
DrinkCount = 0
elseif DrinkCount >= warningThreshold then
Notify('Agua fresca', 'Sigues bebiendo... ten cuidado.', 3000, "info")
else
Notify('Agua fresca', 'Has tomado un vaso de agua.', 3000, "info")
end
else
Notify('Agua fresca', 'Has tomado un vaso de agua.', 3000, "info")
end
IsAnimated = false
ClearPedSecondaryTask(playerPed)
DeleteObject(prop)
RemoveAnimDict(animDict)
TriggerServerEvent('muhaddil-machines:RemoveThirst')
if Config.CountDrinksPlace == 'after' then
DrinkCount = DrinkCount + 1
end
end)
end
local function WaterCoolerTarget()
for waterCoolerName, data in pairs(Config.WaterCoolers) do
local options = {
{
label = "Beber Agua",
icon = 'fa-solid fa-glass-water',
onSelect = function(d)
local entity = d.entity
interactWithWaterCooler(entity)
end
}
}
exports.ox_target:addModel(joaat(data.model), options)
end
end
local function standAnimation(entity)
local ped = PlayerPedId()
local position = GetOffsetFromEntityInWorldCoords(entity, 0.0, -0.97, 0.05)
local heading = GetEntityHeading(entity)
buying = true
TaskTurnPedToFaceEntity(ped, entity, -1)
if not IsEntityAtCoord(ped, position.x, position.y, position.z, 0.1, 0.0, 0.1, false, true, 0) then
TaskGoStraightToCoord(ped, position.x, position.y, position.z, 1.0, 20000, heading, 0.1)
Citizen.Wait(1000)
end
TaskTurnPedToFaceEntity(ped, entity, -1)
Citizen.Wait(1000)
playAnimation(ped, Config.Animations.stand[1], Config.Animations.stand[2])
Citizen.Wait(1000)
ClearPedSecondaryTask(ped)
buying = false
end
local function showQuantityDialogStands(item, standName, entity)
local input = lib.inputDialog("Selecciona la cantidad", {
{ type = 'number', label = 'Cantidad', min = 1, max = Config.InputMaxValue, default = 1 }
})
if not input then return end
local cantidad = input[1]
if cantidad and cantidad > 0 then
local ped = PlayerPedId()
if buying then return end
buying = true
standAnimation(entity)
TriggerServerEvent('muhaddil-machines:buy', 'stand', standName, item.name, cantidad)
else
Notify('Error', 'Cantidad no válida', 5000, "error")
end
buying = false
end
local function standMenu(standName, entity, items)
local options = {}
for _, item in pairs(items) do
table.insert(options, {
title = replacePrice(item.label, item.price),
icon = item.icon or 'fa-solid fa-bottle-water',
onSelect = function()
if buying then return end
showQuantityDialogStands(item, standName, entity)
end
})
end
lib.registerContext({
id = 'stand_menu_' .. standName,
title = 'Puesto de Comida',
canClose = true,
options = options
})
lib.showContext('stand_menu_' .. standName)
end
local function newsAnimation(entity)
local ped = PlayerPedId()
local position = GetOffsetFromEntityInWorldCoords(entity, 0.0, -0.97, 0.05)
local heading = GetEntityHeading(entity)
buying = true
TaskTurnPedToFaceEntity(ped, entity, -1)
if not IsEntityAtCoord(ped, position.x, position.y, position.z, 0.0, 0.0, 0.0, false, true, 0) then
TaskGoStraightToCoord(ped, position.x, position.y, position.z, 1.0, 20000, heading, 0.1)
Citizen.Wait(1000)
end
TaskTurnPedToFaceEntity(ped, entity, -1)
Citizen.Wait(1000)
loadAnimDict(Config.Animations.newsSellers[1])
TaskPlayAnim(ped, Config.Animations.newsSellers[1], Config.Animations.newsSellers[2], 8.0, 5.0, -1, 1, 1, false,
false, false)
Citizen.Wait(2500)
ClearPedTasks(ped)
RemoveAnimDict(Config.Animations.newsSellers[1])
ClearPedSecondaryTask(ped)
buying = false
end
local function showQuantityDialogNews(item, newsName, entity)
local input = lib.inputDialog("Selecciona la cantidad", {
{ type = 'number', label = 'Cantidad', min = 1, max = Config.InputMaxValue, default = 1 }
})
if not input then return end
local cantidad = input[1]
if cantidad and cantidad > 0 then
local ped = PlayerPedId()
if buying then return end
buying = true
newsAnimation(entity)
TriggerServerEvent('muhaddil-machines:buy', 'news', newsName, item.name, cantidad)
else
Notify('Error', 'Cantidad no válida', 5000, "error")
end
buying = false
end
local function newsMenu(newsName, entity, items)
local options = {}
for _, item in pairs(items) do
table.insert(options, {
title = replacePrice(item.label, item.price),
icon = item.icon or 'fa-solid fa-bottle-water',
onSelect = function()
if buying then return end
showQuantityDialogNews(item, newsName, entity)
end
})
end
lib.registerContext({
id = 'news_menu_' .. newsName,
title = 'Venta de Noticias',
canClose = true,
options = options
})
lib.showContext('news_menu_' .. newsName)
end
local function setupTargeting()
for vendingMachineName, data in pairs(Config.machines) do
local options = {
{
label = "Abrir Máquina Expendedora",
icon = 'fa-solid fa-basket-shopping',
onSelect = function(d)
if buying then return end
local entity = d.entity
showVendingMenu(vendingMachineName, entity, data.items)
end
}
}
exports.ox_target:addModel(joaat(data.model), options)
end
for standName, data in pairs(Config.Stands) do
local options = {
{
label = "Abrir Puesto de Comida",
icon = 'fa-solid fa-utensils',
onSelect = function(d)
if buying then return end
local entity = d.entity
standMenu(standName, entity, data.items)
end
}
}
exports.ox_target:addModel(joaat(data.model), options)
end
for newsName, data in pairs(Config.NewsSellers) do
local options = {
{
label = "Abrir Venta de Noticias",
icon = 'fa-solid fa-newspaper',
onSelect = function(d)
if buying then return end
local entity = d.entity
newsMenu(newsName, entity, data.items)
end
}
}
exports.ox_target:addModel(joaat(data.model), options)
end
end
CreateThread(function()
Wait(100)
setupTargeting()
WaterCoolerTarget()
-- standsTarget()
end)