Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.44 KB | None | 0 0
  1. -- FiveM Heli Cam by mraes
  2. -- Version 1.3 2017-06-12
  3.  
  4. -- config
  5. local fov_max = 80.0
  6. local fov_min = 10.0 -- max zoom level (smaller fov is more zoom)
  7. local zoomspeed = 2.0 -- camera zoom speed
  8. local speed_lr = 3.0 -- speed by which the camera pans left-right
  9. local speed_ud = 3.0 -- speed by which the camera pans up-down
  10. local toggle_helicam = 51 -- control id of the button by which to toggle the helicam mode. Default: INPUT_CONTEXT (G)
  11. local toggle_vision = 25 -- control id to toggle vision mode. Default: INPUT_AIM (Right mouse btn)
  12. local toggle_rappel = 22 -- control id to rappel out of the heli. Default: INPUT_DUCK (spacebar)
  13. local toggle_spotlight = 183 -- control id to toggle the front spotlight Default: INPUT_PhoneCameraGrid (E)
  14. local toggle_lock_on = 18 -- control id to lock onto a vehicle with the camera. Default is INPUT_SPRINT (enter)
  15.  
  16. -- Script starts here
  17. local helicam = false
  18. local polmav_hash = GetHashKey("polmav")
  19. local frogger_hash = GetHashKey("frogger2")
  20. local lssdh_hash = GetHashKey("LSSDH1")
  21. local swat_hash = GetHashKey("SWATH1")
  22.  
  23. local fov = (fov_max+fov_min)*0.5
  24. local vision_state = 2 -- 0 is normal, 1 is nightmode, 2 is thermal vision
  25. Citizen.CreateThread(function()
  26. while true do
  27. Citizen.Wait(0)
  28. if IsPlayerInPolmav() or IsPlayerInFrogger() or IsPlayerInLSSDH() or IsPlayerInSwatt() then
  29. local lPed = GetPlayerPed(-1)
  30. local heli = GetVehiclePedIsIn(lPed)
  31.  
  32. if IsHeliHighEnough(heli) then
  33. if IsControlJustPressed(0, toggle_helicam) then -- Toggle Helicam
  34. PlaySoundFrontend(-1, "SELECT", "HUD_FRONTEND_DEFAULT_SOUNDSET", false)
  35. helicam = true
  36. end
  37.  
  38. if IsControlJustPressed(0, toggle_rappel) then -- Initiate rappel
  39. Citizen.Trace("try to rappel")
  40. if GetPedInVehicleSeat(heli, 1) == lPed or GetPedInVehicleSeat(heli, 2) == lPed then
  41. PlaySoundFrontend(-1, "SELECT", "HUD_FRONTEND_DEFAULT_SOUNDSET", false)
  42. TaskRappelFromHeli(GetPlayerPed(-1), 1)
  43. else
  44. SetNotificationTextEntry( "STRING" )
  45. AddTextComponentString("~r~Vous ne pouvez pas descendre en rappel depuis ce siège.")
  46. DrawNotification(false, false )
  47. PlaySoundFrontend(-1, "5_Second_Timer", "DLC_HEISTS_GENERAL_FRONTEND_SOUNDS", false)
  48. end
  49. end
  50. end
  51.  
  52. if IsControlJustPressed(0, toggle_spotlight) and GetPedInVehicleSeat(heli, -1) == lPed then
  53. spotlight_state = not spotlight_state
  54. TriggerServerEvent("heli:spotlight", spotlight_state)
  55. PlaySoundFrontend(-1, "SELECT", "HUD_FRONTEND_DEFAULT_SOUNDSET", false)
  56. end
  57.  
  58. end
  59.  
  60. if helicam then
  61. SetTimecycleModifier("heliGunCam")
  62. SetTimecycleModifierStrength(0.3)
  63. local scaleform = RequestScaleformMovie("HELI_CAM")
  64. while not HasScaleformMovieLoaded(scaleform) do
  65. Citizen.Wait(0)
  66. end
  67. local lPed = GetPlayerPed(-1)
  68. local heli = GetVehiclePedIsIn(lPed)
  69. local cam = CreateCam("DEFAULT_SCRIPTED_FLY_CAMERA", true)
  70. AttachCamToEntity(cam, heli, 0.0,0.0,-1.5, true)
  71. SetCamRot(cam, 0.0,0.0,GetEntityHeading(heli))
  72. SetCamFov(cam, fov)
  73. RenderScriptCams(true, false, 0, 1, 0)
  74. PushScaleformMovieFunction(scaleform, "SET_CAM_LOGO")
  75. PushScaleformMovieFunctionParameterInt(1) -- 0 for nothing, 1 for LSPD logo
  76. PopScaleformMovieFunctionVoid()
  77. local locked_on_vehicle = nil
  78. while helicam and not IsEntityDead(lPed) and (GetVehiclePedIsIn(lPed) == heli) and IsHeliHighEnough(heli) do
  79.  
  80. if IsControlJustPressed(0, toggle_helicam) then -- Toggle Helicam
  81. PlaySoundFrontend(-1, "SELECT", "HUD_FRONTEND_DEFAULT_SOUNDSET", false)
  82. helicam = false
  83. end
  84. if IsControlJustPressed(0, toggle_vision) then
  85. PlaySoundFrontend(-1, "SELECT", "HUD_FRONTEND_DEFAULT_SOUNDSET", false)
  86. ChangeVision()
  87. end
  88. if locked_on_vehicle then
  89. if DoesEntityExist(locked_on_vehicle) then
  90. PointCamAtEntity(cam, locked_on_vehicle, 0.0, 0.0, 0.0, true)
  91. RenderVehicleInfo(locked_on_vehicle)
  92. if IsControlJustPressed(0, toggle_lock_on) then
  93. PlaySoundFrontend(-1, "SELECT", "HUD_FRONTEND_DEFAULT_SOUNDSET", false)
  94. locked_on_vehicle = nil
  95. local rot = GetCamRot(cam, 2) -- All this because I can't seem to get the camera unlocked from the entity
  96. local fov = GetCamFov(cam)
  97. local old cam = cam
  98. DestroyCam(old_cam, false)
  99. cam = CreateCam("DEFAULT_SCRIPTED_FLY_CAMERA", true)
  100. AttachCamToEntity(cam, heli, 0.0,0.0,-1.5, true)
  101. SetCamRot(cam, rot, 2)
  102. SetCamFov(cam, fov)
  103. RenderScriptCams(true, false, 0, 1, 0)
  104. end
  105. else
  106. locked_on_vehicle = nil -- Cam will auto unlock when entity doesn't exist anyway
  107. end
  108. else
  109. local zoomvalue = (1.0/(fov_max-fov_min))*(fov-fov_min)
  110. CheckInputRotation(cam, zoomvalue)
  111. local vehicle_detected = GetVehicleInView(cam)
  112. if DoesEntityExist(vehicle_detected) then
  113. RenderVehicleInfo(vehicle_detected)
  114. if IsControlJustPressed(0, toggle_lock_on) then
  115. PlaySoundFrontend(-1, "SELECT", "HUD_FRONTEND_DEFAULT_SOUNDSET", false)
  116. locked_on_vehicle = vehicle_detected
  117. end
  118. end
  119. end
  120. HandleZoom(cam)
  121. HideHUDThisFrame()
  122. PushScaleformMovieFunction(scaleform, "SET_ALT_FOV_HEADING")
  123. PushScaleformMovieFunctionParameterFloat(GetEntityCoords(heli).z)
  124. PushScaleformMovieFunctionParameterFloat(zoomvalue)
  125. PushScaleformMovieFunctionParameterFloat(GetCamRot(cam, 2).z)
  126. PopScaleformMovieFunctionVoid()
  127. DrawScaleformMovieFullscreen(scaleform, 255, 255, 255, 255)
  128. Citizen.Wait(0)
  129. end
  130. helicam = false
  131. ClearTimecycleModifier()
  132. fov = (fov_max+fov_min)*0.5 -- reset to starting zoom level
  133. RenderScriptCams(false, false, 0, 1, 0) -- Return to gameplay camera
  134. SetScaleformMovieAsNoLongerNeeded(scaleform) -- Cleanly release the scaleform
  135. DestroyCam(cam, false)
  136. SetNightvision(false)
  137. SetSeethrough(false)
  138. end
  139. end
  140. end)
  141.  
  142. RegisterNetEvent('heli:spotlight')
  143. AddEventHandler('heli:spotlight', function(serverID, state)
  144. local heli = GetVehiclePedIsIn(GetPlayerPed(GetPlayerFromServerId(serverID)), false)
  145. SetVehicleSearchlight(heli, state, false)
  146. Citizen.Trace("Set heli light state to "..tostring(state).." for serverID: "..serverID)
  147. end)
  148.  
  149. function IsPlayerInPolmav()
  150. local lPed = GetPlayerPed(-1)
  151. local vehicle = GetVehiclePedIsIn(lPed)
  152. return IsVehicleModel(vehicle, polmav_hash)
  153. end
  154.  
  155. function IsPlayerInFrogger()
  156. local lPed = GetPlayerPed(-1)
  157. local vehicle = GetVehiclePedIsIn(lPed)
  158. return IsVehicleModel(vehicle, frogger_hash)
  159. end
  160.  
  161. function IsPlayerInSwatt()
  162. local lPed = GetPlayerPed(-1)
  163. local vehicle = GetVehiclePedIsIn(lPed)
  164. return IsVehicleModel(vehicle, swat_hash)
  165. end
  166.  
  167. function IsPlayerInLSSDH()
  168. local lPed = GetPlayerPed(-1)
  169. local vehicle = GetVehiclePedIsIn(lPed)
  170. return IsVehicleModel(vehicle, lssdh_hash)
  171. end
  172.  
  173. function IsHeliHighEnough(heli)
  174. return GetEntityHeightAboveGround(heli) > 1.5
  175. end
  176.  
  177. function ChangeVision()
  178. if vision_state == 0 then
  179. SetNightvision(true)
  180. vision_state = 1
  181. elseif vision_state == 1 then
  182. SetNightvision(false)
  183. SetSeethrough(true)
  184. vision_state = 2
  185. else
  186. SetSeethrough(false)
  187. vision_state = 0
  188. end
  189. end
  190.  
  191. function HideHUDThisFrame()
  192. HideHelpTextThisFrame()
  193. HideHudAndRadarThisFrame()
  194. HideHudComponentThisFrame(19) -- weapon wheel
  195. HideHudComponentThisFrame(1) -- Wanted Stars
  196. HideHudComponentThisFrame(2) -- Weapon icon
  197. HideHudComponentThisFrame(3) -- Cash
  198. HideHudComponentThisFrame(4) -- MP CASH
  199. HideHudComponentThisFrame(13) -- Cash Change
  200. HideHudComponentThisFrame(11) -- Floating Help Text
  201. HideHudComponentThisFrame(12) -- more floating help text
  202. HideHudComponentThisFrame(15) -- Subtitle Text
  203. HideHudComponentThisFrame(18) -- Game Stream
  204. end
  205.  
  206. function CheckInputRotation(cam, zoomvalue)
  207. local rightAxisX = GetDisabledControlNormal(0, 220)
  208. local rightAxisY = GetDisabledControlNormal(0, 221)
  209. local rotation = GetCamRot(cam, 2)
  210. if rightAxisX ~= 0.0 or rightAxisY ~= 0.0 then
  211. new_z = rotation.z + rightAxisX*-1.0*(speed_ud)*(zoomvalue+0.1)
  212. 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)
  213. SetCamRot(cam, new_x, 0.0, new_z, 2)
  214. end
  215. end
  216.  
  217. function HandleZoom(cam)
  218. if IsControlJustPressed(0,241) then -- Scrollup
  219. fov = math.max(fov - zoomspeed, fov_min)
  220. end
  221. if IsControlJustPressed(0,242) then
  222. fov = math.min(fov + zoomspeed, fov_max) -- ScrollDown
  223. end
  224. local current_fov = GetCamFov(cam)
  225. 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
  226. fov = current_fov
  227. end
  228. SetCamFov(cam, current_fov + (fov - current_fov)*0.05) -- Smoothing of camera zoom
  229. end
  230.  
  231. function GetVehicleInView(cam)
  232. local coords = GetCamCoord(cam)
  233. local forward_vector = RotAnglesToVec(GetCamRot(cam, 2))
  234. --DrawLine(coords, coords+(forward_vector*100.0), 255,0,0,255) -- debug line to show LOS of cam
  235. local rayhandle = CastRayPointToPoint(coords, coords+(forward_vector*200.0), 10, GetVehiclePedIsIn(GetPlayerPed(-1)), 0)
  236. local _, _, _, _, entityHit = GetRaycastResult(rayhandle)
  237. if entityHit>0 and IsEntityAVehicle(entityHit) then
  238. return entityHit
  239. else
  240. return nil
  241. end
  242. end
  243.  
  244. function RenderVehicleInfo(vehicle)
  245. local model = GetEntityModel(vehicle)
  246. local vehname = GetLabelText(GetDisplayNameFromVehicleModel(model))
  247. local licenseplate = GetVehicleNumberPlateText(vehicle)
  248. SetTextFont(0)
  249. SetTextProportional(1)
  250. SetTextScale(0.0, 0.55)
  251. SetTextColour(255, 255, 255, 255)
  252. SetTextDropshadow(0, 0, 0, 0, 255)
  253. SetTextEdge(1, 0, 0, 0, 255)
  254. SetTextDropShadow()
  255. SetTextOutline()
  256. SetTextEntry("STRING")
  257. AddTextComponentString("Model: "..vehname.."\nPlate: "..licenseplate)
  258. DrawText(0.45, 0.9)
  259. end
  260.  
  261. -- function HandleSpotlight(cam)
  262. -- if IsControlJustPressed(0, toggle_spotlight) then
  263. -- PlaySoundFrontend(-1, "SELECT", "HUD_FRONTEND_DEFAULT_SOUNDSET", false)
  264. -- spotlight_state = not spotlight_state
  265. -- end
  266. -- if spotlight_state then
  267. -- local rotation = GetCamRot(cam, 2)
  268. -- local forward_vector = RotAnglesToVec(rotation)
  269. -- local camcoords = GetCamCoord(cam)
  270. -- DrawSpotLight(camcoords, forward_vector, 255, 255, 255, 300.0, 10.0, 0.0, 2.0, 1.0)
  271. -- end
  272. -- end
  273.  
  274. function RotAnglesToVec(rot) -- input vector3
  275. local z = math.rad(rot.z)
  276. local x = math.rad(rot.x)
  277. local num = math.abs(math.cos(x))
  278. return vector3(-math.sin(z)*num, math.cos(z)*num, math.sin(x))
  279. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement