Okay, part of code was bad, now it works how it should.
Citizen.CreateThread(function()
while true do
local coordA = GetEntityCoords(GetPlayerPed(-1), 1)
local coordB = GetOffsetFromEntityInWorldCoords(GetPlayerPed(-1), 0.0, 1.0, 0.0)
local vehicle = getVehicleInDirection(coordA, coordB)
if DoesEntityExist(vehicle) and IsEntityAVehicle(vehicle) then
local trunkpos = GetWorldPositionOfEntityBone(vehicle, GetEntityBoneIndexByName(vehicle, "boot"))
local playerpos = GetEntityCoords(GetPlayerPed(-1), 1)
local distanceToTrunk = GetDistanceBetweenCoords(trunkpos, playerpos, 1)
if distanceToTrunk < 1 then
DrawText3D(trunkpos.x, trunkpos.y, trunkpos.z - 0.3, "PRESS TO OPEN")
end
end
Citizen.Wait(0)
end
end)
function getVehicleInDirection(coordFrom, coordTo)
local rayHandle = CastRayPointToPoint(coordFrom.x, coordFrom.y, coordFrom.z, coordTo.x, coordTo.y, coordTo.z, 10, GetPlayerPed(-1), 0)
local _, _, _, _, vehicle = GetRaycastResult(rayHandle)
return vehicle
end
3 Likes