Advertisement
Guest User

Untitled

a guest
Oct 6th, 2017
629
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. if ( data == "button1" ) then
  2. TriggerEvent( 'Engine' )
  3.  
  4. -- Thats from cl_action.lua for the button
  5.  
  6. -- This goes at the bottom of cl_action.lua
  7. RegisterNetEvent('Engine')
  8.  
  9. local vehicles = {}
  10. local State = {}
  11.  
  12. Citizen.CreateThread(function()
  13. while true do
  14. Citizen.Wait(0)
  15. if GetSeatPedIsTryingToEnter(GetPlayerPed(-1)) == -1 and not table.contains(vehicles, GetVehiclePedIsTryingToEnter(GetPlayerPed(-1))) then
  16. table.insert(vehicles, GetVehiclePedIsTryingToEnter(GetPlayerPed(-1)))
  17. table.insert(State, IsVehicleEngineOn(GetVehiclePedIsTryingToEnter(GetPlayerPed(-1))))
  18. elseif IsPedInAnyVehicle(GetPlayerPed(-1), false) and not table.contains(vehicles, GetVehiclePedIsIn(GetPlayerPed(-1), false)) then
  19. table.insert(vehicles, GetVehiclePedIsIn(GetPlayerPed(-1), false))
  20. table.insert(State, IsVehicleEngineOn(GetVehiclePedIsIn(GetPlayerPed(-1), false)))
  21. end
  22. for i = 1, tablelength(vehicles) do
  23. if (GetPedInVehicleSeat(vehicles[i], -1) == GetPlayerPed(-1)) or IsVehicleSeatFree(vehicles[i], -1) then
  24. SetVehicleEngineOn(vehicles[i], State[i], State[i], State[i])
  25. end
  26. end
  27. end
  28. end)
  29.  
  30. AddEventHandler('Engine', function()
  31. local veh
  32. local StateIndex
  33. for i = 1, tablelength(vehicles) do
  34. if vehicles[i] == GetVehiclePedIsIn(GetPlayerPed(-1), false) then
  35. veh = vehicles[i]
  36. StateIndex = i
  37. end
  38. end
  39. if IsPedInAnyVehicle(GetPlayerPed(-1), false) then
  40. if (GetPedInVehicleSeat(veh, -1) == GetPlayerPed(-1)) then
  41. if IsVehicleEngineOn(veh) then
  42. State[StateIndex] = false
  43. else
  44. State[StateIndex] = true
  45. end
  46. end
  47. end
  48. end)
  49.  
  50. function drawNotification(text) --Just Don't Edit!
  51. SetNotificationTextEntry("STRING")
  52. AddTextComponentString(text)
  53. DrawNotification(false, false)
  54. end
  55.  
  56. function tablelength(T) --Just Don't Edit!
  57. local count = 0
  58. for _ in pairs(T) do count = count + 1 end
  59. return count
  60. end
  61.  
  62. function table.contains(table, element)
  63. for _, value in pairs(table) do
  64. if value == element then
  65. return true
  66. end
  67. end
  68. return false
  69. end
  70.  
  71. -- Then add the button in ui.lua and change button 1 to whatever button you are gonna use.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement