TaskLeaveVehicle flags not seeming to work

#1
ClearPedTasksImmediately(ped)
TaskLeaveVehicle(ped,vehicle,4160)
RemoveAllPedWeapons(PlayerPedId(),false)

I’m trying to get the player’s departure from the vehicle to be less teleport-y and abrupt and make it look more natural but despite the native’s page’s instruction on flags and what they mean, no matter what I choose (0, 1, 64, 4160), it always looks like I’m using 16(teleports out of car with door remaining closed)

Can someone tell me what I’m doing wrong that it’s not respecting the flag?

0 Likes

#2

odd, I have used that native, but it seemed to work ok for me iirc, I think. What happens if you remove clearpedtasksimmediately? or use clearpedtasks instead? also, try a different vehicle to see if that makes a difference.

0 Likes

#3

Thanks for the help! Most of my coding-related topics have been met with absolute silence lately. I had begun to think I had been ghosted :slight_smile:

I tried different vehicles(car, bike, truck) and I both commented and changed clearpedtasksimmediately but every time, my character visually is one moment sitting in the vehicle and the next standing outside of it. I also tried adding a 2 second pause between each step to allow it to follow through but that didn’t matter either.

I’m not sure what else to try. It’s a very basic script that looks for non police to be sitting in or on a police vehicle’s driver position and if it meets those conditions, removes them from the vehicle and strips their weapons. There’s really not much complexity to it.

Citizen.CreateThread(function()
	while Config.kickFromPolice == true do
		Citizen.Wait(1000)
		if (AntiCheat == true and whitelisted == false and whiteCheck == false)then
			local vehicle = GetVehiclePedIsIn(GetPlayerPed(-1), false)
			local ped = GetPlayerPed(-1)
			local vehicleClass = GetVehicleClass(vehicle)
			PlayerData = ESX.GetPlayerData()
			
			if vehicleClass == 18 and GetPedInVehicleSeat(vehicle, -1) == ped then
				--print('SV: In service vehicle')
				if PlayerData.job.name ~= 'police' and PlayerData.job.name ~= 'ambulance' and PlayerData.job.name ~= 'mecano' then
					--print('SV: Not proper job')
					ClearPedTasks(ped, true)
        			TaskLeaveVehicle(ped, vehicle, 64)
					RemoveAllPedWeapons(PlayerPedId(),false)
					TriggerEvent('esx:showNotification', 'This vehicle is not meant for you.')
					TriggerEvent('esx:showNotification', 'We thank you for your generous donation of weapons.')

					
				end
			end
		end
	end
end)
0 Likes

#4

Your code looks OK, like it should work. Did you try it without it being in a loop? Or make the Wait 5000 or something to test. The other thing could be setting the combat attribute to be 3 (dont leave vehicle, but I doubt that you are doing that on a player ped), maybe there are other settings applied to the player in other resources. Good way to test is to have a very simple test resource just calling that task w.o. 3rd party resources to see if that works, to rule out other resources etc…

0 Likes

#5

Excuse my ignorance but how would you check without it being in a loop? I’m not sure I would go about accomplishing that.

0 Likes

#6

np. Just make the loop like Wait 5000 for testing. Enough time to allow the ped to get out of the vehicle completely before TaskLeave… is called again.

0 Likes

#7

Gave it ten seconds to work it’s magic. Still an instant teleport outside the vehicle:

			if PlayerData.job.name ~= 'police' and PlayerData.job.name ~= 'ambulance' and PlayerData.job.name ~= 'mecano' then
				
				if vehicleClass == 18 and GetPedInVehicleSeat(vehicle, -1) == ped then
					
					ClearPedTasksImmediately(ped, true)
					TaskLeaveVehicle(ped, vehicle, 64)
					RemoveAllPedWeapons(PlayerPedId(),false)
					TriggerEvent('esx:showNotification', 'This vehicle is not meant for you.')
					TriggerEvent('esx:showNotification', 'We thank you for your generous donation of weapons.')
					Citizen.Wait(10000)
					
				end
			end
0 Likes

#8

Do you have other 3rd party resources removed? And just a test resource with a simple loop that would cause all peds (via enumeratepeds) to leave vehicles with vanilla FiveM? If that fails, maybe try different resource manifest versions. Basically try to rule out if it something else causing it. Your code looks OK.

0 Likes