64 lines
		
	
	
	
		
			2 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
			
		
		
	
	
			64 lines
		
	
	
	
		
			2 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
| local vehicleStashes = {}
 | |
| 
 | |
| local function OpenVehicleRoofbox(player, vehicle)
 | |
|     Entity(vehicle).state.kq_roofboxes_open = true
 | |
| end
 | |
| local function CloseVehicleRoofbox(player, vehicle)
 | |
|     Entity(vehicle).state.kq_roofboxes_open = false
 | |
| end
 | |
| 
 | |
| RegisterServerEvent('kq_roofboxes:server:openRoofbox')
 | |
| AddEventHandler('kq_roofboxes:server:openRoofbox', function(netId, model)
 | |
|     local player = source
 | |
|     local vehicle = NetworkGetEntityFromNetworkId(netId)
 | |
|     
 | |
|     Debug('Attempting open vehicle roofbox')
 | |
|     
 | |
|     if not CanPlayerOpenVehicleRoofbox(player, vehicle) then
 | |
|         Debug('CanPlayerOpenVehicleRoofbox returned false')
 | |
|         return
 | |
|     end
 | |
|     Debug('Opening vehicle roofbox')
 | |
|     
 | |
|     OpenVehicleRoofbox(player, vehicle)
 | |
|     
 | |
|     local mapping = {
 | |
|         [1] = 'normalRoofbox',
 | |
|         [2] = 'smallRoofbox',
 | |
|         [3] = 'supercarRoofbox',
 | |
|     }
 | |
|     
 | |
|     local size = Config.stashes[mapping[model]]
 | |
|     
 | |
|     local stashId = GetVehicleStashId(vehicle)
 | |
|     exports.kq_link:OpenCustomStash(player, stashId, L('Roofbox'), size.slots, size.maxWeight)
 | |
|     vehicleStashes[stashId] = vehicle
 | |
| end)
 | |
| 
 | |
| RegisterServerEvent('kq_roofboxes:server:closeInventory')
 | |
| AddEventHandler('kq_roofboxes:server:closeInventory', function(netId)
 | |
|     CloseVehicleRoofbox(source, NetworkGetEntityFromNetworkId(netId))
 | |
| end)
 | |
| 
 | |
| RegisterServerEvent('ox_inventory:closedInventory')
 | |
| AddEventHandler('ox_inventory:closedInventory', function(player, stashId)
 | |
|     if vehicleStashes[stashId] then
 | |
|         CloseVehicleRoofbox(player, vehicleStashes[stashId])
 | |
|     end
 | |
| end)
 | |
| 
 | |
| RegisterServerEvent('inventory:closeInventory')
 | |
| AddEventHandler('inventory:closeInventory', function(player, stashId)
 | |
|     if vehicleStashes[stashId] then
 | |
|         CloseVehicleRoofbox(player, vehicleStashes[stashId])
 | |
|     end
 | |
| end)
 | |
| 
 | |
| RegisterServerEvent('qb-inventory:server:closeInventory')
 | |
| AddEventHandler('qb-inventory:server:closeInventory', function(stashId)
 | |
|     if vehicleStashes[stashId] then
 | |
|         CloseVehicleRoofbox(source, vehicleStashes[stashId])
 | |
|     end
 | |
| end)
 | |
| 
 | |
| 
 | 
