Skip to content

Commit

Permalink
Merge pull request #101 from overextended/entitypoints
Browse files Browse the repository at this point in the history
  • Loading branch information
thelindat authored Aug 14, 2023
2 parents cea7848 + 9847977 commit d4f5273
Showing 1 changed file with 32 additions and 5 deletions.
37 changes: 32 additions & 5 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ local GetEntityModel = GetEntityModel
local IsDisabledControlJustPressed = IsDisabledControlJustPressed
local DisableControlAction = DisableControlAction
local DisablePlayerFiring = DisablePlayerFiring
local GetModelDimensions = GetModelDimensions
local GetOffsetFromEntityInWorldCoords = GetOffsetFromEntityInWorldCoords
local options = {}
local currentTarget = {}
local currentMenu
Expand All @@ -36,9 +38,11 @@ local debug = GetConvarInt('ox_target:debug', 0) == 1

---@param option table
---@param distance number
---@param entityHit number
---@param endCoords vector3
local function shouldHide(option, distance, entityHit, endCoords)
---@param entityHit? number
---@param entityType? number
---@param entityModel? number | false
local function shouldHide(option, distance, endCoords, entityHit, entityType, entityModel)
if option.menuName ~= currentMenu then
return true
end
Expand All @@ -55,9 +59,13 @@ local function shouldHide(option, distance, entityHit, endCoords)
return true
end

local bone = option.bones
local bone = entityModel and option.bones or nil

if bone then
---@cast entityHit number
---@cast entityType number
---@cast entityModel number

local _type = type(bone)

if _type == 'string' then
Expand Down Expand Up @@ -92,6 +100,25 @@ local function shouldHide(option, distance, entityHit, endCoords)
end
end

local offset = entityModel and option.offset or nil

if offset then
---@cast entityHit number
---@cast entityType number
---@cast entityModel number

if not option.absoluteOffset then
local min, max = GetModelDimensions(entityModel)
offset = (max - min) * offset + min
end

offset = GetOffsetFromEntityInWorldCoords(entityHit, offset.x, offset.y, offset.z)

if #(endCoords - offset) > (option.offsetSize or 1) then
return true
end
end

if option.canInteract then
local success, resp = pcall(option.canInteract, entityHit, distance, endCoords, option.name, bone)
return not success or not resp
Expand Down Expand Up @@ -189,7 +216,7 @@ local function startTargeting()

for i = 1, optionCount do
local option = v[i]
local hide = shouldHide(option, distance, entityHit, endCoords)
local hide = shouldHide(option, distance, endCoords, entityHit, entityType, entityModel)

if option.hide ~= hide then
option.hide = hide
Expand All @@ -210,7 +237,7 @@ local function startTargeting()

for j = 1, optionCount do
local option = zoneOptions[j]
local hide = shouldHide(option, distance, entityHit, endCoords)
local hide = shouldHide(option, distance, endCoords)

if option.hide ~= hide then
option.hide = hide
Expand Down

0 comments on commit d4f5273

Please sign in to comment.