add GetClosestBone

This commit is contained in:
darknight2590
2021-12-19 08:15:26 +02:00
committed by GitHub
parent e7c4562289
commit 186c99fee7
+23
View File
@@ -263,6 +263,29 @@ function QBCore.Functions.GetClosestObject(coords)
return closestObject, closestDistance
end
function QBCore.Functions.GetClosestBone(entity, list)
local playerCoords, bone, coords, distance = GetEntityCoords(PlayerPedId())
for _, element in pairs(list) do
local boneCoords = GetWorldPositionOfEntityBone(entity, element.id or element)
local boneDistance = #(playerCoords - boneCoords)
if not coords then
bone, coords, distance = element, boneCoords, boneDistance
elseif distance > boneDistance then
bone, coords, distance = element, boneCoords, boneDistance
end
end
if not bone then
bone = {id = GetEntityBoneIndexByName(entity, "bodyshell"), type = "remains", name = "bodyshell"}
coords = GetWorldPositionOfEntityBone(entity, bone.id)
distance = #(coords - playerCoords)
end
return bone, coords, distance
end
-- Vehicle
function QBCore.Functions.SpawnVehicle(model, cb, coords, isnetworked)