80 lines
		
	
	
	
		
			2.5 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
			
		
		
	
	
			80 lines
		
	
	
	
		
			2.5 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
| ESX = nil
 | |
| QBCore = nil
 | |
| 
 | |
| if (GetResourceState('es_extended') == 'started') then
 | |
|     ESX = exports['es_extended']:getSharedObject()
 | |
| elseif (GetResourceState('qb-core') == 'started') then
 | |
|     QBCore = exports['qb-core']:GetCoreObject()
 | |
| end
 | |
| 
 | |
| Functions = {}
 | |
| 
 | |
| Functions.OnServerDeployLight = function(playerId, vehicle)
 | |
|     -- Do something when a player deploys a light
 | |
| end
 | |
| 
 | |
| Functions.OnServerRemoveLight = function(playerId, vehicle)
 | |
|     -- Do something when a player removes a light
 | |
| end
 | |
| 
 | |
| -- Removes the item from the player inventory, ensure function returns true on succes
 | |
| Functions.RemoveLightItem = function(playerId)
 | |
|     if (not Config.RequiredItem.Enabled) then
 | |
|         return true
 | |
|     end
 | |
| 
 | |
|     local itemName = Config.RequiredItem.Name
 | |
|     if ESX then
 | |
|         local xPlayer = ESX.GetPlayerFromId(playerId)
 | |
|         if xPlayer.getInventoryItem(itemName).count < 1 then
 | |
|             return false
 | |
|         end
 | |
|         xPlayer.removeInventoryItem(itemName, 1)
 | |
|     elseif QBCore then
 | |
|         local Player = QBCore.Functions.GetPlayer(playerId)
 | |
|         if not Player.Functions.GetItemByName(itemName) then
 | |
|             return false
 | |
|         end
 | |
|         Player.Functions.RemoveItem(itemName, 1)
 | |
|     end
 | |
|     return true
 | |
| end
 | |
| 
 | |
| -- Adds the item back to the player inventory
 | |
| Functions.AddLightItem = function(playerId)
 | |
|     if (not Config.RequiredItem.Enabled) then
 | |
|         return
 | |
|     end
 | |
| 
 | |
|     local itemName = Config.RequiredItem.Name
 | |
|     if ESX then
 | |
|         local xPlayer = ESX.GetPlayerFromId(playerId)
 | |
|         xPlayer.addInventoryItem(itemName, 1)
 | |
|     elseif QBCore then
 | |
|         local Player = QBCore.Functions.GetPlayer(playerId)
 | |
|         Player.Functions.AddItem(itemName, 1)
 | |
|     end
 | |
| end
 | |
| 
 | |
| -- Create the usable light item (only triggered if enabled in the configuration)
 | |
| Functions.RegisterItem = function(itemName, onItemUse)
 | |
|     if (GetResourceState('ox_inventory') == 'started') then
 | |
|         exports(itemName, function(event, item, inventory, slot, data)
 | |
|             local source = inventory.id
 | |
|             if (event == 'usingItem') then
 | |
|                 onItemUse(source)
 | |
|                 return false
 | |
|             end
 | |
|         end)
 | |
|     elseif (ESX) then
 | |
|         ESX.RegisterUsableItem(itemName, function(source)
 | |
|             onItemUse(source)
 | |
|         end)
 | |
|     elseif (QBCore) then
 | |
|         QBCore.Functions.CreateUseableItem(itemName, function(source)
 | |
|             onItemUse(source)
 | |
|         end)
 | |
|     else
 | |
|         print('gs_deployablelight: [ERROR] No inventory framework detected')
 | |
|     end
 | |
| end
 | 
