mirror of
https://github.com/qbcore-fivem/qb-core.git
synced 2026-09-04 17:23:31 +00:00
add GetClosestBone
This commit is contained in:
@@ -263,6 +263,29 @@ function QBCore.Functions.GetClosestObject(coords)
|
|||||||
return closestObject, closestDistance
|
return closestObject, closestDistance
|
||||||
end
|
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
|
-- Vehicle
|
||||||
|
|
||||||
function QBCore.Functions.SpawnVehicle(model, cb, coords, isnetworked)
|
function QBCore.Functions.SpawnVehicle(model, cb, coords, isnetworked)
|
||||||
|
|||||||
Reference in New Issue
Block a user