forked from GhzGarage/qb-ammunationjob
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.lua
239 lines (226 loc) · 8 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
local QBCore = exports['qb-core']:GetCoreObject()
local PlayerData = QBCore.Functions.GetPlayerData()
local supplyType = nil
-- Handlers
RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function ()
PlayerData = QBCore.Functions.GetPlayerData()
end)
RegisterNetEvent('QBCore:Client:OnJobUpdate', function(JobInfo)
PlayerData.job = JobInfo
end)
-- Functions
local function OpenSuppliesMenu()
exports['qb-menu']:openMenu({
{ header = 'Weapon Supplies', isMenuHeader = true},
{ header = 'Standard Pistol',
params = {
event = 'qb-ammunation:client:grabSupplies',
args = {
type = 'pistol'
}
}
},
{ header = 'Ceramic Pistol',
params = {
event = 'qb-ammunation:client:grabSupplies',
args = {
type = 'ceramic'
}
}
},
{ header = 'Combat Pistol',
params = {
event = 'qb-ammunation:client:grabSupplies',
args = {
type = 'combat'
}
}
},
{ header = 'SNS Pistol',
params = {
event = 'qb-ammunation:client:grabSupplies',
args = {
type = 'sns'
}
}
},
{ header = 'Pump Shotgun',
params = {
event = 'qb-ammunation:client:grabSupplies',
args = {
type = 'pump'
}
}
},
{ header = 'Marksman Rifle',
params = {
event = 'qb-ammunation:client:grabSupplies',
args = {
type = 'marksman'
}
}
},
})
end
local function CraftWeapon()
if not supplyType then return QBCore.Functions.Notify('You have no supplies', 'error') end
TriggerEvent('animations:client:EmoteCommandStart', {"c"})
QBCore.Functions.Progressbar('crafting_weapon', 'Crafting '..Config.WeaponLabels[supplyType], 5000, false, false, {
disableMovement = true,
disableCarMovement = true,
disableMouse = false,
disableCombat = true,
}, {
animDict = "mini@repair",
anim = "fixing_a_ped",
}, {}, {}, function() -- Success
QBCore.Functions.Notify("Crafted "..Config.WeaponLabels[supplyType], 'success')
TriggerServerEvent('qb-ammunation:server:craftWeapon', PlayerData.job.name, Config.Weapons[supplyType])
supplyType = nil
ClearPedTasks(PlayerPedId())
end, function() -- Cancel
ClearPedTasks(PlayerPedId())
QBCore.Functions.Notify('You have cancelled the crafting process', 'error')
end)
end
local function OpenGunMenu()
QBCore.Functions.TriggerCallback('qb-ammunation:server:getCraftedWeapons', function(weapons)
local availableWeapons = {{header = 'Available Weapons', isMenuHeader = true}}
for k,v in pairs(weapons) do
availableWeapons[#availableWeapons + 1] = {
header = QBCore.Shared.Items[k].label,
txt = 'Amount: ' ..v,
params = {
event = 'qb-ammunation:client:showcaseWeapon',
args = {
weapon = k
}
}
}
end
exports['qb-menu']:openMenu(availableWeapons)
end, PlayerData.job.name)
end
local function SellWeapon(zoneName, entity, weapon, coords, job)
local dialog = exports['qb-input']:ShowInput({
header = 'State ID',
submitText = 'Sell Weapon',
inputs = {
{
type = 'number',
isRequired = true,
name = 'stateId',
text = 'State ID (#)'
}
}
})
if dialog then
if not dialog.stateId then return end
exports['qb-target']:RemoveZone(zoneName)
DeleteEntity(entity)
TriggerServerEvent('qb-ammunation:server:buyWeapon', dialog.stateId, weapon, coords, job)
end
end
-- Events
RegisterNetEvent('qb-ammunation:client:grabSupplies', function(data)
if supplyType then return QBCore.Functions.Notify('You already have supplies', 'error') end
supplyType = data.type
TriggerServerEvent('qb-ammunation:server:grabSupplies', PlayerData.job.name, data.type)
TriggerEvent('animations:client:EmoteCommandStart', {"box"})
end)
RegisterNetEvent('qb-ammunation:client:showcaseWeapon', function(data)
local weaponModel = Config.WeaponModels[data.weapon]
RequestModel(weaponModel)
while not HasModelLoaded(weaponModel) do
Wait(0)
end
local showcaseWeapon = CreateObject(GetHashKey(weaponModel), Config.Shops[PlayerData.job.name]['showcase'].x, Config.Shops[PlayerData.job.name]['showcase'].y, Config.Shops[PlayerData.job.name]['showcase'].z, true, true, true)
SetEntityHeading(showcaseWeapon, Config.Shops[PlayerData.job.name]['showcase'].w)
local zoneName = PlayerData.job.name..' '..data.weapon
local coords = Config.Shops[PlayerData.job.name].showcase
exports['qb-target']:AddEntityZone(zoneName, showcaseWeapon, {
name = zoneName,
debugPoly = false
}, {
options = {
{
icon = 'fa-solid fa-basket-shopping',
label = 'Sell Weapon',
action = function()
SellWeapon(zoneName, showcaseWeapon, data.weapon, coords, PlayerData.job.name)
end
},
{
icon = 'fa-solid fa-ban',
label = 'Remove Weapon',
action = function()
exports['qb-target']:RemoveZone(zoneName)
DeleteEntity(showcaseWeapon)
end
}
},
distance = 2.0,
})
end)
-- Threads
CreateThread(function()
for k,v in pairs(Config.Shops) do
exports['qb-target']:AddBoxZone(v.menu.name, v.menu.loc, v.menu.length, v.menu.width, {
name = v.menu.name,
heading = v.menu.heading,
debug = v.menu.debugPoly,
minZ = v.menu.minZ,
maxZ = v.menu.maxZ
}, {
options = {
{
icon = 'fa-solid fa-gun',
label = 'View available guns',
job = k,
action = function()
OpenGunMenu()
end,
},
},
distance = 1.5
})
exports['qb-target']:AddBoxZone(v.supplies.name, v.supplies.loc, v.supplies.length, v.supplies.width, {
name = v.supplies.name,
heading = v.supplies.heading,
debug = v.supplies.debugPoly,
minZ = v.supplies.minZ,
maxZ = v.supplies.maxZ
}, {
options = {
{
icon = 'fa-solid fa-box',
label = 'Get supplies',
job = k,
action = function()
OpenSuppliesMenu()
end,
},
},
distance = 1.5
})
exports['qb-target']:AddBoxZone(v.craft.name, v.craft.loc, v.craft.length, v.craft.width, {
name = v.craft.name,
heading = v.craft.heading,
debug = v.craft.debugPoly,
minZ = v.craft.minZ,
maxZ = v.craft.maxZ
}, {
options = {
{
icon = 'fa-solid fa-wrench',
label = 'Craft weapon',
job = k,
action = function()
CraftWeapon()
end,
},
},
distance = 1.5
})
end
end)