Facebook
From client.lua, 5 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 547
  1. -- Local
  2.  
  3. local Keys = {
  4.  
  5.         ["ESC"] = 322, ["F1"] = 288, ["F2"] = 289, ["F3"] = 170, ["F5"] = 166, ["F6"] = 167, ["F7"] = 168, ["F8"] = 169, ["F9"] = 56, ["F10"] = 57,
  6.  
  7.         ["~"] = 243, ["1"] = 157, ["2"] = 158, ["3"] = 160, ["4"] = 164, ["5"] = 165, ["6"] = 159, ["7"] = 161, ["8"] = 162, ["9"] = 163, ["-"] = 84, ["="] = 83, ["BACKSPACE"] = 177,
  8.  
  9.         ["TAB"] = 37, ["Q"] = 44, ["W"] = 32, ["E"] = 38, ["R"] = 45, ["T"] = 245, ["Y"] = 246, ["U"] = 303, ["P"] = 199, ["["] = 39, ["]"] = 40, ["ENTER"] = 18,
  10.  
  11.         ["CAPS"] = 137, ["A"] = 34, ["S"] = 8, ["D"] = 9, ["F"] = 23, ["G"] = 47, ["H"] = 74, ["K"] = 311, ["L"] = 182,
  12.  
  13.         ["LEFTSHIFT"] = 21, ["Z"] = 20, ["X"] = 73, ["C"] = 26, ["V"] = 0, ["B"] = 29, ["N"] = 249, ["M"] = 244, [","] = 82, ["."] = 81,
  14.  
  15.         ["LEFTCTRL"] = 36, ["LEFTALT"] = 19, ["SPACE"] = 22, ["RIGHTCTRL"] = 70,
  16.  
  17.         ["HOME"] = 213, ["PAGEUP"] = 10, ["PAGEDOWN"] = 11, ["DELETE"] = 178,
  18.  
  19.         ["LEFT"] = 174, ["RIGHT"] = 175, ["TOP"] = 27, ["DOWN"] = 173,
  20.  
  21.         ["NENTER"] = 201, ["N4"] = 108, ["N5"] = 60, ["N6"] = 107, ["N+"] = 96, ["N-"] = 97, ["N7"] = 117, ["N8"] = 61, ["N9"] = 118
  22.  
  23. }
  24.  
  25.  
  26.  
  27. local CurrentAction = nil
  28.  
  29. local GUI                       = {}
  30.  
  31. GUI.Time                        = 0
  32.  
  33. local HasAlreadyEnteredMarker   = false
  34.  
  35. local LastZone                  = nil
  36.  
  37. local CurrentActionMsg          = ''
  38.  
  39. local CurrentActionData         = {}
  40.  
  41.  
  42.  
  43. local this_Garage = {}
  44.  
  45. -- Fin Local
  46.  
  47.  
  48.  
  49. -- Init ESX
  50.  
  51. ESX = nil
  52.  
  53.  
  54.  
  55. Citizen.CreateThread(function()
  56.  
  57.         while ESX == nil do
  58.  
  59.                 TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
  60.  
  61.                 Citizen.Wait(0)
  62.  
  63.         end
  64.  
  65. end)
  66.  
  67. -- Fin init ESX
  68.  
  69.  
  70.  
  71. --- Gestion Des blips
  72.  
  73. RegisterNetEvent('esx:playerLoaded')
  74.  
  75. AddEventHandler('esx:playerLoaded', function(xPlayer)
  76.  
  77.     --PlayerData = xPlayer
  78.  
  79.     --TriggerServerEvent('esx_jobs:giveBackCautionInCaseOfDrop')
  80.  
  81.     refreshBlips()
  82.  
  83. end)
  84.  
  85.  
  86.  
  87. function refreshBlips()
  88.  
  89.         local zones = {}
  90.  
  91.         local blipInfo = {}    
  92.  
  93.  
  94.  
  95.         for zoneKey,zoneValues in pairs(Config.Garages)do
  96.  
  97.  
  98.  
  99.                 local blip = AddBlipForCoord(zoneValues.Pos.x, zoneValues.Pos.y, zoneValues.Pos.z)
  100.  
  101.                 SetBlipSprite (blip, Config.BlipInfos.Sprite)
  102.  
  103.                 SetBlipDisplay(blip, 4)
  104.  
  105.                 SetBlipScale  (blip, 1.2)
  106.  
  107.                 SetBlipColour (blip, Config.BlipInfos.Color)
  108.  
  109.                 SetBlipAsShortRange(blip, true)
  110.  
  111.                 BeginTextCommandSetBlipName("STRING")
  112.  
  113.                 AddTextComponentString(zoneKey)
  114.  
  115.                 EndTextCommandSetBlipName(blip)
  116.  
  117.         end
  118.  
  119. end
  120.  
  121. -- Fin Gestion des Blips
  122.  
  123.  
  124.  
  125. --Fonction Menu
  126.  
  127.  
  128.  
  129. function OpenMenuGarage()
  130.  
  131.        
  132.  
  133.        
  134.  
  135.         ESX.UI.Menu.CloseAll()
  136.  
  137.  
  138.  
  139.         local elements = {
  140.  
  141.                 {label = "Lista pojazdow", value = 'list_vehicles'},
  142.  
  143.                 {label = "Zwroc pojazd", value = 'stock_vehicle'},
  144.  
  145.                 {label = "Zniszczone pojazdy ("..Config.Price.."$)", value = 'return_vehicle'},
  146.  
  147.         }
  148.  
  149.  
  150.  
  151.  
  152.  
  153.         ESX.UI.Menu.Open(
  154.  
  155.                 'default', GetCurrentResourceName(), 'garage_menu',
  156.  
  157.                 {
  158.  
  159.                         title    = 'Garage',
  160.  
  161.                         align    = 'top-left',
  162.  
  163.                         elements = elements,
  164.  
  165.                 },
  166.  
  167.                 function(data, menu)
  168.  
  169.  
  170.  
  171.                         menu.close()
  172.  
  173.                         if(data.current.value == 'list_vehicles') then
  174.  
  175.                                 ListVehiclesMenu()
  176.  
  177.                         end
  178.  
  179.                         if(data.current.value == 'stock_vehicle') then
  180.  
  181.                                 StockVehicleMenu()
  182.  
  183.                         end
  184.  
  185.                         if(data.current.value == 'return_vehicle') then
  186.  
  187.                                 ReturnVehicleMenu()
  188.  
  189.                         end
  190.  
  191.  
  192.  
  193.                         local playerPed = GetPlayerPed(-1)
  194.  
  195.                         SpawnVehicle(data.current.value)
  196.  
  197.                         --local coords    = societyConfig.Zones.VehicleSpawnPoint.Pos
  198.  
  199.  
  200.  
  201.                 end,
  202.  
  203.                 function(data, menu)
  204.  
  205.                         menu.close()
  206.  
  207.                         --CurrentAction = 'open_garage_action'
  208.  
  209.                 end
  210.  
  211.         )      
  212.  
  213. end
  214.  
  215. -- Afficher les listes des vehicules
  216.  
  217. function ListVehiclesMenu()
  218.  
  219.         local elements = {}
  220.  
  221.  
  222.  
  223.         ESX.TriggerServerCallback('eden_garage:getVehicles', function(vehicles)
  224.  
  225.  
  226.  
  227.                 for _,v in pairs(vehicles) do
  228.  
  229.  
  230.  
  231.                         local hashVehicule = v.vehicle.model
  232.  
  233.                 local vehicleName = GetDisplayNameFromVehicleModel(hashVehicule)
  234.  
  235.                 local labelvehicle
  236.  
  237.  
  238.  
  239.                 if(v.state)then
  240.  
  241.                 labelvehicle = vehicleName..': W garazu'
  242.  
  243.                
  244.  
  245.                 else
  246.  
  247.                 labelvehicle = vehicleName..': Brak w garazu'
  248.  
  249.                 end    
  250.  
  251.                         table.insert(elements, {label =labelvehicle , value = v})
  252.  
  253.                        
  254.  
  255.                 end
  256.  
  257.  
  258.  
  259.                 ESX.UI.Menu.Open(
  260.  
  261.                 'default', GetCurrentResourceName(), 'spawn_vehicle',
  262.  
  263.                 {
  264.  
  265.                         title    = 'Garage',
  266.  
  267.                         align    = 'top-left',
  268.  
  269.                         elements = elements,
  270.  
  271.                 },
  272.  
  273.                 function(data, menu)
  274.  
  275.                         if(data.current.value.state)then
  276.  
  277.                                 menu.close()
  278.  
  279.                                 SpawnVehicle(data.current.value.vehicle)
  280.  
  281.                         else
  282.  
  283.                                 TriggerEvent('esx:showNotification', 'Pojazd zostal wyciagniety')
  284.  
  285.                         end
  286.  
  287.                 end,
  288.  
  289.                 function(data, menu)
  290.  
  291.                         menu.close()
  292.  
  293.                         --CurrentAction = 'open_garage_action'
  294.  
  295.                 end
  296.  
  297.         )      
  298.  
  299.         end)
  300.  
  301. end
  302.  
  303. -- Fin Afficher les listes des vehicules
  304.  
  305.  
  306.  
  307. -- Fonction qui permet de rentrer un vehicule
  308.  
  309. function StockVehicleMenu()
  310.  
  311.         local playerPed  = GetPlayerPed(-1)
  312.  
  313.         if IsAnyVehicleNearPoint(this_Garage.DeletePoint.Pos.x,  this_Garage.DeletePoint.Pos.y,  this_Garage.DeletePoint.Pos.z,  3.5) then
  314.  
  315.  
  316.  
  317.                 local vehicle       = GetClosestVehicle(this_Garage.DeletePoint.Pos.x, this_Garage.DeletePoint.Pos.y, this_Garage.DeletePoint.Pos.z, this_Garage.DeletePoint.Size.x, 0, 70)
  318.  
  319.                 local vehicleProps  = ESX.Game.GetVehicleProperties(vehicle)
  320.  
  321.  
  322.  
  323.                 ESX.TriggerServerCallback('eden_garage:stockv',function(valid)
  324.  
  325.  
  326.  
  327.                         if(valid) then
  328.  
  329.                                 TriggerServerEvent('eden_garage:debug', vehicle)
  330.  
  331.                                 DeleteVehicle(vehicle)
  332.  
  333.                                 TriggerServerEvent('eden_garage:modifystate', vehicleProps, true)
  334.  
  335.                                 TriggerEvent('esx:showNotification', 'Pojazd zostal przeniesiony do garazu')
  336.  
  337.                         else
  338.  
  339.                                 TriggerEvent('esx:showNotification', 'Nie posiadasz tego pojazdu')
  340.  
  341.                         end
  342.  
  343.                 end,vehicleProps)
  344.  
  345.         else
  346.  
  347.                 TriggerEvent('esx:showNotification', 'Brak pojazdu w punkcie')
  348.  
  349.         end
  350.  
  351.  
  352.  
  353. end
  354.  
  355. -- Fin fonction qui permet de rentrer un vehicule
  356.  
  357. --Fin fonction Menu
  358.  
  359.  
  360.  
  361.  
  362.  
  363. --Fonction pour spawn vehicule
  364.  
  365. function SpawnVehicle(vehicle)
  366.  
  367.  
  368.  
  369.         ESX.Game.SpawnVehicle(vehicle.model, {
  370.  
  371.                 x = this_Garage.SpawnPoint.Pos.x ,
  372.  
  373.                 y = this_Garage.SpawnPoint.Pos.y,
  374.  
  375.                 z = this_Garage.SpawnPoint.Pos.z + 1                                                                                   
  376.  
  377.                 },120, function(callback_vehicle)
  378.  
  379.                 ESX.Game.SetVehicleProperties(callback_vehicle, vehicle)
  380.  
  381.                 end)
  382.  
  383.         TriggerServerEvent('eden_garage:modifystate', vehicle, false)
  384.  
  385.  
  386.  
  387. end
  388.  
  389. --Fin fonction pour spawn vehicule
  390.  
  391.  
  392.  
  393. --Action das les markers
  394.  
  395. AddEventHandler('eden_garage:hasEnteredMarker', function(zone)
  396.  
  397.         if zone == 'garage' then
  398.  
  399.                 CurrentAction     = 'garage_action_menu'
  400.  
  401.                 CurrentActionMsg  = "Wcisnij ~INPUT_PICKUP~ zeby otworzyc garaz"
  402.  
  403.                 CurrentActionData = {}
  404.  
  405.         end
  406.  
  407. end)
  408.  
  409.  
  410.  
  411. AddEventHandler('eden_garage:hasExitedMarker', function(zone)
  412.  
  413.         ESX.UI.Menu.CloseAll()
  414.  
  415.         CurrentAction = nil
  416.  
  417. end)
  418.  
  419. --Fin Action das les markers
  420.  
  421.  
  422.  
  423. function ReturnVehicleMenu()
  424.  
  425.  
  426.  
  427.         ESX.TriggerServerCallback('eden_garage:getOutVehicles', function(vehicles)
  428.  
  429.  
  430.  
  431.                 local elements = {}
  432.  
  433.  
  434.  
  435.                 for _,v in pairs(vehicles) do
  436.  
  437.  
  438.  
  439.                         local hashVehicule = v.model
  440.  
  441.                 local vehicleName = GetDisplayNameFromVehicleModel(hashVehicule)
  442.  
  443.                 local labelvehicle
  444.  
  445.  
  446.  
  447.                 labelvehicle = vehicleName..': Brak pojazdu w garazu'
  448.  
  449.        
  450.  
  451.                         table.insert(elements, {label =labelvehicle , value = v})
  452.  
  453.                        
  454.  
  455.                 end
  456.  
  457.  
  458.  
  459.                 ESX.UI.Menu.Open(
  460.  
  461.                 'default', GetCurrentResourceName(), 'return_vehicle',
  462.  
  463.                 {
  464.  
  465.                         title    = 'Garage',
  466.  
  467.                         align    = 'top-left',
  468.  
  469.                         elements = elements,
  470.  
  471.                 },
  472.  
  473.                 function(data, menu)
  474.  
  475.  
  476.  
  477.                         ESX.TriggerServerCallback('eden_garage:checkMoney', function(hasEnoughMoney)
  478.  
  479.                                 if hasEnoughMoney then
  480.  
  481.                                                        
  482.  
  483.                                         TriggerServerEvent('eden_garage:pay')
  484.  
  485.                                         SpawnVehicle(data.current.value)
  486.  
  487.                                 else
  488.  
  489.                                         ESX.ShowNotification('Nie masz wystarczajaco pieniedzy')                                               
  490.  
  491.                                 end
  492.  
  493.                         end)
  494.  
  495.                 end,
  496.  
  497.                 function(data, menu)
  498.  
  499.                         menu.close()
  500.  
  501.                         --CurrentAction = 'open_garage_action'
  502.  
  503.                 end
  504.  
  505.                 )      
  506.  
  507.         end)
  508.  
  509. end
  510.  
  511.  
  512.  
  513. -- Affichage markers
  514.  
  515. Citizen.CreateThread(function()
  516.  
  517.         while true do
  518.  
  519.                 Wait(0)        
  520.  
  521.                 local coords = GetEntityCoords(GetPlayerPed(-1))                       
  522.  
  523.  
  524.  
  525.                 for k,v in pairs(Config.Garages) do
  526.  
  527.                         if(GetDistanceBetweenCoords(coords, v.Pos.x, v.Pos.y, v.Pos.z, true) < Config.DrawDistance) then               
  528.  
  529.                                 DrawMarker(v.Marker, v.Pos.x, v.Pos.y, v.Pos.z, 0.0, 0.0, 0.0, 0, 0.0, 0.0, v.Size.x, v.Size.y, v.Size.z, v.Color.r, v.Color.g, v.Color.b, 100, false, true, 2, false, false, false, false)
  530.  
  531.                                 DrawMarker(v.SpawnPoint.Marker, v.SpawnPoint.Pos.x, v.SpawnPoint.Pos.y, v.SpawnPoint.Pos.z, 0.0, 0.0, 0.0, 0, 0.0, 0.0, v.SpawnPoint.Size.x, v.SpawnPoint.Size.y, v.SpawnPoint.Size.z, v.SpawnPoint.Color.r, v.SpawnPoint.Color.g, v.SpawnPoint.Color.b, 100, false, true, 2, false, false, false, false)      
  532.  
  533.                                 DrawMarker(v.DeletePoint.Marker, v.DeletePoint.Pos.x, v.DeletePoint.Pos.y, v.DeletePoint.Pos.z, 0.0, 0.0, 0.0, 0, 0.0, 0.0, v.DeletePoint.Size.x, v.DeletePoint.Size.y, v.DeletePoint.Size.z, v.DeletePoint.Color.r, v.DeletePoint.Color.g, v.DeletePoint.Color.b, 100, false, true, 2, false, false, false, false)    
  534.  
  535.  
  536.  
  537.                         end            
  538.  
  539.                 end    
  540.  
  541.         end
  542.  
  543. end)
  544.  
  545. -- Fin affichage markers
  546.  
  547.  
  548.  
  549. -- Activer le menu quand player dedans
  550.  
  551. Citizen.CreateThread(function()
  552.  
  553.         local currentZone = 'garage'
  554.  
  555.         while true do
  556.  
  557.  
  558.  
  559.                 Wait(0)
  560.  
  561.  
  562.  
  563.                 local coords      = GetEntityCoords(GetPlayerPed(-1))
  564.  
  565.                 local isInMarker  = false
  566.  
  567.  
  568.  
  569.                 for _,v in pairs(Config.Garages) do
  570.  
  571.                         if(GetDistanceBetweenCoords(coords, v.Pos.x, v.Pos.y, v.Pos.z, true) < v.Size.x) then
  572.  
  573.                                 isInMarker  = true
  574.  
  575.                                 this_Garage = v
  576.  
  577.                         end
  578.  
  579.                 end
  580.  
  581.  
  582.  
  583.                 if isInMarker and not hasAlreadyEnteredMarker then
  584.  
  585.                         hasAlreadyEnteredMarker = true
  586.  
  587.                         LastZone                = currentZone
  588.  
  589.                         TriggerEvent('eden_garage:hasEnteredMarker', currentZone)
  590.  
  591.                 end
  592.  
  593.  
  594.  
  595.                 if not isInMarker and hasAlreadyEnteredMarker then
  596.  
  597.                         hasAlreadyEnteredMarker = false
  598.  
  599.                         TriggerEvent('eden_garage:hasExitedMarker', LastZone)
  600.  
  601.                 end
  602.  
  603.  
  604.  
  605.         end
  606.  
  607. end)
  608.  
  609.  
  610.  
  611.  
  612.  
  613. -- Fin activer le menu quand player dedans
  614.  
  615.  
  616.  
  617. -- Controle touche
  618.  
  619. Citizen.CreateThread(function()
  620.  
  621.         while true do
  622.  
  623.  
  624.  
  625.                 Citizen.Wait(0)
  626.  
  627.  
  628.  
  629.                 if CurrentAction ~= nil then
  630.  
  631.  
  632.  
  633.                         SetTextComponentFormat('STRING')
  634.  
  635.                         AddTextComponentString(CurrentActionMsg)
  636.  
  637.                         DisplayHelpTextFromStringLabel(0, 0, 1, -1)
  638.  
  639.  
  640.  
  641.                         if IsControlPressed(0,  Keys['E']) and (GetGameTimer() - GUI.Time) > 150 then
  642.  
  643.  
  644.  
  645.                                 if CurrentAction == 'garage_action_menu' then
  646.  
  647.                                         OpenMenuGarage()
  648.  
  649.                                 end
  650.  
  651.  
  652.  
  653.                                 CurrentAction = nil
  654.  
  655.                                 GUI.Time      = GetGameTimer()
  656.  
  657.  
  658.  
  659.                         end
  660.  
  661.                 end
  662.  
  663.         end
  664.  
  665. end)
  666.  
  667. -- Fin controle touche