SetPlayerInVehicle: Difference between revisions

From Onset Developer Wiki
Created page with "{{Info|Function|Server|1.0}} {{FuncDescription|__EDIT_ME__}} {{FuncSyntax|SetPlayerInVehicle(player, vehicle [, seat])}} {{FuncParameters}} {{FuncParam|player|__EDIT_ME__}}..."
 
No edit summary
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Info|Function|Server|1.0}}
{{Info|Function|Server|1.0}}


{{FuncDescription|__EDIT_ME__}}
{{FuncDescription|With this function you can put players inside vehicles or use it to change their seats}}


{{FuncSyntax|SetPlayerInVehicle(player, vehicle [, seat])}}
{{FuncSyntax|SetPlayerInVehicle(player, vehicle [, seat])}}


{{FuncParameters}}
{{FuncParameters}}
{{FuncParam|player|__EDIT_ME__}}
{{FuncParam|player|Player you want to set in a vehicle}}
{{FuncParam|vehicle |__EDIT_ME__}}
{{FuncParam|vehicle |Vehicle you want to set player into}}
{{FuncParamOptional|seat|__EDIT_ME__}}
{{FuncParamOptional|seat|Seat number you want to set player into, 1: front left, 2: front right, 3: rear left, 4: rear right}}


{{FuncReturnValue|__EDIT_ME__}}
NOTE: Some vehicles have more than 4 seats.
 
{{FuncReturnValue|Returns '''true''' on success.}}


== Example ==
== Example ==
__EDIT_ME__
<syntaxhighlight lang="Lua">
--This function enables player to go from passenger seat to driver seat
function shuff(player)
  local veh = GetPlayerVehicle(player)
    --Check if player is inside a vehicle
  if veh ~= 0 then
      --if driver seat is empty
      if GetVehicleDriver(veh) == 0 or not GetVehicleDriver(veh) then
        if GetPlayerVehicleSeat(player) == 2 then --check if player is in passenger seat
            SetPlayerInVehicle(player, veh, 1)
        end
      end
  end
end
AddCommand('shuff', shuff)
 
 
function spawnTaxiCar(player)
    local x,y,z = GetPlayerLocation(player)
    local h = GetPlayerHeading(player)
 
    local veh = CreateVehicle(2, x, y, z, h)
    SetPlayerInVehicle(player, veh)
end
AddCommand('taxi', spawnTaxiCar)
</syntaxhighlight>


{{RelatedFunctions}}
{{RelatedFunctions}}
__EDIT_ME__
*[[GetPlayerVehicle]]
*[[GetPlayerVehicleSeat]]
*[[SetPlayerInVehicle]]
*[[RemovePlayerFromVehicle]]

Latest revision as of 18:48, 14 December 2020

SetPlayerInVehicle

Type: Function
Context: Server
Introduced: v1.0

Description

With this function you can put players inside vehicles or use it to change their seats

Syntax

SetPlayerInVehicle(player, vehicle [, seat])

Parameters

  • player
    Player you want to set in a vehicle
  • vehicle
    Vehicle you want to set player into
  • seat (optional)
    Seat number you want to set player into, 1: front left, 2: front right, 3: rear left, 4: rear right

NOTE: Some vehicles have more than 4 seats.

Return Value

  • Returns true on success.

Example

--This function enables player to go from passenger seat to driver seat
function shuff(player)
   local veh = GetPlayerVehicle(player)
    --Check if player is inside a vehicle
   if veh ~= 0 then
      --if driver seat is empty
      if GetVehicleDriver(veh) == 0 or not GetVehicleDriver(veh) then
         if GetPlayerVehicleSeat(player) == 2 then --check if player is in passenger seat
            SetPlayerInVehicle(player, veh, 1)
         end
      end
   end
end
AddCommand('shuff', shuff)


function spawnTaxiCar(player)
    local x,y,z = GetPlayerLocation(player)
    local h = GetPlayerHeading(player)

    local veh = CreateVehicle(2, x, y, z, h)
    SetPlayerInVehicle(player, veh)
end
AddCommand('taxi', spawnTaxiCar)

See also