davedumas0

fiveM-movies.lua

Aug 24th, 2017
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.29 KB | None | 0 0
  1. ----------------------------------------------------------
  2. ---------------------load movie settings------------------
  3. ----------------------------------------------------------
  4. -- Configure the opening hours
  5. local openingHour = 0
  6. local closingHour = 22
  7.  
  8. -- Configure the coordinates for all the cinemas
  9. local cinemaLocations = {
  10.   { ['name'] = "Downtown", ['x'] = 300.788, ['y'] = 200.752, ['z'] = 104.385},
  11.   { ['name'] = "Morningwood", ['x'] = -1423.954, ['y'] = -213.62, ['z'] = 46.5},
  12.   { ['name'] = "Vinewood",  ['x'] = 302.907, ['y'] = 135.939, ['z'] = 160.946}
  13. }
  14. --adds blips for movie theater
  15. local blipsLoaded = false
  16. local MovieState = false
  17. function LoadBlips()
  18.   for k,v in ipairs(cinemaLocations) do
  19.     local blip = AddBlipForCoord(v.x, v.y, v.z)
  20.     SetBlipSprite(blip, 135)
  21.     SetBlipScale(blip, 1.2)
  22.     SetBlipColour(blip, 25)
  23.     SetBlipAsShortRange(blip, false)
  24.     BeginTextCommandSetBlipName("STRING")
  25.     AddTextComponentSubstringPlayerName("Movie Theater")
  26.     EndTextCommandSetBlipName(blip)
  27. --loads the theater interior
  28.     RequestIpl("v_cinema")
  29.     blipsLoaded = true
  30.   end
  31. end
  32.  
  33.  
  34. --gets a random movie
  35. function randomVideo()
  36.  n = GetRandomIntInRange(0, 3)
  37.    if n == 0 then
  38.     return "PL_CINEMA_CARTOON"
  39.    elseif n == 1 then
  40.     return "PL_STD_CNT"
  41.    elseif n == 2 then
  42.     return "PL_STD_WZL"
  43.    elseif n == 3 then
  44.     return "PL_CINEMA_MULTIPLAYER_NO_MELTDOWN"
  45.    elseif n == 4 then
  46.     return "PL_CINEMA_ACTION"  
  47.    end
  48. end
  49.          
  50. ------------------------------------------------------------
  51. ---------------------set up movie---------------------------
  52. ------------------------------------------------------------
  53. function SetupMovie()
  54.   cinema = GetInteriorAtCoords(320.217, 263.81, 82.974)
  55.   LoadInterior(cinema)
  56. --this gets the hash key of the cinema screen
  57.   cin_screen = GetHashKey("v_ilev_cin_screen")
  58.    if not DoesEntityExist(tv) then
  59.      tv = CreateObjectNoOffset(cin_screen, 320.1257, 248.6608, 86.56934, 1, true, false)
  60.      SetEntityHeading(tv, 179.99998474121)
  61.     else
  62.      tv = GetClosestObjectOfType(319.884, 262.103, 82.917, 20.475, cin_screen, 0, 0, 0)
  63.    end
  64. --this checks if the rendertarget is registered and  registers rendertarget
  65.   if not IsNamedRendertargetRegistered("cinscreen") then
  66.     RegisterNamedRendertarget("cinscreen", 0)
  67.   end
  68. --this checks if the screen is linked to rendertarget and links screen to rendertarget
  69.     if not IsNamedRendertargetLinked(cin_screen) then
  70.         LinkNamedRendertarget(cin_screen)
  71.     end
  72.   rendertargetid = GetNamedRendertargetRenderId("cinscreen")
  73. --this checks if the rendertarget is linked AND registered
  74.   if IsNamedRendertargetLinked(cin_screen) and IsNamedRendertargetRegistered("cinscreen") then
  75. --this sets the rendertargets channel and video
  76.     Citizen.InvokeNative(0x9DD5A62390C3B735, 2, randomVideo(), 0)
  77. --this sets the rendertarget   
  78.     SetTextRenderId(rendertargetid)
  79. --duh sets the volume
  80.     SetTvVolume(100)   
  81. --duh sets the cannel
  82.     SetTvChannel(2)
  83. --duh sets subtitles
  84.     EnableMovieSubtitles(1)
  85. --these are for the rendertarget 2d settings and stuff 
  86.     Citizen.InvokeNative(0x67A346B3CDB15CA5, 100.0)
  87.     Citizen.InvokeNative(0x61BB1D9B3A95D802, 4)
  88.     Citizen.InvokeNative(0xC6372ECD45D73BCD, 1)
  89.   else
  90. --this puts the rendertarget back to regular use(playing)
  91.    SetTextRenderId(GetDefaultScriptRendertargetRenderId())
  92.   end
  93.   if MovieState == false then
  94.     MovieState = true
  95.     CreateMovieThread()
  96.   end
  97. end
  98. function helpDisplay(text, state)
  99.   SetTextComponentFormat("STRING")
  100.   AddTextComponentString(text)
  101.   DisplayHelpTextFromStringLabel(0, state, 0, -1)
  102. end
  103. --this FUNCTION deletes the movie screen sets the channel to basicly nothing
  104. function DeconstructMovie()
  105.  local obj = GetClosestObjectOfType(319.884, 262.103, 82.917, 20.475, cin_screen, 0, 0, 0)
  106.   cin_screen = GetHashKey("v_ilev_cin_screen")
  107.   SetTvChannel(-1)  
  108.   ReleaseNamedRendertarget(GetHashKey("cinscreen"))
  109.   SetTextRenderId(GetDefaultScriptRendertargetRenderId())
  110.   SetEntityAsMissionEntity(obj,true,false)
  111.   DeleteObject(obj)
  112. end
  113. --this FUNCTION is what draws the tv channel(needs to be in a loop)
  114. function StartMovie()
  115.     DrawTvChannel(0.5, 0.5, 1.0, 1.0, 0.0, 255, 255, 255, 255)
  116. end
  117. --this starts the movie
  118. function CreateMovieThread()
  119.   Citizen.CreateThread(function()
  120.     SetTextRenderId(GetNamedRendertargetRenderId("cinscreen"))
  121.     Citizen.InvokeNative(0x9DD5A62390C3B735, 2, randomVideo(), 0)      
  122.     SetTvChannel(2)
  123.     Citizen.InvokeNative(0x67A346B3CDB15CA5, 100.0)
  124.     Citizen.InvokeNative(0x61BB1D9B3A95D802, 4)
  125.     Citizen.InvokeNative(0xC6372ECD45D73BCD, 1)    
  126.     while(true) do
  127.       Citizen.Wait(0)
  128.       StartMovie()
  129.     end
  130.   end)
  131. end
  132. --this is the enter theater stuff
  133. function IsPlayerInArea()
  134.   playerPed = GetPlayerPed(-1)
  135.   playerCoords = GetEntityCoords(playerPed, true)
  136.   hour = GetClockHours()
  137.   for k,v in ipairs(cinemaLocations) do
  138. -- Check if the player is near the cinema
  139.         if GetDistanceBetweenCoords(playerCoords, v.x, v.y, v.z) < 4.8 then
  140. -- Check if the cinema is open or closed.
  141.           if hour < openingHour or hour > closingHour then
  142.             helpDisplay("The cinema is ~r~closed ~w~come back between 1am and 22pm.", 0)
  143.           else
  144.             helpDisplay("Press ~INPUT_CONTEXT~ to watch a movie", 0)
  145. -- Check if the player is near the cinema and pressed "INPUT_CONTEXT"
  146.             if IsControlPressed(0, 38) then
  147.               DoScreenFadeOut(1000)
  148.               SetupMovie()
  149. -- Teleport the Player inside the cinema
  150.               Citizen.Wait(500)
  151.               SetEntityCoords(playerPed, 320.217, 263.81, 81.974, true, true, true, true)
  152.               DoScreenFadeIn(800)
  153.               Citizen.Wait(30)
  154.               SetEntityHeading(playerPed, 180.475)
  155.               TaskLookAtCoord(GetPlayerPed(-1), 319.259, 251.827, 85.648, -1, 2048, 3)
  156.               FreezeEntityPosition(GetPlayerPed(-1), 1)
  157.               Notify("press ~r~ESC ~w~key to exit")          
  158.             end
  159.           end
  160.         end
  161.       end
  162. end                
  163. Citizen.CreateThread(function()
  164.   while true do
  165.     Citizen.Wait(0)
  166.     IsPlayerInArea()
  167.   end
  168. end)
  169. --if the player is not inside theater delete screen
  170. Citizen.CreateThread(function()
  171.  if GetRoomKeyFromEntity(PlayerPedId()) ~= -1337806789 and DoesEntityExist(GetClosestObjectOfType(319.884, 262.103, 82.917, 20.475, cin_screen, 0, 0, 0)) then
  172.  
  173.     DeconstructMovie()
  174.  end
  175. -- Create the blips for the cinema's
  176.   LoadBlips()      
  177. end)
  178. Citizen.CreateThread(function()
  179.   while true do
  180.     Citizen.Wait(0)
  181.     playerPed = GetPlayerPed(-1)  
  182. --if player hits "esc" key while in theater they exit
  183.       if IsControlPressed(0, 322) and GetRoomKeyFromEntity(PlayerPedId()) == -1337806789 then
  184.         DoScreenFadeOut(1000)
  185.         SetEntityCoords(playerPed, 297.891, 193.296, 104.344, 161.925)
  186.         Citizen.Wait(30)       
  187.         DoScreenFadeIn(800)
  188.         FreezeEntityPosition(GetPlayerPed(-1), 0)
  189.         SetFollowPedCamViewMode(fistPerson)
  190.         DeconstructMovie()
  191.         --ClearRoomForEntity(playerPed)
  192.         MovieState = false
  193.       end
  194.     if GetRoomKeyFromEntity(PlayerPedId()) == -1337806789 then
  195.      --SetPlayerInvisibleLocally(PlayerId(),  true)
  196.      SetEntityVisible(PlayerPedId(-1), false)
  197.      SetPlayerInvincible(PlayerId(), true)
  198.      SetCurrentPedWeapon(PlayerPedId(), GetHashKey("weapon_unarmed"), 1)
  199.      SetFollowPedCamViewMode(4)
  200.     else
  201.      SetEntityVisible(PlayerPedId(-1), true)
  202.     end
  203.     end
  204. end)
Add Comment
Please, Sign In to add comment