Skip to content

Commit

Permalink
refactor(client/inventory): improve vehicle trunk checks
Browse files Browse the repository at this point in the history
Validate doors exist, unless it's (probably) a trailer.
Removes trunk from invalid vehicles like phantom.
  • Loading branch information
thelindat committed Aug 15, 2023
1 parent 7745852 commit 08c5b27
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions modules/inventory/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ end

local Utils = require 'modules.utils.client'
local Vehicles = data 'vehicles'
local backDoorIds = { 2, 3 }

function Inventory.CanAccessTrunk(entity)
if cache.vehicle or not NetworkGetEntityIsNetworked(entity) then return end
Expand All @@ -30,6 +31,19 @@ function Inventory.CanAccessTrunk(entity)

if (checkVehicle == 0 or checkVehicle == 1) or (not Vehicles.trunk[vehicleClass] and not Vehicles.trunk.models[vehicleHash]) then return end

---@type number | number[]
local doorId = checkVehicle and 4 or 5

if not GetIsDoorValid(entity, doorId --[[@as number]]) then
if vehicleClass ~= 11 and (doorId ~= 5 or GetEntityBoneIndexByName(entity, 'boot') ~= -1 or not GetIsDoorValid(entity, 2)) then
return
end

if vehicleClass ~= 11 then
doorId = backDoorIds
end
end

local min, max = GetModelDimensions(vehicleHash)
local offset = (max - min) * (not checkVehicle and vec3(0.5, 0, 0.5) or vec3(0.5, 1, 0.5)) + min
offset = GetOffsetFromEntityInWorldCoords(entity, offset.x, offset.y, offset.z)
Expand All @@ -39,7 +53,7 @@ function Inventory.CanAccessTrunk(entity)

TaskTurnPedToFaceCoord(cache.ped, coords.x, coords.y, coords.z, 0)

return checkVehicle and 4 or 5
return doorId
end
end

Expand All @@ -57,10 +71,6 @@ function Inventory.OpenTrunk(entity)
local invId = 'trunk'..plate
local coords = GetEntityCoords(entity)

if door == 5 and GetEntityBoneIndexByName(entity, 'boot') == -1 then
door = { 2, 3 }
end

TaskTurnPedToFaceCoord(cache.ped, coords.x, coords.y, coords.z, 0)

if not client.openInventory('trunk', { id = invId, netid = NetworkGetNetworkIdFromEntity(entity), entityid = entity, door = door }) then return end
Expand Down

0 comments on commit 08c5b27

Please sign in to comment.