Player::putIntoVehicle
Server-Side Function
JavaScript |
---|
JavaScript Syntax
This method puts player into vehicle.
The vehicle must be streamed-in for this method to work as intended.
For client side head to [Player::setIntoVehicle]
Syntax
player.putIntoVehicle(vehicle, seat)
Seats:
- 0 - driver seat
- 1 - passenger seat 1
- 2 - passenger seat 2
- 3 - passenger seat 3
Example
//Server side
mp.events.addCommand("spawncar", (player, _, model = "sultanrs") => {
const position = player.position;
const vehicle = mp.vehicles.new(mp.joaat(model), position); //Creating the vehicle
player.putIntoVehicle(vehicle, 0); //we put the player into the vehicle as soon as the vehicle is streamed in.
})
Quick Snippet
Making a custom vehicle stream in handler for server side.
//Server side
mp.events.addCommand("spawncar", (player, _) => {
const position = new mp.Vector3(573.07, -352.55, 43.21); //A random position to spawn the vehicle at
const vehicle = mp.vehicles.new(mp.joaat("sultanrs"), position); //Creating the vehicle
//Adding a custom method to the vehicle which will handle the stream in (will be called from the client).
vehicle.onStreamIn = (veh) => { //supports async as well
if (!player || !mp.players.exists(player)) return; //if the player is no longer available when this method is called we return here.
player.putIntoVehicle(veh, 0); //we put the player into the vehicle as soon as the vehicle is streamed in.
}
player.position = vehicle.position; //setting player position to the vehicle position
})
//Adding a event which will be called from client when the vehicle streams in
mp.events.add('server::vehicleStreamIn', async (player, remoteid) => {
const vehicle = mp.vehicles.at(remoteid);
if (!vehicle || !mp.vehicles.exists(vehicle)) return;
if (!vehicle.onStreamIn || typeof vehicle.onStreamIn === 'undefined') return;
vehicle.onStreamIn.constructor.name === 'AsyncFunction' ? await vehicle.onStreamIn(vehicle) : vehicle.onStreamIn(vehicle);
});
//Client side
mp.events.add('entityStreamIn', (entity) => {
if (entity.type === 'vehicle') {
mp.events.callRemote('server::vehicleStreamIn', entity.remoteId);
}
});
See Also
- Functions
- Player::ban
- Player::call
- Player::callProc
- Player::callToStreamed
- Player::callUnreliable
- Player::cancelPendingRpc
- Player::clearDecorations
- Player::getClothes
- Player::getDecoration
- Player::getFaceFeature
- Player::getHeadBlend
- Player::getHeadOverlay
- Player::getProp
- Player::getWeaponAmmo
- Player::giveWeapon
- Player::hasPendingRpc
- Player::invoke
- Player::isStreamed
- Player::isStreamedFor
- Player::kick
- Player::kickSilent
- Player::notify
- Player::outputChatBox
- Player::playAnimation
- Player::playScenario
- Player::putIntoVehicle
- Player::removeFromVehicle
- Player::removeObject
- Player::removeWeapon
- Player::removeAllWeapons
- Player::resetWeapon
- Player::setClothes
- Player::setCustomization
- Player::setDecoration
- Player::setFaceFeature
- Player::setHairColor
- Player::setHeadBlend
- Player::setHeadOverlay
- Player::setProp
- Player::setWeaponAmmo
- Player::spawn
- Player::stopAnimation
- Player::updateHeadBlend
- Player::enableVoiceTo
- Player::disableVoiceTo
- Weapons::clear
- Entity::destroy
- Entity::dist
- Entity::distSquared
- Entity::getVariable
- Entity::setVariable
- Entity::setVariables
- Properties
- Player::action
- Player::aimTarget
- Player::allWeapons
- Player::armour
- Player::eyeColor
- Player::faceFeatures
- Player::hairColor
- Player::hairHighlightColor
- Player::heading
- Player::health
- Player::rgscId
- Player::ip
- Player::serial
- Player::isAiming
- Player::isClimbing
- Player::isEnteringVehicle
- Player::isInCover
- Player::isInMelee
- Player::isJumping
- Player::isLeavingVehicle
- Player::isOnLadder
- Player::isReloading
- Player::name
- Player::packetLoss
- Player::ping
- Player::seat
- Player::socialClub
- Player::streamedPlayers
- Player::vehicle
- Player::voiceListeners
- Player::disableOutgoingSync
- Player::weapon
- Player::weaponAmmo
- Player::weapons
- Entity::alpha
- Entity::data
- Entity::dimension
- Entity::id
- Entity::model
- Entity::position
- Entity::type