forked from GhzGarage/qb-ammunationjob
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.lua
106 lines (97 loc) · 2.98 KB
/
server.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
local QBCore = exports['qb-core']:GetCoreObject()
local supplies = {
['ammuone'] = {},
['ammutwo'] = {},
['ammuthree'] = {},
['ammufour'] = {},
['ammufive'] = {},
['ammusix'] = {},
['ammuseven'] = {},
['ammueight'] = {},
['ammunine'] = {},
['ammuten'] = {},
['ammuelev'] = {},
}
local weapons = {
['ammuone'] = {},
['ammutwo'] = {},
['ammuthree'] = {},
['ammufour'] = {},
['ammufive'] = {},
['ammusix'] = {},
['ammuseven'] = {},
['ammueight'] = {},
['ammunine'] = {},
['ammuten'] = {},
['ammuelev'] = {},
}
local function isAvailable(weapon, job)
for k,v in pairs(weapons) do
if k == job then
if v[weapon] > 0 then return true end
end
end
return false
end
local function removeWeapon(weapon, job)
for k,v in pairs(weapons) do
if k == job then
if v[weapon] then
v[weapon] = v[weapon] - 1
end
end
end
end
RegisterNetEvent('qb-ammunation:server:grabSupplies', function(job, type)
local src = source
local playerJob = QBCore.Functions.GetPlayer(src).PlayerData.job.name
if playerJob ~= job then return end
for k,v in pairs(supplies) do
if k == job then
if v[type] then
v[type] = v[type] + 1
else
v[type] = 1
end
end
end
end)
RegisterNetEvent('qb-ammunation:server:craftWeapon', function(job, weapon)
local src = source
local playerJob = QBCore.Functions.GetPlayer(src).PlayerData.job.name
if playerJob ~= job then return end
for k,v in pairs(weapons) do
if k == job then
if v[weapon] then
v[weapon] = v[weapon] + 1
else
v[weapon] = 1
end
end
end
end)
RegisterNetEvent('qb-ammunation:server:buyWeapon', function(buyerId, weapon, coords, job)
local src = source
local ped = GetPlayerPed(src)
local tped = GetPlayerPed(buyerId)
local pcoords = GetEntityCoords(ped)
local tcoords = GetEntityCoords(tped)
--local acoords = vector3(coords.x, coords.y, coords.z)
local buyer = QBCore.Functions.GetPlayer(tonumber(buyerId))
if buyer then
if #(pcoords - tcoords) < 5.0 then
if not isAvailable(weapon, job) then return end
buyer.Functions.AddItem(weapon, 1)
removeWeapon(weapon, job)
TriggerClientEvent('QBCore:Notify', buyerId, "You received a " .. QBCore.Shared.Items[weapon].label)
else
TriggerClientEvent('QBCore:Notify', src, "You are too far away from the buyer")
end
end
end)
QBCore.Functions.CreateCallback('qb-ammunation:server:getCraftSupplies', function(source, cb, job)
cb(supplies[job])
end)
QBCore.Functions.CreateCallback('qb-ammunation:server:getCraftedWeapons', function(source, cb, job)
cb(weapons[job])
end)