Working on a Police Radar

Hi guys,
I’m creating a new Police Radar system
I’ve got a big problem, when the cars move out from the front of my car i loose istantaneously their speed (if i don’t block it that is a feature that i’m programming now).

I’ve tried to use Wait(1000), but the radar just appear and disappear every 1 second. Can you help me?

Code:

	while true do
		Wait(0)
		if IsControlJustPressed(1, 128) and IsPedInAnyPoliceVehicle(GetPlayerPed(-1)) and not IsPedInAnyHeli(GetPlayerPed(-1)) then
			
			if radar.shown then 
				radar.shown = false 
				radar.info = string.format("--")
				radar.info2 = string.format("--")
				radar.info3 = string.format("--")
			else 
				radar.shown = true 
			end
		end
		if IsControlJustPressed(1, 127) and IsPedInAnyPoliceVehicle(GetPlayerPed(-1)) and not IsPedInAnyHeli(GetPlayerPed(-1)) then
			PlaySoundFrontend(-1,  "Beep_Red", "DLC_HEIST_HACKING_SNAKE_SOUNDS", 0,0,1)
			if radar.freeze then
				radar.freeze = false
			else
				radar.freeze = true 
			end
	
		end
		
		if radar.shown  then
			if radar.freeze == false then
					local veh = GetVehiclePedIsIn(GetPlayerPed(-1), false)
					local coordA = GetOffsetFromEntityInWorldCoords(veh, 0.0, 1.0, 1.0)
					local coordB = GetOffsetFromEntityInWorldCoords(veh, 0.0, 105.0, 0.0)
					local frontcar = StartShapeTestCapsule(coordA, coordB, 3.0, 10, veh, 7)
					local a, b, c, d, e = GetShapeTestResult(frontcar)
					
					if IsEntityAVehicle(e) then
						
						local fmodel = GetDisplayNameFromVehicleModel(GetEntityModel(e))
						local fvspeed = GetEntitySpeed(e)*3.6
						local fplate = GetVehicleNumberPlateText(e)
						radar.info = string.format("%s", math.ceil(fvspeed))
					else
						local fvspeed = '--'
						radar.info = string.format("%s", fvspeed)
					end
					
					local bcoordB = GetOffsetFromEntityInWorldCoords(veh, 0.0, -105.0, 0.0)
					local rearcar = StartShapeTestCapsule(coordA, bcoordB, 3.0, 10, veh, 7)
					local f, g, h, i, j = GetShapeTestResult(rearcar)
					
					if IsEntityAVehicle(j) then
						local bmodel = GetDisplayNameFromVehicleModel(GetEntityModel(j))
						local bvspeed = GetEntitySpeed(j)*3.6
						local bplate = GetVehicleNumberPlateText(j)
						radar.info2 = string.format("%s", math.ceil(bvspeed))
					else
						local bvspeed = '--'
						radar.info2 = string.format("%s", bvspeed)
					end
					
			end

The plugin is based on another plugin outsurce. I’m just editing it to fit my needs

Bare with me as I am no pro, just thinking out loud here…

It may be this line here, you’re checking to see if they’re in a police vehicle, then you’re getting out of said police vehicle so there isn’t anything telling it to retain that speed even when you get out…if that makes sense?

if IsControlJustPressed(1, 127) and IsPedInAnyPoliceVehicle(GetPlayerPed(-1)) and not IsPedInAnyHeli(GetPlayerPed(-1)) then

Nope, It isn’t my problem,

My problem is that, when he don’t see a vehicle in front of him, it must stop himself for just 1-2 second, and only then reset.

Locking speed is another problem that i’haven’t coded yet :slight_smile:

Do all the stuff to do with getting the vehicles speed in a different loop or do displaying the actual radar in a different loop. Otherwise you are causing everything in the loop to pause, not just the speed, causing the radar to not appear.

???

This looks pretty similar to Brocks ALPR :thinking: https://www.diffchecker.com/MAgFtAL5

It probably is…

hello how can I change the radar place for example leave it up and not down as it comes by default

hello how can I change the radar place for example leave it up and not down as it comes by defaultT

where would you Put That code?