Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2018
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.72 KB | None | 0 0
  1.  
  2. local function _SetEntityAsNoLongerNeeded(entity)
  3. Citizen.InvokeNative(0xB736A491E64A32CF,Citizen.PointerValueIntInitialized(entity))
  4. end
  5.  
  6. local lastVehicle
  7.  
  8. local function SpawnVehicle(model, x, y, z, heading, ped)
  9. -- Just in case they are in a vehicle which this trainer didn't spawn.
  10. if not lastVehicle and GetVehiclePedIsIn(ped, false) then
  11. lastVehicle = GetVehiclePedIsIn(ped, false)
  12. end
  13.  
  14. if IsModelValid(model) then
  15. _LoadModel( model )
  16.  
  17. local veh = CreateVehicle( model, x, y, z + 1, heading, true, true )
  18.  
  19. if featureSpawnInsideCar then
  20. SetPedIntoVehicle(ped, veh, -1)
  21. end
  22.  
  23. if featureDeleteLastVehicle then
  24. _SetEntityAsNoLongerNeeded(veh)
  25. -- Remove the last vehicle.
  26. if (lastVehicle) then
  27. if(GetVehicleNumberOfPassengers(lastVehicle) ~= 0 or IsVehicleSeatFree(lastVehicle, -1) == false) then
  28. drawNotification("~r~Last Vehicle could not be deleted.")
  29. else
  30. SetEntityAsMissionEntity(lastVehicle, true, true)
  31. DeleteVehicle(lastVehicle)
  32. end
  33. end
  34. end
  35.  
  36. drawNotification("~g~Vehicle spawned!")
  37. lastVehicle = veh
  38. UpdateVehicleFeatureVariables( veh )
  39. toggleRadio(ped)
  40.  
  41. SetModelAsNoLongerNeeded( veh )
  42.  
  43. return veh
  44. else
  45. drawNotification("~r~Invalid Model!")
  46. end
  47. end
  48.  
  49.  
  50.  
  51. RegisterNUICallback("vehspawnoptions", function(data,cb)
  52. local text = "~r~OFF"
  53. if(data.newstate) then
  54. text = "~g~ON"
  55. end
  56. if data.action == "despawn" then
  57. featureDeleteLastVehicle = data.newstate
  58. drawNotification("Delete Previous Vehicle: "..tostring(text))
  59. elseif data.action == "insidecar" then
  60. featureSpawnInsideCar = data.newstate
  61. drawNotification("Spawn Into Vehicle: "..tostring(text))
  62. elseif data.action == "infront" then
  63. featureSpawnCarInFront = data.newstate
  64. drawNotification( "Spawn vehicle in front: " .. tostring( text ) )
  65. end
  66.  
  67. if(cb)then cb("ok") end
  68. end)
  69.  
  70.  
  71.  
  72. RegisterNUICallback("vehspawn", function(data, cb)
  73. local playerPed = GetPlayerPed(-1)
  74. local x, y, z
  75. local vehicle
  76.  
  77. if ( featureSpawnCarInFront ) then
  78. x, y, z = table.unpack( GetOffsetFromEntityInWorldCoords( playerPed, 0.0, 7.5, 0.0 ) )
  79. else
  80. x, y, z = table.unpack( GetEntityCoords( playerPed, true ) )
  81. end
  82.  
  83. local heading = GetEntityHeading(playerPed)
  84.  
  85. if data.action == "input" then
  86. local result = requestInput("", 60)
  87.  
  88. if result then
  89. vehicle = SpawnVehicle(GetHashKey(string.upper(result)), x, y, z, heading, playerPed)
  90. UpdateVehicleFeatureVariables( vehicle )
  91. end
  92. return
  93. end
  94.  
  95. local playerVeh = GetVehiclePedIsIn(playerPed, true)
  96. local vehhash = GetHashKey(data.action)
  97.  
  98. vehicle = SpawnVehicle(vehhash, x, y, z, heading, playerPed)
  99.  
  100. UpdateVehicleFeatureVariables( vehicle )
  101.  
  102. if ( cb ) then cb( "ok" ) end
  103. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement