-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclient.lua
159 lines (135 loc) · 4.75 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
local IneractionMenu = exports['interactionMenu']
local buying = false
local function loadAnimDict(animDict)
RequestAnimDict(animDict)
while not HasAnimDictLoaded(animDict) do
Citizen.Wait(0)
end
end
local function moveToPosition(ped, position, heading)
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)
while not IsEntityAtCoord(ped, position.x, position.y, position.z, 0.1, 0.1, 0.1, false, true, 0) do
Citizen.Wait(1000)
end
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 playAmbientAudio()
RequestAmbientAudioBank("VENDING_MACHINE", false)
HintAmbientAudioBank("VENDING_MACHINE", 0)
end
local function vendingAnimation(entity)
local ped = PlayerPedId()
local position = GetOffsetFromEntityInWorldCoords(entity, 0.0, -0.97, 0.05)
local heading = GetEntityHeading(entity)
buying = true
TaskTurnPedToFaceEntity(ped, entity, -1)
moveToPosition(ped, position, heading)
TaskTurnPedToFaceEntity(ped, entity, -1)
Citizen.Wait(1000)
playAmbientAudio()
playAnimation(ped, Config.animations.dispense[1], Config.animations.dispense[2])
ReleaseAmbientAudioBank()
buying = false
end
local function replacePrice(inputString, price)
return inputString:gsub("%%price%%", tostring(price))
end
local function ox_target()
for vendingMachineName, data in pairs(Config.machines) do
local options = {}
for index, value in pairs(data.items) do
local i = #options + 1
options[i] = {
label = replacePrice(value.label, value.price),
icon = value.icon or 'fa-solid fa-bottle-water',
}
if value.price and value.name then
options[i].onSelect = function(d)
if buying then return end
vendingAnimation(d.entity)
TriggerServerEvent('keep-vendingMachines:server:buy', vendingMachineName, value.name)
end
end
end
exports.ox_target:addModel(joaat(data.model), options)
end
end
local function qb_target()
for vendingMachineName, data in pairs(Config.machines) do
local options = {}
for index, value in pairs(data.items) do
local i = #options + 1
options[i] = {
label = replacePrice(value.label, value.price),
icon = value.icon or 'fa-solid fa-bottle-water',
}
if value.price and value.name then
options[i].action = function(entity)
if buying then return end
vendingAnimation(entity)
TriggerServerEvent('keep-vendingMachines:server:buy', vendingMachineName, value.name)
end
end
end
exports['qb-target']:AddTargetModel(joaat(data.model), {
options = options,
distance = 2.5,
})
end
end
local function interactionMenu()
for vendingMachineName, data in pairs(Config.machines) do
local options = {}
options[1] = {
label = 'Buy',
}
for index, value in pairs(data.items) do
local i = #options + 1
options[i] = {
label = replacePrice(value.label, value.price),
icon = value.icon or 'fa-solid fa-bottle-water',
}
if value.price and value.name then
options[i].action = {
type = 'sync',
func = function(entity)
if buying then return end
vendingAnimation(entity)
TriggerServerEvent('keep-vendingMachines:server:buy', vendingMachineName, value.name)
end
}
end
end
IneractionMenu:Create {
model = joaat(data.model),
offset = data.offset or vec3(0, 0, 0),
maxDistance = 1.3,
indicator = {
prompt = 'E',
keyPress = {
padIndex = 0,
control = 38
},
},
options = options
}
end
end
CreateThread(function()
Wait(100)
if Config.target == 'ox_target' then
ox_target()
elseif Config.target == 'qb-target' then
qb_target()
elseif Config.target == 'interactionMenu' then
interactionMenu()
end
end)