Mohamed-Hussien

Park

Sep 20th, 2020
801
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --client
  2. Citizen.CreateThread(function()
  3.     Wait(3000)
  4.     ESX.TriggerServerCallback("IsRespawned", function(firstplayer)
  5.         if firstplayer == false then
  6.             ESX.TriggerServerCallback("GetAllVehicles", function(vehicles)
  7.                 for i, v in pairs (vehicles) do
  8.                     local vehPos = json.decode(v.pos)
  9.                     local vehProperties = json.decode(v.vehicle)
  10.                     local plate = v.plate
  11.                     local exisitedVehicle = ESX.Game.GetClosestVehicle(vector3(vehPos.x, vehPos.y, vehPos.z), { [vehProperties.model] = true })
  12.                     if exisitedVehicle then
  13.                         ESX.Game.DeleteVehicle(exisitedVehicle)
  14.                     end
  15.                     local veh = CreateVehicle(vehProperties.model, vehPos.x, vehPos.y, vehPos.z, vehPos.heading)
  16.                     Wait(1000)
  17.                     if DoesEntityExist(veh) then
  18.                         SetVehicleEngineOn(veh, false, true, true)
  19.                         TriggerServerEvent('nfwlock:setVehicleDoorsForEveryone', {veh, 2, plate})
  20.                         SetVehicleProperties(veh, vehProperties)
  21.                     end
  22.                 end
  23.             end)
  24.         end
  25.     end)
  26. end)
  27.  
  28. function SetVehicleProperties (vehicle, props)
  29.     if DoesEntityExist(vehicle) then
  30.         local colorPrimary, colorSecondary = GetVehicleColours(vehicle)
  31.         local pearlescentColor, wheelColor = GetVehicleExtraColours(vehicle)
  32.         SetVehicleModKit(vehicle, 0)
  33.  
  34.         if props.plate then SetVehicleNumberPlateText(vehicle, props.plate) end
  35.         if props.plateIndex then SetVehicleNumberPlateTextIndex(vehicle, props.plateIndex) end
  36.         if props.bodyHealth then SetVehicleBodyHealth(vehicle, props.bodyHealth + 0.0) end
  37.         if props.engineHealth then SetVehicleEngineHealth(vehicle, props.engineHealth + 0.0) end
  38.         if props.tankHealth then SetVehiclePetrolTankHealth(vehicle, props.tankHealth + 0.0) end
  39.         if props.fuelLevel then SetVehicleFuelLevel(vehicle, props.fuelLevel + 0.0) end
  40.         if props.dirtLevel then SetVehicleDirtLevel(vehicle, props.dirtLevel + 0.0) end
  41.         if props.color1 then SetVehicleColours(vehicle, props.color1, colorSecondary) end
  42.         if props.color2 then SetVehicleColours(vehicle, props.color1 or colorPrimary, props.color2) end
  43.         if props.pearlescentColor then SetVehicleExtraColours(vehicle, props.pearlescentColor, wheelColor) end
  44.         if props.wheelColor then SetVehicleExtraColours(vehicle, props.pearlescentColor or pearlescentColor, props.wheelColor) end
  45.         if props.wheels then SetVehicleWheelType(vehicle, props.wheels) end
  46.         if props.windowTint then SetVehicleWindowTint(vehicle, props.windowTint) end
  47.  
  48.         if props.neonEnabled then
  49.             SetVehicleNeonLightEnabled(vehicle, 0, props.neonEnabled[1])
  50.             SetVehicleNeonLightEnabled(vehicle, 1, props.neonEnabled[2])
  51.             SetVehicleNeonLightEnabled(vehicle, 2, props.neonEnabled[3])
  52.             SetVehicleNeonLightEnabled(vehicle, 3, props.neonEnabled[4])
  53.         end
  54.  
  55.         if props.extras then
  56.             for extraId,enabled in pairs(props.extras) do
  57.                 if enabled then
  58.                     SetVehicleExtra(vehicle, tonumber(extraId), 0)
  59.                 else
  60.                     SetVehicleExtra(vehicle, tonumber(extraId), 1)
  61.                 end
  62.             end
  63.         end
  64.  
  65.         if props.neonColor then SetVehicleNeonLightsColour(vehicle, props.neonColor[1], props.neonColor[2], props.neonColor[3]) end
  66.         if props.xenonColor then SetVehicleXenonLightsColour(vehicle, props.xenonColor) end
  67.         if props.modSmokeEnabled then ToggleVehicleMod(vehicle, 20, true) end
  68.         if props.tyreSmokeColor then SetVehicleTyreSmokeColor(vehicle, props.tyreSmokeColor[1], props.tyreSmokeColor[2], props.tyreSmokeColor[3]) end
  69.         if props.modSpoilers then SetVehicleMod(vehicle, 0, props.modSpoilers, false) end
  70.         if props.modFrontBumper then SetVehicleMod(vehicle, 1, props.modFrontBumper, false) end
  71.         if props.modRearBumper then SetVehicleMod(vehicle, 2, props.modRearBumper, false) end
  72.         if props.modSideSkirt then SetVehicleMod(vehicle, 3, props.modSideSkirt, false) end
  73.         if props.modExhaust then SetVehicleMod(vehicle, 4, props.modExhaust, false) end
  74.         if props.modFrame then SetVehicleMod(vehicle, 5, props.modFrame, false) end
  75.         if props.modGrille then SetVehicleMod(vehicle, 6, props.modGrille, false) end
  76.         if props.modHood then SetVehicleMod(vehicle, 7, props.modHood, false) end
  77.         if props.modFender then SetVehicleMod(vehicle, 8, props.modFender, false) end
  78.         if props.modRightFender then SetVehicleMod(vehicle, 9, props.modRightFender, false) end
  79.         if props.modRoof then SetVehicleMod(vehicle, 10, props.modRoof, false) end
  80.         if props.modEngine then SetVehicleMod(vehicle, 11, props.modEngine, false) end
  81.         if props.modBrakes then SetVehicleMod(vehicle, 12, props.modBrakes, false) end
  82.         if props.modTransmission then SetVehicleMod(vehicle, 13, props.modTransmission, false) end
  83.         if props.modHorns then SetVehicleMod(vehicle, 14, props.modHorns, false) end
  84.         if props.modSuspension then SetVehicleMod(vehicle, 15, props.modSuspension, false) end
  85.         if props.modArmor then SetVehicleMod(vehicle, 16, props.modArmor, false) end
  86.         if props.modTurbo then ToggleVehicleMod(vehicle,  18, props.modTurbo) end
  87.         if props.modXenon then ToggleVehicleMod(vehicle,  22, props.modXenon) end
  88.         if props.modFrontWheels then SetVehicleMod(vehicle, 23, props.modFrontWheels, false) end
  89.         if props.modBackWheels then SetVehicleMod(vehicle, 24, props.modBackWheels, false) end
  90.         if props.modPlateHolder then SetVehicleMod(vehicle, 25, props.modPlateHolder, false) end
  91.         if props.modVanityPlate then SetVehicleMod(vehicle, 26, props.modVanityPlate, false) end
  92.         if props.modTrimA then SetVehicleMod(vehicle, 27, props.modTrimA, false) end
  93.         if props.modOrnaments then SetVehicleMod(vehicle, 28, props.modOrnaments, false) end
  94.         if props.modDashboard then SetVehicleMod(vehicle, 29, props.modDashboard, false) end
  95.         if props.modDial then SetVehicleMod(vehicle, 30, props.modDial, false) end
  96.         if props.modDoorSpeaker then SetVehicleMod(vehicle, 31, props.modDoorSpeaker, false) end
  97.         if props.modSeats then SetVehicleMod(vehicle, 32, props.modSeats, false) end
  98.         if props.modSteeringWheel then SetVehicleMod(vehicle, 33, props.modSteeringWheel, false) end
  99.         if props.modShifterLeavers then SetVehicleMod(vehicle, 34, props.modShifterLeavers, false) end
  100.         if props.modAPlate then SetVehicleMod(vehicle, 35, props.modAPlate, false) end
  101.         if props.modSpeakers then SetVehicleMod(vehicle, 36, props.modSpeakers, false) end
  102.         if props.modTrunk then SetVehicleMod(vehicle, 37, props.modTrunk, false) end
  103.         if props.modHydrolic then SetVehicleMod(vehicle, 38, props.modHydrolic, false) end
  104.         if props.modEngineBlock then SetVehicleMod(vehicle, 39, props.modEngineBlock, false) end
  105.         if props.modAirFilter then SetVehicleMod(vehicle, 40, props.modAirFilter, false) end
  106.         if props.modStruts then SetVehicleMod(vehicle, 41, props.modStruts, false) end
  107.         if props.modArchCover then SetVehicleMod(vehicle, 42, props.modArchCover, false) end
  108.         if props.modAerials then SetVehicleMod(vehicle, 43, props.modAerials, false) end
  109.         if props.modTrimB then SetVehicleMod(vehicle, 44, props.modTrimB, false) end
  110.         if props.modTank then SetVehicleMod(vehicle, 45, props.modTank, false) end
  111.         if props.modWindows then SetVehicleMod(vehicle, 46, props.modWindows, false) end
  112.  
  113.         if props.modLivery then
  114.             SetVehicleMod(vehicle, 48, props.modLivery, false)
  115.             SetVehicleLivery(vehicle, props.modLivery)
  116.         end
  117.     end
  118. end
  119.  
  120. --server
  121.  
  122. ESX = nil
  123. local firstPlayer = false
  124. TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
  125.  
  126. ESX.RegisterServerCallback('IsRespawned', function(source, cb)
  127.     if firstPlayer then
  128.         cb(true)
  129.     else
  130.         cb(false)
  131.         firstPlayer = true
  132.     end
  133. end)
  134.  
  135.  
  136. ESX.RegisterServerCallback('GetAllVehicles', function(source, cb)
  137.     MySQL.Async.fetchAll('SELECT * FROM parking', {}, function(vehicles)
  138.         print("^1[My-Parking Resource]: ^2All Vehicles Has Been Returned To Their Places!!")       
  139.         cb(vehicles)
  140.     end)
  141. end)
  142.  
RAW Paste Data