Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function _SetEntityAsNoLongerNeeded(entity)
- Citizen.InvokeNative(0xB736A491E64A32CF,Citizen.PointerValueIntInitialized(entity))
- end
- local lastVehicle
- local function SpawnVehicle(model, x, y, z, heading, ped)
- -- Just in case they are in a vehicle which this trainer didn't spawn.
- if not lastVehicle and GetVehiclePedIsIn(ped, false) then
- lastVehicle = GetVehiclePedIsIn(ped, false)
- end
- if IsModelValid(model) then
- _LoadModel( model )
- local veh = CreateVehicle( model, x, y, z + 1, heading, true, true )
- if featureSpawnInsideCar then
- SetPedIntoVehicle(ped, veh, -1)
- end
- if featureDeleteLastVehicle then
- _SetEntityAsNoLongerNeeded(veh)
- -- Remove the last vehicle.
- if (lastVehicle) then
- if(GetVehicleNumberOfPassengers(lastVehicle) ~= 0 or IsVehicleSeatFree(lastVehicle, -1) == false) then
- drawNotification("~r~Last Vehicle could not be deleted.")
- else
- SetEntityAsMissionEntity(lastVehicle, true, true)
- DeleteVehicle(lastVehicle)
- end
- end
- end
- drawNotification("~g~Vehicle spawned!")
- lastVehicle = veh
- UpdateVehicleFeatureVariables( veh )
- toggleRadio(ped)
- SetModelAsNoLongerNeeded( veh )
- return veh
- else
- drawNotification("~r~Invalid Model!")
- end
- end
- RegisterNUICallback("vehspawnoptions", function(data,cb)
- local text = "~r~OFF"
- if(data.newstate) then
- text = "~g~ON"
- end
- if data.action == "despawn" then
- featureDeleteLastVehicle = data.newstate
- drawNotification("Delete Previous Vehicle: "..tostring(text))
- elseif data.action == "insidecar" then
- featureSpawnInsideCar = data.newstate
- drawNotification("Spawn Into Vehicle: "..tostring(text))
- elseif data.action == "infront" then
- featureSpawnCarInFront = data.newstate
- drawNotification( "Spawn vehicle in front: " .. tostring( text ) )
- end
- if(cb)then cb("ok") end
- end)
- RegisterNUICallback("vehspawn", function(data, cb)
- local playerPed = GetPlayerPed(-1)
- local x, y, z
- local vehicle
- if ( featureSpawnCarInFront ) then
- x, y, z = table.unpack( GetOffsetFromEntityInWorldCoords( playerPed, 0.0, 7.5, 0.0 ) )
- else
- x, y, z = table.unpack( GetEntityCoords( playerPed, true ) )
- end
- local heading = GetEntityHeading(playerPed)
- if data.action == "input" then
- local result = requestInput("", 60)
- if result then
- vehicle = SpawnVehicle(GetHashKey(string.upper(result)), x, y, z, heading, playerPed)
- UpdateVehicleFeatureVariables( vehicle )
- end
- return
- end
- local playerVeh = GetVehiclePedIsIn(playerPed, true)
- local vehhash = GetHashKey(data.action)
- vehicle = SpawnVehicle(vehhash, x, y, z, heading, playerPed)
- UpdateVehicleFeatureVariables( vehicle )
- if ( cb ) then cb( "ok" ) end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement