Skip to content

Commit

Permalink
refactor(client): use GetEntityBonePosition_2
Browse files Browse the repository at this point in the history
Allegedly faster.
  • Loading branch information
thelindat committed Feb 22, 2023
1 parent 4f2b9a8 commit 7efd2b3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 deletions client/defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ if GetConvarInt('ox_target:defaults', 1) ~= 1 then return end

local ox_target = exports.ox_target
local GetEntityBoneIndexByName = GetEntityBoneIndexByName
local GetWorldPositionOfEntityBone = GetWorldPositionOfEntityBone
local GetEntityBonePosition_2 = GetEntityBonePosition_2
local GetVehicleDoorLockStatus = GetVehicleDoorLockStatus

local function toggleDoor(vehicle, door)
Expand All @@ -27,7 +27,7 @@ ox_target:addGlobalVehicle({
local boneId = GetEntityBoneIndexByName(entity, 'door_dside_f')

if boneId ~= -1 then
return #(coords - GetWorldPositionOfEntityBone(entity, boneId)) < 0.5 or #(coords - GetWorldPositionOfEntityBone(entity, GetEntityBoneIndexByName(entity, 'seat_dside_f'))) < 0.72
return #(coords - GetEntityBonePosition_2(entity, boneId)) < 0.5 or #(coords - GetEntityBonePosition_2(entity, GetEntityBoneIndexByName(entity, 'seat_dside_f'))) < 0.72
end
end,
onSelect = function(data)
Expand All @@ -48,7 +48,7 @@ ox_target:addGlobalVehicle({
local boneId = GetEntityBoneIndexByName(entity, 'door_pside_f')

if boneId ~= -1 then
return #(coords - GetWorldPositionOfEntityBone(entity, boneId)) < 0.5 or #(coords - GetWorldPositionOfEntityBone(entity, GetEntityBoneIndexByName(entity, 'seat_pside_f'))) < 0.72
return #(coords - GetEntityBonePosition_2(entity, boneId)) < 0.5 or #(coords - GetEntityBonePosition_2(entity, GetEntityBoneIndexByName(entity, 'seat_pside_f'))) < 0.72
end
end,
onSelect = function(data)
Expand All @@ -69,7 +69,7 @@ ox_target:addGlobalVehicle({
local boneId = GetEntityBoneIndexByName(entity, 'door_dside_r')

if boneId ~= -1 then
return #(coords - GetWorldPositionOfEntityBone(entity, boneId)) < 0.5 or #(coords - GetWorldPositionOfEntityBone(entity, GetEntityBoneIndexByName(entity, 'seat_dside_r'))) < 0.72
return #(coords - GetEntityBonePosition_2(entity, boneId)) < 0.5 or #(coords - GetEntityBonePosition_2(entity, GetEntityBoneIndexByName(entity, 'seat_dside_r'))) < 0.72
end
end,
onSelect = function(data)
Expand All @@ -90,7 +90,7 @@ ox_target:addGlobalVehicle({
local boneId = GetEntityBoneIndexByName(entity, 'door_pside_r')

if boneId ~= -1 then
return #(coords - GetWorldPositionOfEntityBone(entity, boneId)) < 0.5 or #(coords - GetWorldPositionOfEntityBone(entity, GetEntityBoneIndexByName(entity, 'seat_pside_r'))) < 0.72
return #(coords - GetEntityBonePosition_2(entity, boneId)) < 0.5 or #(coords - GetEntityBonePosition_2(entity, GetEntityBoneIndexByName(entity, 'seat_pside_r'))) < 0.72
end
end,
onSelect = function(data)
Expand All @@ -108,7 +108,7 @@ ox_target:addGlobalVehicle({
bones = 'bonnet',
canInteract = function(entity, distance, coords, name, boneId)
if GetVehicleDoorLockStatus(entity) > 1 then return end
return #(coords - GetWorldPositionOfEntityBone(entity, boneId)) < 0.9
return #(coords - GetEntityBonePosition_2(entity, boneId)) < 0.9
end,
onSelect = function(data)
toggleDoor(data.entity, 4)
Expand All @@ -124,7 +124,7 @@ ox_target:addGlobalVehicle({
bones = 'boot',
canInteract = function(entity, distance, coords, name, boneId)
if GetVehicleDoorLockStatus(entity) > 1 then return end
return #(coords - GetWorldPositionOfEntityBone(entity, boneId)) < 0.9
return #(coords - GetEntityBonePosition_2(entity, boneId)) < 0.9
end,
onSelect = function(data)
toggleDoor(data.entity, 5)
Expand Down
4 changes: 2 additions & 2 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ local GetCurrentZone = GetCurrentZone
local PlayerHasGroups = PlayerHasGroups or function() return true end
local PlayerHasItems = PlayerHasItems
local GetEntityBoneIndexByName = GetEntityBoneIndexByName
local GetWorldPositionOfEntityBone = GetWorldPositionOfEntityBone
local GetEntityBonePosition_2 = GetEntityBonePosition_2
local next = next
local GetEntityModel = GetEntityModel
local GetEntityOptions = GetEntityOptions
Expand Down Expand Up @@ -172,7 +172,7 @@ local function enableTargeting()
local boneId = GetEntityBoneIndexByName(entityHit, bone[j])

if boneId ~= -1 then
local dist = #(endCoords - GetWorldPositionOfEntityBone(entityHit, boneId))
local dist = #(endCoords - GetEntityBonePosition_2(entityHit, boneId))

if dist <= (boneDistance or 1) then
closestBone = boneId
Expand Down

0 comments on commit 7efd2b3

Please sign in to comment.