Amazing script! Could you possibly make the spotlight follow the camera?
Curtis
Amazing script! Could you possibly make the spotlight follow the camera?
Curtis
read his last comment.
Crash when pressed X to rappel :’( California Video Error#
Relog try again, Sounds likes a regular crash
Its OK because i have install skin model.
Anyway you can add controller support?
X key crashes anyone on our server and Search light does not come on with the G key, I wonder if the G key is conflicting with other scripts.
It seems rappel doesn’t work with modded polmav. Not interested in fixing this.
Edit: It doesn’t work with some modded polmavs.
Anyone know how to adjust the angle of the spotlight? Would like it to aim more downward instead of straight, trying to track a person or car with it is tough cause you have to pretty much angle forward in the heli which increases speed .
That’s not entirely true actually. I’m playing with a modded polmav and it works great. I think the difference is that it has to be a similar to the polmav. It can’t be like an apache and bare no resemblance. I’m playing with an LAPD AS350.
For those of you that want to limit the function of the helicopter, which as-is is OP.
Comment out the locals on line 11 and 14 to remove Nightvision/FLIR and Lock-on.
Just a heads up, it works great!
Can we make it work with addon vehicles?
Possible to use SET_MOUNTED_WEAPON_TARGET to control the spotlight?
that makes sense. let’s see if he can do it. but doesn’t that require the polmav to inherently support that? I’m probably wrong just curious
The default GTA polmav does support it, just need to work out how to get the native to work.
for the people who want the search lite to follow the camera I have tried this many different ways but the only real way to do it is to use DrawSpotLight however this function and its other function called DrawSpotLightWithShadow just simply doesnt seem to be working in this version of fivem sadly.
Now if all your after is a light that actually makes the people visible that you are chasing thes here is my modified code. q turns on the light and y/n turns the intensity up and down.
-- FiveM Heli Cam by mraes
-- Version 1.3 2017-06-12
-- config
local clientside_light = true
local fov_max = 80.0
local fov_min = 10.0 -- max zoom level (smaller fov is more zoom)
local zoomspeed = 2.0 -- camera zoom speed
local speed_lr = 3.0 -- speed by which the camera pans left-right
local speed_ud = 3.0 -- speed by which the camera pans up-down
local toggle_helicam = 51 -- control id of the button by which to toggle the helicam mode. Default: INPUT_CONTEXT (E)
local toggle_vision = 25 -- control id to toggle vision mode. Default: INPUT_AIM (Right mouse btn)
local toggle_rappel = 154 -- control id to rappel out of the heli. Default: INPUT_DUCK (X)
local toggle_spotlight = 183 -- control id to toggle the front spotlight Default: INPUT_PhoneCameraGrid (G)
local toggle_lock_on = 22 -- control id to lock onto a vehicle with the camera. Default is INPUT_SPRINT (spacebar)
-- Script starts here
local helicam = false
local polmav_hash = GetHashKey("polmav")
local helicam = false
local brightness = 20.0
local fov = (fov_max+fov_min)*0.5
local vision_state = 0 -- 0 is normal, 1 is nightmode, 2 is thermal vision
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
if IsPlayerInPolmav() then
local lPed = GetPlayerPed(-1)
local heli = GetVehiclePedIsIn(lPed)
if IsHeliHighEnough(heli) then
if IsControlJustPressed(0, toggle_helicam) then -- Toggle Helicam
PlaySoundFrontend(-1, "SELECT", "HUD_FRONTEND_DEFAULT_SOUNDSET", false)
helicam = true
end
if IsControlJustPressed(0, toggle_rappel) then -- Initiate rappel
Citizen.Trace("try to rappel")
if GetPedInVehicleSeat(heli, 1) == lPed or GetPedInVehicleSeat(heli, 2) == lPed then
PlaySoundFrontend(-1, "SELECT", "HUD_FRONTEND_DEFAULT_SOUNDSET", false)
TaskRappelFromHeli(GetPlayerPed(-1), 1)
else
SetNotificationTextEntry( "STRING" )
AddTextComponentString("~r~Can't rappel from this seat")
DrawNotification(false, false )
PlaySoundFrontend(-1, "5_Second_Timer", "DLC_HEISTS_GENERAL_FRONTEND_SOUNDS", false)
end
end
end
if IsControlJustPressed(0, toggle_spotlight) and GetPedInVehicleSeat(heli, -1) == lPed then
spotlight_state = not spotlight_state
TriggerServerEvent("heli:spotlight", spotlight_state)
PlaySoundFrontend(-1, "SELECT", "HUD_FRONTEND_DEFAULT_SOUNDSET", false)
end
end
if helicam then
SetTimecycleModifier("heliGunCam")
SetTimecycleModifierStrength(0.3)
local scaleform = RequestScaleformMovie("HELI_CAM")
while not HasScaleformMovieLoaded(scaleform) do
Citizen.Wait(0)
end
local lPed = GetPlayerPed(-1)
local heli = GetVehiclePedIsIn(lPed)
local cam = CreateCam("DEFAULT_SCRIPTED_FLY_CAMERA", true)
AttachCamToEntity(cam, heli, 0.0,0.0,-1.5, true)
SetCamRot(cam, 0.0,0.0,GetEntityHeading(heli))
SetCamFov(cam, fov)
RenderScriptCams(true, false, 0, 1, 0)
PushScaleformMovieFunction(scaleform, "SET_CAM_LOGO")
PushScaleformMovieFunctionParameterInt(1) -- 0 for nothing, 1 for LSPD logo
PopScaleformMovieFunctionVoid()
local locked_on_vehicle = nil
while helicam and not IsEntityDead(lPed) and (GetVehiclePedIsIn(lPed) == heli) and IsHeliHighEnough(heli) do
if IsControlJustPressed(0, toggle_helicam) then -- Toggle Helicam
PlaySoundFrontend(-1, "SELECT", "HUD_FRONTEND_DEFAULT_SOUNDSET", false)
helicam = false
end
if IsControlJustPressed(0, toggle_vision) then
PlaySoundFrontend(-1, "SELECT", "HUD_FRONTEND_DEFAULT_SOUNDSET", false)
ChangeVision()
end
if IsControlJustPressed(0, 44) then
PlaySoundFrontend(-1, "SELECT", "HUD_FRONTEND_DEFAULT_SOUNDSET", false)
if helilight then
helilight = false
else
helilight = true
end
end
if IsControlJustPressed(0, 246) then
PlaySoundFrontend(-1, "SELECT", "HUD_FRONTEND_DEFAULT_SOUNDSET", false)
if helilight then
brightness = lightUp(brightness)
end
end
if IsControlJustPressed(0, 249) then
PlaySoundFrontend(-1, "SELECT", "HUD_FRONTEND_DEFAULT_SOUNDSET", false)
if helilight then
brightness = lightDown(brightness)
end
end
if locked_on_vehicle then
if DoesEntityExist(locked_on_vehicle) then
PointCamAtEntity(cam, locked_on_vehicle, 0.0, 0.0, 0.0, true)
RenderVehicleInfo(locked_on_vehicle)
if IsControlJustPressed(0, toggle_lock_on) then
PlaySoundFrontend(-1, "SELECT", "HUD_FRONTEND_DEFAULT_SOUNDSET", false)
locked_on_vehicle = nil
local rot = GetCamRot(cam, 2) -- All this because I can't seem to get the camera unlocked from the entity
local fov = GetCamFov(cam)
local old cam = cam
DestroyCam(old_cam, false)
cam = CreateCam("DEFAULT_SCRIPTED_FLY_CAMERA", true)
AttachCamToEntity(cam, heli, 0.0,0.0,-1.5, true)
SetCamRot(cam, rot, 2)
SetCamFov(cam, fov)
RenderScriptCams(true, false, 0, 1, 0)
end
else
locked_on_vehicle = nil -- Cam will auto unlock when entity doesn't exist anyway
end
else
local zoomvalue = (1.0/(fov_max-fov_min))*(fov-fov_min)
CheckInputRotation(cam, zoomvalue)
local vehicle_detected = GetVehicleInView(cam)
if DoesEntityExist(vehicle_detected) then
RenderVehicleInfo(vehicle_detected)
if IsControlJustPressed(0, toggle_lock_on) then
PlaySoundFrontend(-1, "SELECT", "HUD_FRONTEND_DEFAULT_SOUNDSET", false)
locked_on_vehicle = vehicle_detected
end
end
end
HandleZoom(cam)
HideHUDThisFrame()
PushScaleformMovieFunction(scaleform, "SET_ALT_FOV_HEADING")
PushScaleformMovieFunctionParameterFloat(GetEntityCoords(heli).z)
PushScaleformMovieFunctionParameterFloat(zoomvalue)
PushScaleformMovieFunctionParameterFloat(GetCamRot(cam, 2).z)
PopScaleformMovieFunctionVoid()
DrawScaleformMovieFullscreen(scaleform, 255, 255, 255, 255)
if helilight and clientside_light then
DrawLightWithRange(GetEntityCoords(heli).x, GetEntityCoords(heli).y, GetEntityCoords(heli).z, 255, 255, 255, 350.0, brightness)
end
Citizen.Wait(0)
end
helicam = false
ClearTimecycleModifier()
fov = (fov_max+fov_min)*0.5 -- reset to starting zoom level
RenderScriptCams(false, false, 0, 1, 0) -- Return to gameplay camera
SetScaleformMovieAsNoLongerNeeded(scaleform) -- Cleanly release the scaleform
DestroyCam(cam, false)
SetNightvision(false)
SetSeethrough(false)
end
end
end)
function lightUp(brightness)
brightness = brightness+5.0
return brightness
end
function lightDown(brightness)
brightness = brightness-5.0
return brightness
end
RegisterNetEvent('heli:spotlight')
AddEventHandler('heli:spotlight', function(serverID, state)
local heli = GetVehiclePedIsIn(GetPlayerPed(GetPlayerFromServerId(serverID)), false)
SetVehicleSearchlight(heli, state, false)
Citizen.Trace("Set heli light state to "..tostring(state).." for serverID: "..serverID)
end)
function IsPlayerInPolmav()
local lPed = GetPlayerPed(-1)
local vehicle = GetVehiclePedIsIn(lPed)
return IsVehicleModel(vehicle, polmav_hash)
end
function IsHeliHighEnough(heli)
return GetEntityHeightAboveGround(heli) > 1.5
end
function ChangeVision()
if vision_state == 0 then
SetNightvision(true)
vision_state = 1
elseif vision_state == 1 then
SetNightvision(false)
SetSeethrough(true)
vision_state = 2
else
SetSeethrough(false)
vision_state = 0
end
end
function HideHUDThisFrame()
HideHelpTextThisFrame()
HideHudAndRadarThisFrame()
HideHudComponentThisFrame(19) -- weapon wheel
HideHudComponentThisFrame(1) -- Wanted Stars
HideHudComponentThisFrame(2) -- Weapon icon
HideHudComponentThisFrame(3) -- Cash
HideHudComponentThisFrame(4) -- MP CASH
HideHudComponentThisFrame(13) -- Cash Change
HideHudComponentThisFrame(11) -- Floating Help Text
HideHudComponentThisFrame(12) -- more floating help text
HideHudComponentThisFrame(15) -- Subtitle Text
HideHudComponentThisFrame(18) -- Game Stream
end
function CheckInputRotation(cam, zoomvalue)
local rightAxisX = GetDisabledControlNormal(0, 220)
local rightAxisY = GetDisabledControlNormal(0, 221)
local rotation = GetCamRot(cam, 2)
if rightAxisX ~= 0.0 or rightAxisY ~= 0.0 then
new_z = rotation.z + rightAxisX*-1.0*(speed_ud)*(zoomvalue+0.1)
new_x = math.max(math.min(20.0, rotation.x + rightAxisY*-1.0*(speed_lr)*(zoomvalue+0.1)), -89.5) -- Clamping at top (cant see top of heli) and at bottom (doesn't glitch out in -90deg)
SetCamRot(cam, new_x, 0.0, new_z, 2)
end
end
function HandleZoom(cam)
if IsControlJustPressed(0,241) then -- Scrollup
fov = math.max(fov - zoomspeed, fov_min)
end
if IsControlJustPressed(0,242) then
fov = math.min(fov + zoomspeed, fov_max) -- ScrollDown
end
local current_fov = GetCamFov(cam)
if math.abs(fov-current_fov) < 0.1 then -- the difference is too small, just set the value directly to avoid unneeded updates to FOV of order 10^-5
fov = current_fov
end
SetCamFov(cam, current_fov + (fov - current_fov)*0.05) -- Smoothing of camera zoom
end
function GetVehicleInView(cam)
local coords = GetCamCoord(cam)
local forward_vector = RotAnglesToVec(GetCamRot(cam, 2))
--DrawLine(coords, coords+(forward_vector*100.0), 255,0,0,255) -- debug line to show LOS of cam
local rayhandle = CastRayPointToPoint(coords, coords+(forward_vector*200.0), 10, GetVehiclePedIsIn(GetPlayerPed(-1)), 0)
local _, _, _, _, entityHit = GetRaycastResult(rayhandle)
if entityHit>0 and IsEntityAVehicle(entityHit) then
return entityHit
else
return nil
end
end
function RenderVehicleInfo(vehicle)
local model = GetEntityModel(vehicle)
local vehname = GetLabelText(GetDisplayNameFromVehicleModel(model))
local licenseplate = GetVehicleNumberPlateText(vehicle)
SetTextFont(0)
SetTextProportional(1)
SetTextScale(0.0, 0.55)
SetTextColour(255, 255, 255, 255)
SetTextDropshadow(0, 0, 0, 0, 255)
SetTextEdge(1, 0, 0, 0, 255)
SetTextDropShadow()
SetTextOutline()
SetTextEntry("STRING")
AddTextComponentString("Model: "..vehname.."\nPlate: "..licenseplate)
DrawText(0.45, 0.9)
end
-- function HandleSpotlight(cam)
-- if IsControlJustPressed(0, toggle_spotlight) then
-- PlaySoundFrontend(-1, "SELECT", "HUD_FRONTEND_DEFAULT_SOUNDSET", false)
-- spotlight_state = not spotlight_state
-- end
-- if spotlight_state then
-- local rotation = GetCamRot(cam, 2)
-- local forward_vector = RotAnglesToVec(rotation)
-- local camcoords = GetCamCoord(cam)
-- DrawSpotLight(camcoords, forward_vector, 255, 255, 255, 300.0, 10.0, 0.0, 2.0, 1.0)
-- end
-- end
function RotAnglesToVec(rot) -- input vector3
local z = math.rad(rot.z)
local x = math.rad(rot.x)
local num = math.abs(math.cos(x))
return vector3(-math.sin(z)*num, math.cos(z)*num, math.sin(x))
end
Sadly i can’t use this great script. i can only use it once then i have to restart FiveM to do it again.
love this script anyway to make something similar for a Police Vehicle to be used as a dash cam maybe ?
some people using this script on my server want to know if it’s possible to have an altimeter on the camera hud?
It has an altimeter on the left though?