Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local myThread = ScriptThread ( "carspawn" )
- function myThread:Run()
- while self:IsRunning() do
- if IsKeyDown ( F4 ) then
- setVehicleModel ( VEHICLE_AIRBUS) --spawn the new car where the old one originally was
- end
- if IsKeyDown ( F11 ) then
- setVehicleModel ( VEHICLE_BLISTA ) --spawn the new car where the old one originally was
- end
- if IsKeyDown ( VK_OEM_5 ) then
- setVehicleModel ( VEHICLE_BLISTA2 ) --spawn the new car where the old one originally was
- end
- if IsKeyDown ( F13 ) then
- setVehicleModel ( VEHICLE_BLISTA3 ) --spawn the new car where the old one originally was
- end
- if IsKeyDown ( F14 ) then
- setVehicleModel ( VEHICLE_BTYPE ) --spawn the new car where the old one originally was
- end
- self:Wait(50)
- end
- end
- --spawning script
- function setVehicleModel ( vehicle, model )
- local position = vehicle:GetPosition()--position
- local rotation = natives.ENTITY.GET_ENTITY_ROTATION ( vehicle.ID, 0 )--rotation
- local velocity = vehicle:GetVelocity()--speed
- local heading = vehicle:GetHeading()
- local occupants = getVehiclePassengers ( vehicle )--passengers in format { { -1, playerid }, { 0, false } }
- local oldCarPosition = vehicle:GetOffsetVector ( 0, 0, 5 )--new coordinates for the old car to gtfo temporarily
- vehicle:SetPosition ( oldCarPosition.x, oldCarPosition.y, oldCarPosition.z )--move the old car
- streaming.RequestModel ( model )--request new car model
- local newCar = game.CreateVehicle ( model, position )--spawn the new car where the old one originally ways
- streaming.ReleaseModel ( model )--release the request
- newCar:SetVelocity ( velocity )--set the speed of the new car using the vector from GetVelocity
- natives.ENTITY.SET_ENTITY_ROTATION ( vehicle.ID, rotation.x, rotation.y, rotation.z, 1, true )--set the rotation to the old rotation
- newCar:SetHeading(heading)
- for i=1,#occupants do--for each object in my table
- if occupants[i][2] then--if we actually got a player in that seat
- natives.AI.CLEAR_PED_TASKS_IMMEDIATELY ( occupants[i][2] )--remove them from the car
- end
- end
- wthread:Wait(50)
- vehicle:SetPosition ( 0, 0, 0 )--move the car to no man's land for game engine deletion
- removeVehicle ( vehicle.ID )
- natives.PED.SET_PED_INTO_VEHICLE ( LocalPlayer().ID, newCar.ID, -1 )--move local player into the new vehicle
- newCar:SetEngineState ( true )
- end
- function getVehiclePassengers ( vehicle )
- if natives.ENTITY.IS_ENTITY_A_VEHICLE ( vehicle.ID ) then
- local maxPassengers = natives.VEHICLE.GET_VEHICLE_MAX_NUMBER_OF_PASSENGERS ( vehicle.ID ) - 2
- local occupants = {}
- for i=-1,maxPassengers do
- local seatFree = natives.VEHICLE.IS_VEHICLE_SEAT_FREE ( vehicle.ID, i )
- local occupant = false
- if not seatFree then
- occupant = natives.VEHICLE.GET_PED_IN_VEHICLE_SEAT ( vehicle.ID, i )
- end
- table.insert ( occupants, { i, occupant } )
- end
- return occupants
- elseif natives.ENTITY.IS_ENTITY_AN_ENTITY ( vehicle.ID ) then
- print ( "getVehiclePassengers - Variable 'vehicle' was not a vehicle entity." )
- return false
- else
- print ( "getVehiclePassengers - Variable 'vehicle' was not a vehicle entity nor entity." )
- return false
- end
- end
- function removeVehicle ( vehicle )
- c_veh = CMemoryBlock ( 4 )
- c_veh:WriteDWORD32 ( 0, vehicle )
- natives.ENTITY.DELETE_ENTITY ( c_veh )
- c_veh:Release()
- wthread:Wait ( 0 )
- end
- function myThread:OnError()
- self:Reset()
- end
- myThread:Register()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement