[Release] Speedcamera

very nice it work pefectly

seems to work but disappears so fast anyway to get it to scan then freeze at highest speed. also how to set distance to pick up speed?

You can set the distance by changing the value 120.0 in this line:

local entityWorld = GetOffsetFromEntityInWorldCoords(ped, 0.0, 120.0, 0.0)

The smaller, the shorter.
As I can see, this script wasn’t designed to hold the speed, you need to see the car and hold the key to get informations.

Ive ben testing this 120 value, no matter what I change it to, 120 all the way up to 2000 it still only registers the same range ,and that’s about 40 feet in front of you.

After testing a bit more, it appears that CastRayPointToPoint isn’t a very good solution for long distance targetting since it can only detect targets at the same height as you (well in its current state)…

This is the new code I made, It’s open able by pressing L, and lockable by pressing E. Thanks to Clod_TIF for the original script, Cosmo for the improved functions, and Bob_74 for making it compatible for players. Replace the speedcamera.lua with this text.

--script by devilkkw
local radar = {shown = false, freeze = false, info = "none", minSpeed = 10.0, maxSpeed = 40.0}

function drawTxt(x,y ,width,height,scale, text, r,g,b,a)
    SetTextFont(0)
    SetTextProportional(0)
    SetTextScale(scale, scale)
    SetTextColour(r, g, b, a)
    SetTextDropShadow(0, 0, 0, 0,255)
    SetTextEdge(1, 0, 0, 0, 255)
    SetTextDropShadow()
    SetTextOutline()
    SetTextEntry("STRING")
    AddTextComponentString(text)
    DrawText(x - width/2, y - height/2 + 0.005)
end

Citizen.CreateThread(function()
	while true do
		Wait(0)
		if IsControlPressed(1, 7)then -- L
			if radar.shown then radar.shown = false else radar.shown = true end
                        Wait(75)
		end
		if IsControlPressed(1, 38)then -- E
			if radar.freeze then radar.freeze = false else radar.freeze = true end
		end
		if radar.shown then
			if radar.freeze == false then
				local pos = GetEntityCoords(GetPlayerPed(-1))
				local carM = GetCurrentTargetCar()
				if carM ~= nil then
					local plate = GetVehicleNumberPlateText(carM)
					local vehSpeedKM = GetEntitySpeed(carM)*3.6
					local vehSpeedMph = GetEntitySpeed(carM)*2.236936
				
					if vehSpeedKM > radar.minSpeed then			  
						if vehSpeedKM < radar.maxSpeed then 
							radar.info = string.format("~b~Plate:~w~ %s ~n~~y~Km/h: ~g~%s~n~~y~Mph: ~g~%s",plate,math.ceil(vehSpeedKM),math.ceil(vehSpeedMph) )
						else
							radar.info = string.format("~b~Plate:~w~ %s ~n~~y~Km/h: ~r~%s~n~~y~Mph: ~r~%s",plate,math.ceil(vehSpeedKM),math.ceil(vehSpeedMph) )
						end
					end
				end
			end
			DrawRect(0.5,0.0,0.12,0.18,0,10,28,210)
            drawTxt(0.53,0.1,0.185,0.206,0.40,radar.info,255,255,255,255)
		end
	end  
end)

function GetCurrentTargetCar()
    local ped = GetPlayerPed(-1)
    local coords = GetEntityCoords(ped)
   
    local entityWorld = GetOffsetFromEntityInWorldCoords(ped, 0.0, 120.0, 0.0)
    local rayHandle = CastRayPointToPoint(coords.x, coords.y, coords.z, entityWorld.x, entityWorld.y, entityWorld.z, 10, ped, 0)
    local a, b, c, d, vehicleHandle = GetRaycastResult(rayHandle)

    return vehicleHandle
end
3 Likes

How do you turn off controller support for it? everytime I look back (click left thumbstick) the radar appears. I don’t want the controller to be able to activate it. Any help appreciated, thanks.

Is it possible to raycast a radius rather than a direction? @Bob_74

Not with this native, it only cast a ray (a line) and return what it has collided with.
I don’t know how to solve the speed camera issue at the moment but there must be a solution :smiley:

what variables do i change to move the output position it interferes with the compass hud i use thats top middle of screen , thanks :smiley:

-edited didnt look close enough noticed it has both mph and km/h my bad

1 Like

@Bob_74

do you know why the second part of my code is not working?

you just took what cosmo made and called it your own.

Anyway this is a modified version that lets you truely lock it until you press the button again, to run the radar hold E and to lock it press the ~ key while holding E, to unlock hold E and press ~ again.
This also includes the fix for player cars.

