[REQUEST] Stop the car when the tire punctures

would anyone have any idea how to stop the car when the tire punctures?

https://runtime.fivem.net/doc/natives/#_0xBA291848A0815CA9

I’m on a train bored so I cannot test this but this should work, it turns the handbrake on when all of the tyres are popped:

local allTyres = true 		--< Do you want vehicle to stop when all tyres are popped or just one?

local tParams = {tyresPopped = 0, isStopped = false, t0 = false, t1 = false, t4 = false, t5 = false, justIn = false}

Citizen.CreateThread(function()
	while true do
		Citizen.Wait(0)
		local me = GetPlayerPed(-1)
		local veh = GetVehiclePedIsIn(me, false)
		
			--Are tyres Popped?--
		if allTyres == true then 
			if IsPedInAnyVehicle(me, false) and tParams.isStopped == false then
				if IsVehicleTyreBurst(veh, 0, false) and tParams.t0 == false then
					tParams.tyresPopped = tParams.tyresPopped + 1
					tParams.t0 = true
				end
				if IsVehicleTyreBurst(veh, 1, false) and tParams.t1 == false then
					tParams.tyresPopped = tParams.tyresPopped + 1
					tParams.t1 = true
				end
				if IsVehicleTyreBurst(veh, 4, false) and tParams.t4 == false then
					tParams.tyresPopped = tParams.tyresPopped + 1
					tParams.t4 = true
				end
				if IsVehicleTyreBurst(veh, 5, false) and tParams.t5 == false then
					tParams.tyresPopped = tParams.tyresPopped + 1
					tParams.t5 = true
				end
			end
		else
			if IsVehicleTyreBurst(veh, 0, false) and tParams.t0 == false then
				tParams.tyresPopped = tParams.tyresPopped + 4
				tParams.t0 = true
				tParams.isStopped = true
			end
			if IsVehicleTyreBurst(veh, 1, false) and tParams.t1 == false then
				tParams.tyresPopped = tParams.tyresPopped + 4
				tParams.t1 = true
				tParams.isStopped = true
			end
			if IsVehicleTyreBurst(veh, 4, false) and tParams.t4 == false then
				tParams.tyresPopped = tParams.tyresPopped + 4
				tParams.t4 = true
				tParams.isStopped = true
			end
			if IsVehicleTyreBurst(veh, 5, false) and tParams.t5 == false then
				tParams.tyresPopped = tParams.tyresPopped + 4
				tParams.t5 = true
				tParams.isStopped = true
			end
		end
				--What to do when tyres are popped?--
		if tParams.tyresPopped >= 4 and tParams.isStopped == false then
			SetVehicleHandbrake(veh, true)
			tParams.isStopped = true
		end
				--This is just to reset everything when getting in new vehicle--
		if IsPedInAnyVehicle(me, false) then
			if tParams.justIn == false then
				tParams.isStopped = false
				tParams.tyresPopped = 0
				tParams.t0 = false
				tParams.t1 = false
				tParams.t4 = false
				tParams.t5 = false
				tParams.justIn = true
			end
		else
			if tParams.justIn == true then
				tParams.justIn = false
			end
		end		
	end
end)
--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

If you want it to apply this when only one tyre has popped then change allTyres at the top of script to false.

While I am here bored on a train I may as well throw this in as well, for testing purposes. If you put this in too, ingame type /tyre over and over to burst your tyres one by one, when they have all burst and you type /tyre again and it will fix the tyres and start the loop all over again.

--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

RegisterCommand("tyre", function()
	local me = GetPlayerPed(-1)
	local veh = GetVehiclePedIsIn(me, false)
	if tParams.isStopped == false then
		if tParams.tyresPopped == 0 then
			SetVehicleTyreBurst(veh, 0, true, 1000.0)
		end
		if tParams.tyresPopped == 1 then
			SetVehicleTyreBurst(veh, 1, true, 1000.0)
		end
		if tParams.tyresPopped == 2 then
			SetVehicleTyreBurst(veh, 4, true, 1000.0)
		end
		if tParams.tyresPopped == 3 then
			SetVehicleTyreBurst(veh, 5, true, 1000.0)
		end
	else
		SetVehicleTyreFixed(veh, 0) tParams.t0 = false
		SetVehicleTyreFixed(veh, 1) tParams.t1 = false
		SetVehicleTyreFixed(veh, 4) tParams.t4 = false
		SetVehicleTyreFixed(veh, 5) tParams.t5 = false
		SetVehicleHandbrake(veh, false)
		tParams.isStopped = false
		tParams.tyresPopped = 0
	end
end)

If I change allTires = true to false on the first shot will it stop the vehicle?

Yes :slight_smile:

1 Like

It didn’t work and when the mechanic tidies up the vehicle it gets frozen in place

I just tested it and it works fine on my end. Although this wasn’t created with other resources in mind, I think when it fixes the vehicle it resets the wheels which makes the script think that the tyres have burst. You will have to mess around with it. I’m still quite new to this so I am not sure if damaging the tyres effects the vehicle health. If it does then you can try adding some code to reset everything when the vehicle health is full. I don’t know though.