- Documentation
- Shared functions
- setPedEnterVehicle
Function
setPedEnterVehicle
Tells a ped to get into a vehicle the normal way, walking up and playing the door animation. On the client it only works for the local player: the player walks to a vehicle within 10 m and gets in (other peds give false). On the server it records the ped's task and sends every client the onClientPedEnterRequest event (ped, vehicle, seat), which a client script can handle; the ped itself does not walk up yet on the server.
Syntax
bool setPedEnterVehicle(ped ped [, vehicle vehicle = nil, int/bool seat = 0])Arguments
pedped- The ped that should get in. On the client it must be
localPlayer. vehiclevehicle, optional = nil- The vehicle. Omitted = the nearest vehicle (client: within 10 m, server: within 10 m).
seatint/bool, optional = 0- Seat: a number 0-8 (0 = driver),
true= the nearest free passenger seat (client only),false/omitted = driver.
Returns
true when the order was accepted.
Example
bindKey("g", "down", function()
if not isPedInVehicle(localPlayer) then
setPedEnterVehicle(localPlayer, nil, true)
end
end)
See also
warpPedIntoVehicleInstantly puts a player or an NPC into the chosen vehicle seat, without walking up and without the get-in animation. If the ped was in another car, it is taken out of it first. When the chosen seat is occupied by someone else, nothing happens and the function returnsfalse. The player's game receives the order immediately, and the server blocks the player from getting out on their own for 3 seconds so the warp is not undone. An NPC in a vehicle always stays seated: while it is in the car, its body has no collision (only bullets hit it), walking and turning wait until it leaves the car, and if the game takes it out of the seat, the client puts it back at once.setPedExitVehicleTakes a ped out of its vehicle on the server, records its "exit vehicle" task and sends every client theonClientPedExitRequestevent (ped, vehicle). The exit works likeremovePedFromVehicle, i.e. instantly, without the door animation. Returnsfalsewhen the ped is not in a vehicle.