-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.lua
More file actions
64 lines (59 loc) · 3.09 KB
/
Copy pathserver.lua
File metadata and controls
64 lines (59 loc) · 3.09 KB
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
local ox_inventory = exports.ox_inventory
local repairs = {}
local function fixWeapon(payload)
if type(payload) ~= 'table' or table.type(payload) == 'empty' then return end
TriggerClientEvent('ox_inventory:closeInventory', payload.source)
ox_inventory:RemoveItem(payload.source, payload.fromSlot.name, 1)
repairs[payload.source] = {}
repairs[payload.source].slot = payload.toSlot.slot
repairs[payload.source].name = payload.toSlot.name
TriggerClientEvent('raze_weaponrepair:repairitem', payload.source, payload.toSlot.name)
end
RegisterNetEvent('raze_weaponrepair:startweaponrepair', function(data)
local src = source
local slot = ox_inventory:GetSlot(src, data.slot)
if slot and slot.name == data.name then
local requiredItem = Config.require[data.name] and Config.require[data.name].requireditem or Config.requireditem
local requiredAmount = Config.require[data.name] and Config.require[data.name].requireditemamount or Config.requireditemamount
local count = ox_inventory:Search(src, 'count', requiredItem)
if not count then return TriggerClientEvent('ox_lib:notify', src, {type = 'error', title = 'Workbench', description = 'Missing Required items'}) end
if count >= requiredAmount then
ox_inventory:RemoveItem(src, requiredItem, requiredAmount)
repairs[src] = {}
repairs[src].slot = data.slot
repairs[src].name = data.name
TriggerClientEvent('raze_weaponrepair:repairitem', src, data.name)
else
TriggerClientEvent('ox_lib:notify', src, {type = 'error', title = 'Workbench', description = string.format('You dont have enough %s', requiredItem)})
end
elseif slot and slot.name ~= data.name then
print('Player ID:', src, 'Attempting to fixweapon with incorrect data, probably cheating')
end
end)
RegisterNetEvent('raze_weaponrepair:fixweapon', function()
local src = source
if repairs[src] then
local slot = ox_inventory:GetSlot(src, repairs[src].slot)
if slot and slot.name == repairs[src].name then
ox_inventory:SetDurability(src, repairs[src].slot, 100)
if slot and slot.name ~= repairs[src].name then
print('Player ID:', src, 'Attempting to fixweapon with data mismatch, probably cheating')
end
else
print('Player ID:', src, 'Attempting to fixweapon with incorrect data, probably cheating')
end
end
end)
lib.callback.register('openRepairBench', function(source)
return ox_inventory:Search(source, 'slots', Weapons)
end)
local hookId = exports.ox_inventory:registerHook('swapItems', function(payload)
if payload.fromSlot.name == Config.repairItem then
if WeaponHashes[payload.toSlot.name] then
if payload.toSlot.metadata.durability >= 100.0 then TriggerClientEvent('ox_lib:notify', payload.source, {position = 'top', type = 'error', description = 'Weapon does not need repairing'}) return false end
CreateThread(function() fixWeapon(payload) end)
return false
end
end
return true
end, {print = true, itemFilter = Filter})