[Release] Speedcamera

That worked great @Cosmo , i can scan 4 lanes of US 13

Hey @Cosmo Where at in the speedcamera.lua would I drop the lines of code for the getnearplayerspeed?
Thanks in advance

So this is fixed for players now?? Ain’t no way

can everyone on the server use this? how can it be restricted to police only if it isn’t already?

@Clod_TIF is there any reason why it looks like you abandoned this? Did you ever get it working for players?

I changed the way it detects vehicles, I think it should fix the problem with players cars.

I used the solution provided here:

--script by devilkkw
local maxSpeed= 40.0
local minSpeed= 10.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

Citizen.CreateThread(function()
    while true do
        Wait(0)
          if IsControlPressed(1, 217)then	-- 217 	INPUT_FRONTEND_SELECT (CapsLock)
            local pos = GetEntityCoords(GetPlayerPed(-1))
             local carM = GetCurrentTargetCar()
             if carM ~=nil then
                  local plate=GetVehicleNumberPlateText(carM)
                  local herSpeedKm= GetEntitySpeed(carM)*3.6
                  local herSpeedMph= GetEntitySpeed(carM)*2.236936
             
             if herSpeedKm > minSpeed 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)

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

It uses GetRaycastResult (you need to target the vehicle) instead of GetClosestVehicle.

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?