Guest User

Heliport Police

a guest
May 4th, 2017
476
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.97 KB | None | 0 0
  1. local polhelicoshop = {
  2.     opened = false,
  3.     title = "Heliport Police",
  4.     currentmenu = "mainpolice",
  5.     lastmenu = nil,
  6.     currentpos = nil,
  7.     selectedbutton = 0,
  8.     marker = { r = 0, g = 155, b = 255, a = 200, type = 1 },
  9.     menu = {
  10.         x = 0.9,
  11.         y = 0.20,
  12.         width = 0.2,
  13.         height = 0.04,
  14.         buttons = 10,
  15.         from = 1,
  16.         to = 10,
  17.         scale = 0.4,
  18.         font = 0,
  19.         ["mainpolice"] = {
  20.             title = "Los Santos Police Department",
  21.             name = "mainpolice",
  22.             buttons = {
  23.             }
  24.         },
  25.     }
  26. }
  27.  
  28.  
  29. RegisterNetEvent('PoliceHeli1')
  30. AddEventHandler('PoliceHeli1', function()
  31.    
  32.     polhelicoshop.menu["mainpolice"].buttons = {}
  33.    
  34.     if (clientrankid == 27) then --Cadet
  35.          table.insert(polhelicoshop.menu["mainpolice"].buttons, {name = "Aucun hélicoptère disponible", description = {}, model = ""})   
  36.     elseif (clientrankid == 28) then --Sergent
  37.          table.insert(polhelicoshop.menu["mainpolice"].buttons, {name = "Aucun hélicoptère disponible", description = {}, model = ""})
  38.     elseif (clientrankid == 29) then --SergentChef
  39.          table.insert(polhelicoshop.menu["mainpolice"].buttons, {name = "Helicoptère Police", description = {}, model = "polmav"})
  40.     elseif (clientrankid == 30) then --Lieutenant
  41.          table.insert(polhelicoshop.menu["mainpolice"].buttons, {name = "Helicoptère Police", description = {}, model = "polmav"})
  42.     elseif (clientrankid == 3) then --Capitaine
  43.          table.insert(polhelicoshop.menu["mainpolice"].buttons, {name = "Helicoptère Police", description = {}, model = "polmav"})
  44.     else   
  45.          table.insert(polhelicoshop.menu["mainpolice"].buttons, {name = "Helicoptère Police", description = {}, model = "polmav"})
  46.     end
  47.    
  48.    
  49. end)
  50.  
  51.  
  52. RegisterNetEvent('PoliceHeli2')
  53. AddEventHandler('PoliceHeli2', function()
  54.  
  55.     polhelicoshop.currentmenu = "mainpolice"
  56.     polhelicoshop.opened = true
  57.     polhelicoshop.selectedbutton = 0
  58.    
  59. end)
  60.        
  61.  
  62. local HeliportPolice_locations = {
  63. {polheli = {448.8877,-981.2548,43.09166}, armurerie = {449.3099,-9982779,24.44535}, outside = {448.8877,-981.2548,43.09166}},
  64. }
  65.  
  66. local HeliportPolice_blips ={}
  67. local inrangeofHeliportPolice = false
  68. local currentlocation = nil
  69. local boughtweapon = false
  70.  
  71. local function LocalPed()
  72. return GetPlayerPed(-1)
  73. end
  74.  
  75. function drawTxt(text,font,centre,x,y,scale,r,g,b,a)
  76.     SetTextFont(font)
  77.     SetTextProportional(0)
  78.     SetTextScale(scale, scale)
  79.     SetTextColour(r, g, b, a)
  80.     SetTextDropShadow(0, 0, 0, 0,255)
  81.     SetTextEdge(1, 0, 0, 0, 255)
  82.     SetTextDropShadow()
  83.     SetTextOutline()
  84.     SetTextCentre(centre)
  85.     SetTextEntry("STRING")
  86.     AddTextComponentString(text)
  87.     DrawText(x , y)
  88. end
  89.  
  90. function IsPlayerinrangeofHeliportPolice()
  91. return inrangeofHeliportPolice
  92. end
  93.  
  94. function ShowHeliPoliceBlips(bool)
  95.     if bool and #HeliportPolice_blips == 0 then
  96.         for station,pos in pairs(HeliportPolice_locations) do
  97.             local loc = pos
  98.             pos = pos.outside
  99.             table.insert(HeliportPolice_blips, {blip = blip, pos = loc})
  100.         end
  101.         Citizen.CreateThread(function()
  102.             while #HeliportPolice_blips > 0 do
  103.                 Citizen.Wait(0)
  104.                 local inrange = false
  105.                 for i,b in ipairs(HeliportPolice_blips) do
  106.                     if (clientjobID == 10) and  GetDistanceBetweenCoords(b.pos.polheli[1],b.pos.polheli[2],b.pos.polheli[3],GetEntityCoords(LocalPed()),true) > 0 then
  107.                         DrawMarker(0,b.pos.polheli[1],b.pos.polheli[2],b.pos.polheli[3],0,0,0,0,0,0,2.001,2.0001,0.5001,0,155,255,200,0,0,0,0)
  108.                         currentlocation = b
  109.                         if GetDistanceBetweenCoords(b.pos.polheli[1],b.pos.polheli[2],b.pos.polheli[3],GetEntityCoords(LocalPed()),true) < 4 then
  110.                         ShowInfoComico("Appuyez sur ~INPUT_CONTEXT~ pour choisir votre ~b~Hélicoptère.", 0)
  111.                         inrange = true
  112.                         end
  113.                     end
  114.                 end
  115.                 inrangeofHeliportPolice = inrange
  116.             end
  117.         end)
  118.     elseif bool == false and #HeliportPolice_blips > 0 then
  119.         for i,b in ipairs(HeliportPolice_blips) do
  120.             if DoesBlipExist(b.blip) then
  121.                 SetBlipAsMissionCreatorBlip(b.blip,false)
  122.                 Citizen.InvokeNative(0x86A652570E5F25DD, Citizen.PointerValueIntInitialized(b.blip))
  123.             end
  124.         end
  125.         HeliportPolice_blips = {}
  126.     end
  127. end
  128.  
  129. --Creator Weapon
  130. function OpenCreatorpolheli()      
  131.     boughtweapon = false
  132.     local ped = LocalPed()
  133.     local pos = currentlocation.pos.polheli
  134.     FreezeEntityPosition(ped,true)
  135.     local g = Citizen.InvokeNative(0xC906A7DAB05C8D2B,pos[1],pos[2],pos[3],Citizen.PointerValueFloat(),0)
  136.     -- SetEntityCoords(ped,pos[1],pos[2],g)
  137.     polhelicoshop.currentmenu = "mainpolice"
  138.     polhelicoshop.opened = true
  139.     polhelicoshop.selectedbutton = 0
  140. end
  141. function CloseCreatorpolheli()
  142.     Citizen.CreateThread(function()
  143.         local ped = LocalPed()
  144.         if not boughtweapon then
  145.             local pos = currentlocation.pos.polheli
  146.             -- SetEntityCoords(ped,pos[1],pos[2],pos[3])
  147.             FreezeEntityPosition(ped,false)
  148.         else
  149.             FreezeEntityPosition(ped,false)
  150.             SetEntityVisible(ped,true) 
  151.         end
  152.         polhelicoshop.opened = false
  153.         polhelicoshop.menu.from = 1
  154.         polhelicoshop.menu.to = 10
  155.     end)
  156. end
  157.  
  158. --Menu polheli
  159.  
  160. function drawMenuButton(button,x,y,selected)
  161.     local menu = polhelicoshop.menu
  162.     SetTextFont(menu.font)
  163.     SetTextProportional(0)
  164.     SetTextScale(menu.scale, menu.scale)
  165.     if selected then
  166.         SetTextColour(0, 0, 0, 255)
  167.     else
  168.         SetTextColour(255, 255, 255, 255)
  169.     end
  170.     SetTextCentre(0)
  171.     SetTextEntry("STRING")
  172.     AddTextComponentString(button.name)
  173.     if selected then
  174.         DrawRect(x,y,menu.width,menu.height,255,255,255,255)
  175.     else
  176.         DrawRect(x,y,menu.width,menu.height,0,0,0,150)
  177.     end
  178.     DrawText(x - menu.width/2 + 0.005, y - menu.height/2 + 0.0028) 
  179. end
  180.  
  181. function drawMenuInfo(text)
  182.     local menu = polhelicoshop.menu
  183.     SetTextFont(menu.font)
  184.     SetTextProportional(0)
  185.     SetTextScale(0.45, 0.45)
  186.     SetTextColour(255, 255, 255, 255)
  187.     SetTextCentre(0)
  188.     SetTextEntry("STRING")
  189.     AddTextComponentString(text)
  190.     DrawRect(0.675, 0.95,0.65,0.050,0,0,0,150)
  191.     DrawText(0.365, 0.934) 
  192. end
  193.  
  194. function drawMenuRight(txt,x,y,selected)
  195.     local menu = polhelicoshop.menu
  196.     SetTextFont(menu.font)
  197.     SetTextProportional(0)
  198.     SetTextScale(menu.scale, menu.scale)
  199.     SetTextRightJustify(1)
  200.     if selected then
  201.         SetTextColour(0, 0, 0, 255)
  202.     else
  203.         SetTextColour(255, 255, 255, 255)
  204.     end
  205.     SetTextCentre(0)
  206.     SetTextEntry("STRING")
  207.     AddTextComponentString(txt)
  208.     DrawText(x + menu.width/2 - 0.03, y - menu.height/2 + 0.0028)  
  209. end
  210.  
  211. function drawMenuTitle(txt,x,y)
  212. local menu = polhelicoshop.menu
  213.     SetTextFont(2)
  214.     SetTextProportional(0)
  215.     SetTextScale(0.5, 0.5)
  216.     SetTextColour(255, 255, 255, 255)
  217.     SetTextEntry("STRING")
  218.     AddTextComponentString(txt)
  219.     DrawRect(x,y,menu.width,menu.height,0,0,0,150)
  220.     DrawText(x - menu.width/2 + 0.005, y - menu.height/2 + 0.0028) 
  221. end
  222.  
  223. function tablelength(T)
  224.   local count = 0
  225.   for _ in pairs(T) do count = count + 1 end
  226.   return count
  227. end
  228. function Notify5(text)
  229. SetNotificationTextEntry('STRING')
  230. AddTextComponentString(text)
  231. DrawNotification(false, false)
  232. end
  233.  
  234. local backlock = false
  235. Citizen.CreateThread(function()
  236.     while true do
  237.         Citizen.Wait(0)
  238.         if IsControlJustPressed(1,38) and IsPlayerinrangeofHeliportPolice() then
  239.             if polhelicoshop.opened then
  240.                
  241.             else
  242.                 TriggerServerEvent('OpenHeliShopPol')
  243.             end
  244.         end
  245.         if polhelicoshop.opened then
  246.             local ped = LocalPed()
  247.             local menu = polhelicoshop.menu[polhelicoshop.currentmenu]
  248.             drawTxt(polhelicoshop.title,1,1,polhelicoshop.menu.x,polhelicoshop.menu.y,1.0, 255,255,255,255)
  249.             drawMenuTitle(menu.title, polhelicoshop.menu.x,polhelicoshop.menu.y + 0.08)
  250.             drawTxt(polhelicoshop.selectedbutton.."/"..tablelength(menu.buttons),0,0,polhelicoshop.menu.x + polhelicoshop.menu.width/2 - 0.0385,polhelicoshop.menu.y + 0.067,0.4, 255,255,255,255)
  251.             local y = polhelicoshop.menu.y + 0.12
  252.             buttoncount = tablelength(menu.buttons)
  253.             local selected = false
  254.            
  255.             for i,button in pairs(menu.buttons) do
  256.                 if i >= polhelicoshop.menu.from and i <= polhelicoshop.menu.to then
  257.                    
  258.                     if i == polhelicoshop.selectedbutton then
  259.                         selected = true
  260.                     else
  261.                         selected = false
  262.                     end
  263.                     drawMenuButton(button,polhelicoshop.menu.x,y,selected)
  264.                     y = y + 0.04
  265.                     if selected and IsControlJustPressed(1,201) then
  266.                         ButtonSelected5(button)
  267.                     end
  268.                 end
  269.             end
  270.         end
  271.         if polhelicoshop.opened then
  272.             if IsControlJustPressed(1,202) then
  273.                 Back5()
  274.             end
  275.             if IsControlJustReleased(1,202) then
  276.                 backlock = false
  277.             end
  278.             if IsControlJustPressed(1,188) then
  279.                 if polhelicoshop.selectedbutton > 1 then
  280.                     polhelicoshop.selectedbutton = polhelicoshop.selectedbutton -1
  281.                     if buttoncount > 10 and polhelicoshop.selectedbutton < polhelicoshop.menu.from then
  282.                         polhelicoshop.menu.from = polhelicoshop.menu.from -1
  283.                         polhelicoshop.menu.to = polhelicoshop.menu.to - 1
  284.                     end
  285.                 end
  286.             end
  287.             if IsControlJustPressed(1,187)then
  288.                 if polhelicoshop.selectedbutton < buttoncount then
  289.                     polhelicoshop.selectedbutton = polhelicoshop.selectedbutton +1
  290.                     if buttoncount > 10 and polhelicoshop.selectedbutton > polhelicoshop.menu.to then
  291.                         polhelicoshop.menu.to = polhelicoshop.menu.to + 1
  292.                         polhelicoshop.menu.from = polhelicoshop.menu.from + 1
  293.                     end
  294.                 end
  295.             end
  296.         end
  297.     end
  298. end)
  299.  
  300.                
  301. function ButtonSelected5(button)
  302.     local ped = GetPlayerPed(-1)
  303.     local this = polhelicoshop.currentmenu
  304.     local btn = button.name
  305.     if this == "mainpolice" then
  306.         if btn == "Aucun hélicoptère disponible" then
  307.            
  308.         else
  309.              TriggerServerEvent('CheckpolheliForGaragePolice',button.model)
  310.              CloseCreatorpolheli()
  311.              polhelicoshop.opened = false
  312.              polhelicoshop.menu.from = 1
  313.              polhelicoshop.menu.to = 10
  314.         end
  315.     else
  316.    
  317.     end
  318. end
  319.  
  320.  
  321. RegisterNetEvent('FinishpolheliCheckForGaragePolice')
  322. AddEventHandler('FinishpolheliCheckForGaragePolice', function()
  323.     boughtweapon = true
  324.     CloseCreatorpolheli()
  325.     polhelicoshop.opened = false
  326.     polhelicoshop.menu.from = 1
  327.     polhelicoshop.menu.to = 10
  328. end)
  329.  
  330. function OpenMenu5(menu)
  331.     polhelicoshop.lastmenu = polhelicoshop.currentmenu
  332.     if menu == "mainpolice" then
  333.         polhelicoshop.lastmenu = "main"
  334.     elseif menu == "mainintervention"  then
  335.         polhelicoshop.lastmenu = "main"
  336.     elseif menu == 'race_create_objects' then
  337.         polhelicoshop.lastmenu = "main"
  338.     elseif menu == "race_create_objects_spawn" then
  339.         polhelicoshop.lastmenu = "race_create_objects"
  340.     end
  341.     polhelicoshop.menu.from = 1
  342.     polhelicoshop.menu.to = 10
  343.     polhelicoshop.selectedbutton = 0
  344.     polhelicoshop.currentmenu = menu   
  345. end
  346.  
  347. function Back5()
  348.     if backlock then
  349.         return
  350.     end
  351.     backlock = true
  352.     if polhelicoshop.currentmenu == "mainpolice" then
  353.         CloseCreatorpolheli()
  354.     elseif polhelicoshop.currentmenu == "police1" or polhelicoshop.currentmenu == "police2" or polhelicoshop.currentmenu == "police3" or polhelicoshop.currentmenu == "police4" or polhelicoshop.currentmenu == "police5" or polhelicoshop.currentmenu == "police6" then
  355.         OpenMenu5(polhelicoshop.lastmenu)
  356.     else
  357.         OpenMenu5(polhelicoshop.lastmenu)
  358.     end
  359. end
  360.  
  361. function stringstarts5(String,Start)
  362.    return string.sub(String,1,string.len(Start))==Start
  363. end
  364.  
  365. local firstspawn = 0
  366. AddEventHandler('playerSpawned', function(spawn)
  367. if firstspawn == 0 then
  368.     ShowHeliPoliceBlips(true)
  369.     firstspawn = 1
  370. end
  371. end)
Add Comment
Please, Sign In to add comment