--script by devilkkw
local maxSpeed= 73.0
local minSpeed= 1.0
local info ="nope"


function drawTxt(x,y ,width,height,scale, text, r,g,b,a)
    SetTextFont(0)
    SetTextProportional(0)
    SetTextScale(scale, scale)
    SetTextColour(r, g, b, a)
    SetTextDropShadow(0, 0, 0, 0,255)
    SetTextEdge(1, 0, 0, 0, 255)
    SetTextDropShadow()
    SetTextOutline()
    SetTextEntry("STRING")
    AddTextComponentString(text)
    DrawText(x - width/2, y - height/2 + 0.005)
end
local locked = false
local speed1 = 0.0
local speed2 = 0.0
local plates = ""
Citizen.CreateThread(function()
	while true do
		Wait(0)
			if locked then
				if speed1 < maxSpeed then 
			      
				  info = string.format("~b~Plate:~w~ %s ~n~~y~Km/h: ~g~%s~n~~y~Mph: ~g~%s",plates,math.ceil(speed1),math.ceil(speed2) )
				 else
				  
				  info = string.format("~b~Plate:~w~ %s ~n~~y~Km/h: ~r~%s~n~~y~Mph: ~r~%s",plates,math.ceil(speed1),math.ceil(speed2) )
				  
				end 
				DrawRect(0.5,0.0,0.12,0.18,0,10,28,210)
                 drawTxt(0.55,0.1,0.185,0.206, 0.40, info, 255,255,255,255)
			end
		  if IsControlPressed(1, 38)then
		    local pos = GetEntityCoords(GetPlayerPed(-1))
			 local carM = GetCurrentTargetCar()
			 
			 if carM ~=nil then
				--TriggerEvent("chatMessage", "FIRE", {255, 0, 0},"test string: " .. tostring(carM))
				--local num = tostring(GetPlayerPed(GetPedInVehicleSeat(carM, -1)))
				--local num = true
				--if num ~= nil and num ~= "" and num ~= "0" then
			      local plate=GetVehicleNumberPlateText(carM)
			      local herSpeedKm= GetEntitySpeed(carM)*3.6
			      local herSpeedMph= GetEntitySpeed(carM)*2.236936
			 if IsControlJustPressed(0, 243) then
					PlaySoundFrontend(-1, "SELECT", "HUD_FRONTEND_DEFAULT_SOUNDSET", false)
					if not locked then
					locked = true
					speed1 = herSpeedKm
					speed2 = herSpeedMph
					plates = plate
					else
						locked = false
					end
				end
			
			 if herSpeedKm > minSpeed and not locked then			 
			         
			    if herSpeedKm < maxSpeed then 
			      
				  info = string.format("~b~Plate:~w~ %s ~n~~y~Km/h: ~g~%s~n~~y~Mph: ~g~%s",plate,math.ceil(herSpeedKm),math.ceil(herSpeedMph) )
				 else
				  
				  info = string.format("~b~Plate:~w~ %s ~n~~y~Km/h: ~r~%s~n~~y~Mph: ~r~%s",plate,math.ceil(herSpeedKm),math.ceil(herSpeedMph) )
				  
				end 
				
				 DrawRect(0.5,0.0,0.12,0.18,0,10,28,210)
                 drawTxt(0.55,0.1,0.185,0.206, 0.40, info, 255,255,255,255)
			     
			 end
			 --end
			 end
		
	   end
	 end  
end)

function GetCurrentTargetCar()
    local ped = GetPlayerPed(-1)
    local coords = GetEntityCoords(ped)
   
    local entityWorld = GetOffsetFromEntityInWorldCoords(ped, 0.0, 1000.0, 0.0)
    local rayHandle = CastRayPointToPoint(coords.x, coords.y, coords.z, entityWorld.x, entityWorld.y, entityWorld.z, 30, ped, 0)
    local a, b, c, d, vehicleHandle = GetRaycastResult(rayHandle)

    return vehicleHandle
end

Hey i changed the speedcamera lua with this and its not working

Should work, do you have any errors you can tell me?

I put the code above yours and works. Idk

I tried your code and when I press E it doesnt display

You have to be right behind a car and moving with it… This is very sketchy and I think someone needs to convert Real Speed Radar to FiveM… I am currently working an that but having a tough time

Yeah I have just noticed

Sorry for no replies guys, i have been very busy. Yes it is quite temperamental, and you dont have to be in a car moving with them, but that does help. You have to be on the same or near the same z axis as them. I will look into making it act a little better, but for now im a little busy.

1 Like

No worries… I still use it cause it works lol