Heres the script:
Citizen.CreateThread( function ()
while true do
Citizen.Wait(0)
if IsPedInAnyVehicle(PlayerPedId(), false) then
local Vehicle = GetVehiclePedIsIn(PlayerPedId(), false);
if GetPedInVehicleSeat(Vehicle, 0) == PlayerPedId() then
if not GetIsTaskActive(PlayerPedId(), 164) and GetIsTaskActive(PlayerPedId(), 165) then
SetPedIntoVehicle(PlayerPedId(), Vehicle, 0);
end
end
end
end
end)
How would you reduce the performance it takes can you do it any other way then change the Citizen.Wait(0) to a higher number because then it will have time to do the animation.
Use this on the ped: SetPedConfigFlag - FiveM Natives @ Cfx.re Docs
SetPedConfigFlag(PlayerPedId(), 184, true)
It is only required to be set once on the ped and not inside a loop.
Thank you but now i can’t attack anything in the vehicle but i might used it wrong?
Citizen.CreateThread(function()
local vehicle
while true do
Citizen.Wait(0)
if IsPedInAnyVehicle(PlayerPedId(), false) then
vehicle = GetVehiclePedIsIn(PlayerPedId(), false)
if GetPedInVehicleSeat(vehicle, 0) == PlayerPedId() then
if not GetIsTaskActive(PlayerPedId(), 164) and GetIsTaskActive(PlayerPedId(), 165) then
SetPedConfigFlag(PlayerPedId(), 184, true) -- Enable the desired ped configuration flag
SetPedIntoVehicle(PlayerPedId(), vehicle, 0)
end
end
else
SetPedConfigFlag(PlayerPedId(), 184, false)
end
end
end)
The flag is called PreventAutoShuffleToDriversSeat
. Setting it to true will prevent the auto shuffle.
You don’t need anything else inside your code.
You could just set this value once after character selection or revive. But to make sure to always have it working, just do something like this:
CreateThread(function()
while (true) do
Wait(5000)
SetPedConfigFlag(PlayerPedId(), 184, true)
end
end)
Easier than looking for every single instance where you would need to get the ped again.
1 Like