Advertisement
Guest User

Untitled

a guest
Dec 5th, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.33 KB | None | 0 0
  1. -- Local
  2. local Keys = {
  3. ["ESC"] = 322, ["F1"] = 288, ["F2"] = 289, ["F3"] = 170, ["F5"] = 166, ["F6"] = 167, ["F7"] = 168, ["F8"] = 169, ["F9"] = 56, ["F10"] = 57,
  4. ["~"] = 243, ["1"] = 157, ["2"] = 158, ["3"] = 160, ["4"] = 164, ["5"] = 165, ["6"] = 159, ["7"] = 161, ["8"] = 162, ["9"] = 163, ["-"] = 84, ["="] = 83, ["BACKSPACE"] = 177,
  5. ["TAB"] = 37, ["Q"] = 44, ["W"] = 32, ["E"] = 38, ["R"] = 45, ["T"] = 245, ["Y"] = 246, ["U"] = 303, ["P"] = 199, ["["] = 39, ["]"] = 40, ["ENTER"] = 18,
  6. ["CAPS"] = 137, ["A"] = 34, ["S"] = 8, ["D"] = 9, ["F"] = 23, ["G"] = 47, ["H"] = 74, ["K"] = 311, ["L"] = 182,
  7. ["LEFTSHIFT"] = 21, ["Z"] = 20, ["X"] = 73, ["C"] = 26, ["V"] = 0, ["B"] = 29, ["N"] = 249, ["M"] = 244, [","] = 82, ["."] = 81,
  8. ["LEFTCTRL"] = 36, ["LEFTALT"] = 19, ["SPACE"] = 22, ["RIGHTCTRL"] = 70,
  9. ["HOME"] = 213, ["PAGEUP"] = 10, ["PAGEDOWN"] = 11, ["DELETE"] = 178,
  10. ["LEFT"] = 174, ["RIGHT"] = 175, ["TOP"] = 27, ["DOWN"] = 173,
  11. ["NENTER"] = 201, ["N4"] = 108, ["N5"] = 60, ["N6"] = 107, ["N+"] = 96, ["N-"] = 97, ["N7"] = 117, ["N8"] = 61, ["N9"] = 118
  12. }
  13.  
  14. local CurrentAction = nil
  15. local GUI = {}
  16. GUI.Time = 0
  17. local HasAlreadyEnteredMarker = false
  18. local LastZone = nil
  19. local CurrentActionMsg = ''
  20. local CurrentActionData = {}
  21. local times = 0
  22. local userProperties = {}
  23. local this_Garage = {}
  24.  
  25. -- End Local
  26. -- Initialise ESX
  27.  
  28. ESX = nil
  29.  
  30. Citizen.CreateThread(function()
  31. while ESX == nil do
  32. TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
  33. Citizen.Wait(0)
  34. end
  35. end)
  36.  
  37. -- End ESX Initialisation
  38. --- Generate map blips
  39.  
  40. RegisterNetEvent('esx:playerLoaded')
  41. AddEventHandler('esx:playerLoaded', function(xPlayer)
  42. --PlayerData = xPlayer
  43. --TriggerServerEvent('esx_jobs:giveBackCautionInCaseOfDrop')
  44. if Config.PropertyGarages then
  45. ESX.TriggerServerCallback('eden_garage:getOwnedProperties', function(properties)
  46. userProperties = properties
  47. PrivateGarageBlips()
  48. end)
  49. end
  50. refreshBlips()
  51. end)
  52.  
  53. function refreshBlips()
  54. local zones = {}
  55. local blipInfo = {}
  56.  
  57. for zoneKey,zoneValues in pairs(Config.Garages)do
  58.  
  59. if not zoneValues.Private then
  60. local blip = AddBlipForCoord(zoneValues.Pos.x, zoneValues.Pos.y, zoneValues.Pos.z)
  61. SetBlipSprite (blip, Config.BlipInfos.Sprite)
  62. SetBlipDisplay(blip, 4)
  63. SetBlipScale (blip, 1.0)
  64. SetBlipColour (blip, Config.BlipInfos.Color)
  65. SetBlipAsShortRange(blip, true)
  66. BeginTextCommandSetBlipName("STRING")
  67. AddTextComponentString(_U('public_garage'))
  68. EndTextCommandSetBlipName(blip)
  69. end
  70.  
  71. if zoneValues.MunicipalPoundPoint then
  72. local blip = AddBlipForCoord(zoneValues.MunicipalPoundPoint.Pos.x, zoneValues.MunicipalPoundPoint.Pos.y, zoneValues.MunicipalPoundPoint.Pos.z)
  73. SetBlipSprite (blip, Config.BlipPound.Sprite)
  74. SetBlipDisplay(blip, 4)
  75. SetBlipScale (blip, 1.0)
  76. SetBlipColour (blip, Config.BlipPound.Color)
  77. SetBlipAsShortRange(blip, true)
  78. BeginTextCommandSetBlipName("STRING")
  79. AddTextComponentString(_U("municipal_pound"))
  80. EndTextCommandSetBlipName(blip)
  81. end
  82. end
  83. end
  84.  
  85. -- Private Blips
  86.  
  87. local function has_value (tab, val)
  88. for index, value in ipairs(tab) do
  89. if value == val then
  90. return true
  91. end
  92. end
  93.  
  94. return false
  95. end
  96.  
  97. local privateBlips = {}
  98. function PrivateGarageBlips()
  99. for _,blip in pairs(privateBlips) do
  100. RemoveBlip(blip)
  101. end
  102. privateBlips = {}
  103. for zoneKey,zoneValues in pairs(Config.Garages)do
  104. if zoneValues.Private and has_value(userProperties, zoneValues.Private) then
  105. local blip = AddBlipForCoord(zoneValues.Pos.x, zoneValues.Pos.y, zoneValues.Pos.z)
  106. SetBlipSprite (blip, Config.BlipPrivate.Sprite)
  107. SetBlipDisplay(blip, 4)
  108. SetBlipScale (blip, 1.0)
  109. SetBlipColour (blip, Config.BlipPrivate.Color)
  110. SetBlipAsShortRange(blip, true)
  111. BeginTextCommandSetBlipName("STRING")
  112. AddTextComponentString(_U('private_garage'))
  113. EndTextCommandSetBlipName(blip)
  114. end
  115. end
  116. end
  117.  
  118. -- End Private Blips
  119. -- End map blip generation
  120. -- Main menu
  121.  
  122. function OpenMenuGarage(PointType)
  123.  
  124. ESX.UI.Menu.CloseAll()
  125.  
  126. local elements = {}
  127.  
  128. if PointType == 'spawn' then
  129. table.insert(elements,{label = _U('list_vehicles'), value = 'list_vehicles'})
  130. end
  131.  
  132. if PointType == 'delete' then
  133. table.insert(elements,{label = _U('stock_vehicle'), value = 'stock_vehicle'})
  134. end
  135.  
  136. if PointType == 'pound' then
  137. table.insert(elements,{label = _U('return_vehicle').." ("..Config.Price.."$)", value = 'return_vehicle'})
  138. end
  139.  
  140. ESX.UI.Menu.Open(
  141. 'default', GetCurrentResourceName(), 'garage_menu',
  142. {
  143. title = _U('garage'),
  144. css = 'garage',
  145. align = 'top-left',
  146. elements = elements,
  147. },
  148. function(data, menu)
  149.  
  150. menu.close()
  151. if(data.current.value == 'list_vehicles') then
  152. ListVehiclesMenu()
  153. end
  154. if(data.current.value == 'stock_vehicle') then
  155. StockVehicleMenu()
  156. end
  157. if(data.current.value == 'return_vehicle') then
  158. ReturnVehicleMenu()
  159. end
  160.  
  161. local playerPed = GetPlayerPed(-1)
  162. SpawnVehicle(data.current.value)
  163.  
  164. end,
  165. function(data, menu)
  166. menu.close()
  167.  
  168. end
  169. )
  170. end
  171.  
  172. -- Vehicle list
  173.  
  174. function ListVehiclesMenu()
  175. local elements = {}
  176.  
  177. ESX.TriggerServerCallback('eden_garage:getVehicles', function(vehicles)
  178.  
  179. for _,v in pairs(vehicles) do
  180.  
  181. local hashVehicule = v.vehicle.model
  182. local vehicleName = GetDisplayNameFromVehicleModel(hashVehicule)
  183. local labelvehicle
  184. local plate = v.plate
  185.  
  186. if(v.state)then
  187. labelvehicle = vehicleName.. ' (' .. plate .. ') ' .._U('garage')
  188. else
  189. labelvehicle = vehicleName.. ' (' .. plate .. ') ' .._U('municipal_pound')
  190. end
  191. table.insert(elements, {label =labelvehicle , value = v})
  192.  
  193. end
  194. local c = 0
  195. for _,a in pairs(vehicles) do
  196. if (a.state) then
  197. c = c + 1
  198. else
  199. c = c - 1
  200. end
  201. end
  202.  
  203.  
  204. ESX.UI.Menu.Open(
  205. 'default', GetCurrentResourceName(), 'spawn_vehicle',
  206. {
  207. title = _U('garage'),
  208. align = 'top-left',
  209. elements = elements,
  210. },
  211. function(data, menu)
  212. if(data.current.value.state)then
  213. menu.close()
  214. if c > 0 then
  215. SpawnVehicle(data.current.value.vehicle, data.current.value.plate)
  216. else
  217. -- TriggerEvent('esx:showNotification', _U('vehicle_is_impounded')) -- LIKELY THIS IS THE CHECK FOR HACKED CAR, Variable "C" was for checking the same plate?
  218. -- TriggerEvent('esx:showNotification', "Vehicle Is Impounded 22A") -- PROBS THIS, CHANGE TO SSPAWNVEHICLE INSTEAD? VEHICLE SHOWS ITS AVAILABLE, BUT IT"S NOT.
  219. SpawnVehicle(data.current.value.vehicle, data.current.value.plate)
  220. end
  221. else
  222. -- TriggerEvent('esx:showNotification', _U('vehicle_is_impounded'))
  223. TriggerEvent('esx:showNotification', "Vehicle Is Impounded 22B")
  224.  
  225. end
  226. end,
  227. function(data, menu)
  228. menu.close()
  229. --CurrentAction = 'open_garage_action'
  230. end
  231. )
  232. end)
  233. end
  234.  
  235. -- End vehicle list
  236.  
  237. function reparation(prix,vehicle,vehicleProps)
  238.  
  239. ESX.UI.Menu.CloseAll()
  240.  
  241. local elements = {
  242. {label = _U('return_vehicle').." ("..prix.."$)", value = 'yes'},
  243. {label = _U('see_mechanic'), value = 'no'},
  244. }
  245. ESX.UI.Menu.Open(
  246. 'default', GetCurrentResourceName(), 'delete_menu',
  247. {
  248. title = _U('damaged_vehicle'),
  249. align = 'top-left',
  250. elements = elements,
  251. },
  252. function(data, menu)
  253.  
  254. menu.close()
  255. if(data.current.value == 'yes') then
  256. TriggerServerEvent('eden_garage:payhealth', prix)
  257. ranger(vehicle,vehicleProps)
  258. end
  259. if(data.current.value == 'no') then
  260. ESX.ShowNotification(_U('visit_mechanic'))
  261. end
  262.  
  263. end,
  264. function(data, menu)
  265. menu.close()
  266.  
  267. end
  268. )
  269. end
  270.  
  271. function ranger(vehicle,vehicleProps)
  272. ESX.Game.DeleteVehicle(vehicle)
  273. TriggerServerEvent('eden_garage:modifystate', vehicleProps.plate, true)
  274. TriggerEvent('esx:showNotification', _U('vehicle_in_garage'))
  275. end
  276.  
  277. -- Store vehicle
  278.  
  279. function StockVehicleMenu()
  280. local playerPed = GetPlayerPed(-1)
  281. if IsPedInAnyVehicle(playerPed, false) then
  282.  
  283. local playerPed = GetPlayerPed(-1)
  284. local coords = GetEntityCoords(playerPed)
  285. local vehicle = GetVehiclePedIsIn(playerPed,false)
  286. local vehicleProps = ESX.Game.GetVehicleProperties(vehicle)
  287.  
  288. local current = GetPlayersLastVehicle(GetPlayerPed(-1), true)
  289. local engineHealth = GetVehicleEngineHealth(current)
  290. local plate = vehicleProps.plate
  291.  
  292. ESX.TriggerServerCallback('eden_garage:stockv',function(valid)
  293.  
  294. if (valid) then
  295. TriggerServerEvent('eden_garage:debug', vehicle)
  296. if engineHealth < 990 then
  297. local fraisRep= math.floor((1000 - engineHealth)/1000*Config.Price*Config.DamageMultiplier)
  298. reparation(fraisRep, vehicle, vehicleProps)
  299. else
  300. ranger(vehicle, vehicleProps)
  301. end
  302. else
  303. TriggerEvent('esx:showNotification', _U('cannot_store_vehicle'))
  304. end
  305. end,vehicleProps)
  306. else
  307. TriggerEvent('esx:showNotification', _('no_vehicle_to_enter'))
  308. end
  309.  
  310. end
  311.  
  312. -- End story vehicle
  313. --End main menu
  314. --Vehicle spawn
  315.  
  316. function SpawnVehicle(vehicle, plate)
  317.  
  318. ESX.Game.SpawnVehicle(vehicle.model,{
  319. x=this_Garage.SpawnPoint.Pos.x ,
  320. y=this_Garage.SpawnPoint.Pos.y,
  321. z=this_Garage.SpawnPoint.Pos.z + 1
  322. },this_Garage.SpawnPoint.Heading, function(callback_vehicle)
  323. ESX.Game.SetVehicleProperties(callback_vehicle, vehicle)
  324. SetVehRadioStation(callback_vehicle, "OFF")
  325. TaskWarpPedIntoVehicle(GetPlayerPed(-1), callback_vehicle, -1)
  326. SetVehicleEngineHealth(callback_vehicle, 1000.0)
  327. SetVehicleBodyHealth(callback_vehicle, 1000.0)
  328. end)
  329.  
  330.  
  331. TriggerServerEvent('eden_garage:modifystate', plate, false)
  332.  
  333. end
  334.  
  335. --End vehicle spawn
  336. --Spawn impounded vehicle
  337.  
  338. function SpawnPoundedVehicle(vehicle, plate)
  339.  
  340. ESX.Game.SpawnVehicle(vehicle.model, {
  341. x = this_Garage.SpawnMunicipalPoundPoint.Pos.x ,
  342. y = this_Garage.SpawnMunicipalPoundPoint.Pos.y,
  343. z = this_Garage.SpawnMunicipalPoundPoint.Pos.z + 1
  344. },this_Garage.SpawnMunicipalPoundPoint.Heading, function(callback_vehicle)
  345. ESX.Game.SetVehicleProperties(callback_vehicle, vehicle)
  346. SetVehRadioStation(callback_vehicle, "OFF")
  347. TaskWarpPedIntoVehicle(GetPlayerPed(-1), callback_vehicle, -1)
  348. end)
  349. TriggerServerEvent('eden_garage:modifystate', plate, true)
  350.  
  351. ESX.SetTimeout(10000, function()
  352. TriggerServerEvent('eden_garage:modifystate', plate, false)
  353. end)
  354.  
  355. end
  356.  
  357. --End spawn impounded vehicle
  358. --Marker action notifications
  359.  
  360. AddEventHandler('eden_garage:hasEnteredMarker', function(zone)
  361.  
  362. if zone == 'spawn' then
  363. CurrentAction = 'spawn'
  364. CurrentActionMsg = _U('press_to_enter')
  365. CurrentActionData = {}
  366. end
  367.  
  368. if zone == 'delete' then
  369. CurrentAction = 'delete'
  370. CurrentActionMsg = _U('press_to_delete')
  371. CurrentActionData = {}
  372. end
  373.  
  374. if zone == 'pound' then
  375. CurrentAction = 'pound_action_menu'
  376. CurrentActionMsg = _U('press_to_impound')
  377. CurrentActionData = {}
  378. end
  379. end)
  380.  
  381. AddEventHandler('eden_garage:hasExitedMarker', function(zone)
  382. ESX.UI.Menu.CloseAll()
  383. CurrentAction = nil
  384. end)
  385.  
  386. --End marker action notifications
  387.  
  388. function ReturnVehicleMenu()
  389.  
  390. ESX.TriggerServerCallback('eden_garage:getOutVehicles', function(vehicles)
  391.  
  392. local elements = {}
  393.  
  394. for _,v in pairs(vehicles) do
  395.  
  396. local hashVehicule = v.model
  397. local vehicleName = GetDisplayNameFromVehicleModel(hashVehicule)
  398. local labelvehicle
  399.  
  400. labelvehicle = vehicleName..': '.._U('return')
  401.  
  402. table.insert(elements, {label =labelvehicle , value = v})
  403.  
  404. end
  405.  
  406. ESX.UI.Menu.Open(
  407. 'default', GetCurrentResourceName(), 'return_vehicle',
  408. {
  409. title = _U('garage'),
  410. align = 'top-left',
  411. elements = elements,
  412. },
  413. function(data, menu)
  414.  
  415. ESX.TriggerServerCallback('eden_garage:checkMoney', function(hasEnoughMoney)
  416. if hasEnoughMoney then
  417.  
  418. if times == 0 then
  419. TriggerServerEvent('eden_garage:pay')
  420. SpawnPoundedVehicle(data.current.value, data.current.value.plate)
  421. times=times+1
  422. elseif times > 0 then
  423. ESX.SetTimeout(60000, function()
  424. times=0
  425. end)
  426. end
  427. else
  428. ESX.ShowNotification(_U('not_enough_money'))
  429. end
  430. end)
  431. end,
  432. function(data, menu)
  433. menu.close()
  434. --CurrentAction = 'open_garage_action'
  435. end
  436. )
  437. end)
  438. end
  439.  
  440. -- Marker display
  441.  
  442. Citizen.CreateThread(function()
  443. while true do
  444. Wait(0)
  445. local coords = GetEntityCoords(GetPlayerPed(-1))
  446.  
  447. for k,v in pairs(Config.Garages) do
  448. if not v.Private or has_value(userProperties, v.Private) then
  449. if(GetDistanceBetweenCoords(coords, v.Pos.x, v.Pos.y, v.Pos.z, true) < Config.DrawDistance) then
  450. 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)
  451. 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)
  452. end
  453. if(v.MunicipalPoundPoint and GetDistanceBetweenCoords(coords, v.MunicipalPoundPoint.Pos.x, v.MunicipalPoundPoint.Pos.y, v.MunicipalPoundPoint.Pos.z, true) < Config.DrawDistance) then
  454. DrawMarker(v.MunicipalPoundPoint.Marker, v.MunicipalPoundPoint.Pos.x, v.MunicipalPoundPoint.Pos.y, v.MunicipalPoundPoint.Pos.z, 0.0, 0.0, 0.0, 0, 0.0, 0.0, v.MunicipalPoundPoint.Size.x, v.MunicipalPoundPoint.Size.y, v.MunicipalPoundPoint.Size.z, v.MunicipalPoundPoint.Color.r, v.MunicipalPoundPoint.Color.g, v.MunicipalPoundPoint.Color.b, 100, false, true, 2, false, false, false, false)
  455. DrawMarker(v.SpawnMunicipalPoundPoint.Marker, v.SpawnMunicipalPoundPoint.Pos.x, v.SpawnMunicipalPoundPoint.Pos.y, v.SpawnMunicipalPoundPoint.Pos.z, 0.0, 0.0, 0.0, 0, 0.0, 0.0, v.SpawnMunicipalPoundPoint.Size.x, v.SpawnMunicipalPoundPoint.Size.y, v.SpawnMunicipalPoundPoint.Size.z, v.SpawnMunicipalPoundPoint.Color.r, v.SpawnMunicipalPoundPoint.Color.g, v.SpawnMunicipalPoundPoint.Color.b, 100, false, true, 2, false, false, false, false)
  456. end
  457. end
  458. end
  459. end
  460. end)
  461.  
  462. -- End marker display
  463. -- Activate menu when in
  464.  
  465. Citizen.CreateThread(function()
  466. local currentZone = 'garage'
  467. while true do
  468.  
  469. Wait(0)
  470.  
  471. local coords = GetEntityCoords(GetPlayerPed(-1))
  472. local isInMarker = false
  473.  
  474. for _,v in pairs(Config.Garages) do
  475. if not v.Private or has_value(userProperties, v.Private) then
  476. if(GetDistanceBetweenCoords(coords, v.SpawnPoint.Pos.x, v.SpawnPoint.Pos.y, v.SpawnPoint.Pos.z, true) < v.Size.x) then
  477. isInMarker = true
  478. this_Garage = v
  479. currentZone = 'spawn'
  480. end
  481.  
  482. if(GetDistanceBetweenCoords(coords, v.DeletePoint.Pos.x, v.DeletePoint.Pos.y, v.DeletePoint.Pos.z, true) < v.Size.x) then
  483. isInMarker = true
  484. this_Garage = v
  485. currentZone = 'delete'
  486. end
  487. if(v.MunicipalPoundPoint and GetDistanceBetweenCoords(coords, v.MunicipalPoundPoint.Pos.x, v.MunicipalPoundPoint.Pos.y, v.MunicipalPoundPoint.Pos.z, true) < v.MunicipalPoundPoint.Size.x) then
  488. isInMarker = true
  489. this_Garage = v
  490. currentZone = 'pound'
  491. end
  492. end
  493. end
  494.  
  495. if isInMarker and not hasAlreadyEnteredMarker then
  496. hasAlreadyEnteredMarker = true
  497. LastZone = currentZone
  498. TriggerEvent('eden_garage:hasEnteredMarker', currentZone)
  499. end
  500.  
  501. if not isInMarker and hasAlreadyEnteredMarker then
  502. hasAlreadyEnteredMarker = false
  503. TriggerEvent('eden_garage:hasExitedMarker', LastZone)
  504. end
  505.  
  506. end
  507. end)
  508.  
  509. -- End Activate menu when in
  510. -- Controls/Keybinds
  511.  
  512. Citizen.CreateThread(function()
  513. while true do
  514.  
  515. Citizen.Wait(0)
  516.  
  517. if CurrentAction ~= nil then
  518.  
  519. SetTextComponentFormat('STRING')
  520. AddTextComponentString(CurrentActionMsg)
  521. DisplayHelpTextFromStringLabel(0, 0, 1, -1)
  522.  
  523. if IsControlPressed(0, Keys['E']) and (GetGameTimer() - GUI.Time) > 150 then
  524.  
  525. if CurrentAction == 'pound_action_menu' then
  526. OpenMenuGarage('pound')
  527. end
  528. if CurrentAction == 'spawn' then
  529. OpenMenuGarage('spawn')
  530. end
  531. if CurrentAction == 'delete' then
  532. OpenMenuGarage('delete')
  533. end
  534.  
  535.  
  536. CurrentAction = nil
  537. GUI.Time = GetGameTimer()
  538.  
  539. end
  540. end
  541. end
  542. end)
  543.  
  544. -- End Controls/Keybinds
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement