THEJean_Kevin

Untitled

Jun 5th, 2018
415
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.40 KB | None | 0 0
  1. local garage = {
  2.     {x=216.329,y=-792.278,z=30.492}
  3. }
  4. local VehiclePlayer = {}
  5.  
  6.  
  7. RegisterNetEvent("ft_libs:OnClientReady")
  8. AddEventHandler('ft_libs:OnClientReady', function()
  9.     creationGarage()
  10. end)
  11.  
  12. function addVehicleToPlayer(data)
  13.     VehiclePlayer[data["plateText" ]] = {model = data[ "model" ], data = data, inGarage = data["inGarage"]}
  14.     TriggerServerEvent("car:RegisterImatriculation",data["plateText" ])
  15. end
  16.  
  17. RegisterNetEvent("car:GetAllPlayerVehicle")
  18. AddEventHandler("car:GetAllPlayerVehicle", function(result)
  19.     for i = 1, i =< #result) do
  20.         addVehicleToPlayer(result[i])
  21.     end
  22. end)
  23.  
  24.  
  25.  
  26. function creationGarage()
  27.     for i =1, #garage do
  28.         exports.ft_libs:AddArea("Garage"..i, {
  29.             marker = {text = "Garage", type = 1, weight = 1, height = 2, red = 51, green = 153, blue = 255,showDistance = 20},
  30.             trigger = { weight = 1, active = { callback = openGarage } },
  31.             blip = { text = "Garage", colorId = 38, imageId = 50 },
  32.             locations = {
  33.                 { x = garage[i].x , y = garage[i].y, z = garage[i].z},
  34.             }
  35.         })
  36.     end
  37.  
  38.     exports.ft_libs:AddMenu("car:garage",{
  39.         menuTitle = "Bienvenue au garage",
  40.         closable = true,
  41.         position = 1,
  42.         buttons = {
  43.             {text = "Quitter", close = true, exec = {callback = function()SetEntityInvincible(GetPlayerPed(-1), false)end)}}
  44.             {text = "Rentrer vehicule",buttons = {{text = "Retour", back = true}} exec = {callback = rentrerVehicule}},
  45.             {text = "Sortir vehicule", exec = {callback = sortirVehiculeInit}},
  46.         }
  47.     })
  48.     exports.ft_libs:AddMenu("car:outVehicle",{position = 1,menuTitle ="Sortir Vehicule"})
  49. end
  50.  
  51. function openGarage(data)
  52.     if not exports.ft_libs:MenuIsOpen() then   
  53.         exports.ft_libs:HelpPromt("Appuyez sur ~INPUT_CONTEXT~ pour ouvrir le ~g~garage")
  54.         if IsControlJustPressed(1,51) then
  55.             exports.ft_libs:OpenMenu("car:garage")
  56.             SetEntityInvincible(GetPlayerPed(-1), true)
  57.         end
  58.     end
  59.  
  60. end
  61.  
  62.  
  63. function SpawnVehicleGarage(data)
  64.     local pos = GetEntityCoords(PlayerPedId())
  65.     local veh = SpawnVehicle(data.vehicleData.data["Model"],data.vehicleData.data,{x=pos.x,y=pos.y,z=pos.z},240,true)
  66.     SetEntityAsMissionEntity(veh,true,false)
  67.     TaskWarpPedIntoVehicle(GetPlayerPed(-1), veh, -1)
  68.     SetVehicleHasBeenOwnedByPlayer(veh, true)
  69.     VehiclePlayer[data.vehicleData.data["plateText"]].inGarage = 0
  70.     exports.ft_libs:CloseMenu()
  71.     SetEntityInvincible(GetPlayerPed(-1), false)
  72. end
  73.  
  74.  
  75. function sortirVehiculeInit()
  76. exports.ft_libs:CleanMenuButtons("car:outVehicle")
  77. exports.ft_libs:AddMenuButton("car:outVehicle", {{text = "Retour", back = true}})
  78.     for k,v in pairs(VehiclePlayer) do
  79.         if VehiclePlayer[k].inGarage == 1 then
  80.             exports.ft_libs:AddMenuButton("car:outVehicle", {{text = VehiclePlayer[k].model.. "  ("..k..")", exec = {callback = SpawnVehicleGarage}, data = {vehicleData = VehiclePlayer[k]}}})
  81.         end
  82.     end
  83.     exports.ft_libs:NextMenu("car:outVehicle")
  84. end
  85.  
  86.  
  87. function rentrerVehicule()
  88.     local playerPed = GetPlayerPed(-1)
  89.     local notfound = true
  90.     local vehicle
  91.     if IsPedSittingInAnyVehicle(playerPed) then
  92.         vehicle = GetVehiclePedIsIn(playerPed, true)
  93.     else
  94.  
  95.             Citizen.Wait(0)
  96.             local pos = GetEntityCoords(PlayerPedId())
  97.             local entityWorld = GetOffsetFromEntityInWorldCoords(playerPed, 0.0, 20.0, 0.0)
  98.  
  99.             local rayHandle = CastRayPointToPoint(pos.x, pos.y, pos.z, entityWorld.x, entityWorld.y, entityWorld.z, 10, playerPed, 0)
  100.             local a, b, c, d, vehicleHandle = GetRaycastResult(rayHandle)
  101.  
  102.             if vehicleHandle ~= nil then
  103.                 if IsEntityAVehicle(vehicleHandle) then
  104.                     vehicle = vehicleHandle
  105.  
  106.                 end
  107.         end
  108.     end
  109.  
  110.     if vehicle ~= nil then
  111.         plate = GetVehicleNumberPlateText(vehicle)
  112.         if VehiclePlayer[plate] ~= nil then
  113.             if VehiclePlayer[plate].inGarage == 0 then
  114.                 TriggerServerEvent("car:SetVehicleGarage",plate,1)
  115.                 VehiclePlayer[plate].inGarage = 1
  116.                 exports.ft_libs:TextNotification({ text = "Ton vehicule a été mit au garage", time = 5000 })
  117.                 SetEntityAsMissionEntity(vehicle)
  118.                 DeleteVehicle(vehicle)
  119.                 exports.ft_libs:CloseMenu()
  120.                 SetEntityInvincible(GetPlayerPed(-1), true)
  121.             else
  122.                 exports.ft_libs:TextNotification({ text = "Ce vehicule est sortie (contacte un admin si tu voie ce message)", time = 5000 })
  123.             end
  124.         else
  125.             exports.ft_libs:TextNotification({ text = "Ce vehicule ne t'appartiens pas", time = 5000 })
  126.         end
  127.     else
  128.         exports.ft_libs:TextNotification({ text = "Pas de vehicule à rentrer", time = 5000 })
  129.     end
  130. end
Advertisement
Add Comment
Please, Sign In to add comment