48 lines
		
	
	
	
		
			1.5 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
			
		
		
	
	
			48 lines
		
	
	
	
		
			1.5 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
---Checks if the player has the weapon item specified
 | 
						|
---@param source string
 | 
						|
---@param weaponHash integer
 | 
						|
---@return boolean hasWeapon
 | 
						|
function HasWeapon(source, weaponHash)
 | 
						|
    local itemName = Config.AllowedWeapons[weaponHash].name
 | 
						|
    local count = exports.ox_inventory:GetItemCount(source, itemName)
 | 
						|
 | 
						|
    return count > 0
 | 
						|
end
 | 
						|
 | 
						|
---Removes the weapon from the player
 | 
						|
---@param source string
 | 
						|
---@param weaponHash integer
 | 
						|
---@param playerPed integer
 | 
						|
---@return boolean success
 | 
						|
function RemoveWeapon(source, weaponHash, playerPed)
 | 
						|
    local weapon = exports.ox_inventory:GetCurrentWeapon(source)
 | 
						|
    if not weapon then
 | 
						|
        return false
 | 
						|
    end
 | 
						|
 | 
						|
    exports.ox_inventory:RemoveItem(source, weapon.name, 1, weapon.metadata, weapon.slot)
 | 
						|
    return true
 | 
						|
end
 | 
						|
 | 
						|
---Reduces durability for the weapon
 | 
						|
---@param source string
 | 
						|
---@param weaponHash integer
 | 
						|
---@param playerPed integer
 | 
						|
---@return boolean removedWeapon If the weapon was removed due to durability going below 0
 | 
						|
function ReduceDurabilityForWeapon(source, weaponHash, playerPed)
 | 
						|
    local durabilityToReduce = Config.AllowedWeapons[weaponHash]?.durability
 | 
						|
    if not durabilityToReduce then
 | 
						|
        return false
 | 
						|
    end
 | 
						|
 | 
						|
    local weapon = exports.ox_inventory:GetCurrentWeapon(source)
 | 
						|
    local durability = (weapon.metadata?.durability or 100) - durabilityToReduce
 | 
						|
 | 
						|
    if durability <= 0.0 then
 | 
						|
        return RemoveWeapon(source, weaponHash, playerPed)
 | 
						|
    else
 | 
						|
        exports.ox_inventory:SetDurability(source, weapon.slot, durability)
 | 
						|
    end
 | 
						|
 | 
						|
    return false
 | 
						|
end
 |