Hi All!
First of all, I want to state that I’m quite new to LUA and this is my very first Fivem project.
Now, what I’m trying to achieve is that being able to open/close vehicle doors while standing right next to it.
Here is my piece of code:
local vehicle = GetClosestVehicle(GetEntityCoords(PlayerPedId()), 10.0, 0, 70)
local lockStatus = GetVehicleDoorLockStatus(vehicle)
local rearLeftDoor = GetEntityBoneIndexByName(vehicle, 'door_dside_r')
local rldCoords = GetWorldPositionOfEntityBone(vehicle, rearLeftDoor)
if GetDistanceBetweenCoords(GetEntityCoords(PlayerPedId()), rldCoords, true) <= 0.9 then
if rearLeftDoor ~= -1 then
if GetVehicleDoorAngleRatio(vehicle, 2) < 0.1 then
DrawSmallText3D(rldCoords, '[MOUSE-RIGHT] Open/Close Rear-Left Door')
if IsControlJustReleased(0, Config.keys["MOUSERIGHT"])then
if lockStatus == 1 then
SetVehicleDoorOpen(vehicle, 2, false)
elseif lockStatus == 2 then
ESX.ShowNotification('The car is locked!')
end
end
else
if IsControlJustReleased(0, Config.keys["MOUSERIGHT"]) then
SetVehicleDoorShut(vehicle, 2, false, false)
end
end
end
end
…which works as expected, however since I want to open/close each and every doors one by one (including hood and boot) by mouse click,
I need to use very short distance between player and the doors, otherwise I’d open rear doors as well while standing next to the front doors.
That’s causing me a little problem. And the problem is that standing right next to the door while opening it blocks the door to open since player is right there.
Now, I’d like to know if it is possible to set some kind of no-collision to the doors while they are opening so it would open completely by going through the player?!
Another question is the heading of the player. I want to prevent opening doors when player is looking to another direction.
Which means they would be able to open doors only when they are heading to the direction of the door.
I know Google is a good friend but I couldn’t find any reference for this move.
I tried this:
IsPedHeadingTowardsPosition(PlayerPedId(), rldCoords.x, rldCoords.y, rldCoords.z)
… but that doesn’t work so obviously I’m doing something wrong.
So dear Fivem community, would you be so kind to helping me out in these issues?
