Stop Vehicle Seat Shuffling

I’m trying to write a script that stops front seat passengers from shuffling to the driver’s seat when it is empty, does anyone have a better way than what I have done? Also the code I wrote is broken, as if you get in a vehicle as the front seat passenger, then get out and get in the driver’s seat, you teleport into the front passenger seat.

--[[------------------------------------------------------------------------
    Vehicle Anti-Shuffle 
------------------------------------------------------------------------]]--
function ManageAntiShuffle()
    local ped = GetPlayerPed( -1 )

    if ( DoesEntityExist( ped ) and not IsEntityDead( ped ) ) then 
        if ( IsPedInAnyVehicle( ped, false ) ) then 
            local veh = GetVehiclePedIsIn( ped, true )
            
            if ( GetLastPedInVehicleSeat( veh, 0 ) == ped and GetPedInVehicleSeat( veh, -1 ) == ped ) then 
                SetPedIntoVehicle( ped, veh, 0 )
            end
        end 
    end
end  

Citizen.CreateThread( function()
    while true do 
        ManageAntiShuffle()

        Citizen.Wait( 0 )
    end 
end )

Try this

-- TaskExitVehicle = 2
if GetPedInVehicleSeat(veh, 0) == ped and IsVehicleSeatFree(veh, -1) and not GetIsTaskActive(ped, 2) then
SetPedIntoVehicle( ped, veh, 0 )
end

Or

-- TaskExitVehicle = 2
-- TaskInVehicleSeatShuffle = 165
if GetPedInVehicleSeat(veh, 0) == ped and GetIsTaskActive(ped, 165) and not GetIsTaskActive(ped, 2) then
SetPedIntoVehicle( ped, veh, 0 )
end

Thanks, the first one works but it doesn’t let you get back out of the vehicle.

This one works but only for parked vehicles and only if the door is not already open, weird

function AntiSeatShuffle()
    local ped = GetPlayerPed(-1)

    if DoesEntityExist(ped) and not IsEntityDead(ped) then 
        if IsPedInAnyVehicle(ped, false) then 
            local veh = GetVehiclePedIsIn(ped, false)
            
            if GetIsTaskActive(ped, 2) == false and GetPedInVehicleSeat(veh, 0) == ped and IsVehicleSeatFree(veh, -1) then
               SetPedIntoVehicle(ped, veh, 0)
            end
        end 
    end
end

Citizen.CreateThread(function()
    while true do 
        AntiSeatShuffle()
        Citizen.Wait(0)
    end 
end)

Preview

But I wouldn’t use it… Here’s why

Srry, GetIsTaskActive takes two parameters

I know the dude doing the vRP Framework has it working (Was amazed it worked correctly last night)… No clue on specifics, sorry… But maybe ask on his vRP post?.. Just a thought

I would love to use this script for my community, I will also be a tester of it.

Got this so far, works better but it’s still weird as the player shuffles to the driver’s seat, then gets teleported back when they’re half way.

function ManageAntiShuffle()
    local ped = GetPlayerPed( -1 )

    if ( DoesEntityExist( ped ) and not IsEntityDead( ped ) ) then 
        if ( IsPedInAnyVehicle( ped, false ) ) then 
            local veh = GetVehiclePedIsIn( ped, true )

            if ( GetPedInVehicleSeat( veh, 0 ) == ped and IsVehicleSeatFree( veh, -1 ) and GetIsTaskActive( ped, 165 ) and not GetIsTaskActive( ped, 2 ) ) then 
                SetPedIntoVehicle( ped, veh, 0 )
            end  
            
            -- if GetPedInVehicleSeat(veh, 0) == ped and IsVehicleSeatFree(veh, -1) and not GetIsTaskActive( ped, 2 ) then
            --     SetPedIntoVehicle( ped, veh, 0 )
            -- end
        end 
    end
end  

Citizen.CreateThread( function()
    while true do 
        ManageAntiShuffle()

        Citizen.Wait( 0 )
    end 
end )

Have you tried CanShuffleSeat(vehicle, false)?
https://runtime.fivem.net/doc/reference.html#_0x30785D90C956BF35

Yeah I did try it, but it didn’t work sadly.

did you ever get this working?

Check this:

Citizen.CreateThread(function()
	while true do
		Citizen.Wait(0)
		if IsPedInAnyVehicle(GetPlayerPed(-1), false) then
			if GetPedInVehicleSeat(GetVehiclePedIsIn(GetPlayerPed(-1), false), 0) == GetPlayerPed(-1) then
				if GetIsTaskActive(GetPlayerPed(-1), 165) then
					SetPedIntoVehicle(GetPlayerPed(-1), GetVehiclePedIsIn(GetPlayerPed(-1), false), 0)
				end
			end
		end
	end
end)

Can anyone confirm if this works? Looking for a good anti shuffle w/o the animation loop and curious if anyone got this one to work for them

isn’t there a way, if task active 165, then disable task 165?

Afaik it is only possible to clear all task, not a specific one

Do you have the program for or how do i name it