Advertisement
davedumas0

fiveM-tv_stuff.lua

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