Squirrel/Server/Functions/Vehicles/GetPassenger

From Liberty Unleashed Wiki
(Difference between revisions)
Jump to: navigation, search
(Example)
(We don't like null passengers)
Line 10: Line 10:
  
 
== Example ==
 
== Example ==
 +
 +
This example command returns who is driving the vehicle when a player types '/driver'.
  
 
<code lang="squirrel">
 
<code lang="squirrel">
 
function onPlayerCommand( pPlayer, szCommand, szText )
 
function onPlayerCommand( pPlayer, szCommand, szText )
 
{
 
{
if ( szCommand == "passenger" )
+
    if ( szCommand == "driver" )
{
+
    {
local pVehicle = FindVehicle( 0 );
+
          local pVehicle = pPlayer.Vehicle;
if ( pVehicle ) MessagePlayer( "Vehicle ID (0) Passenger in Seat ID 1: " + pVehicle.GetPassenger( 1 ), pPlayer );
+
          if ( pVehicle )
}
+
          {
+
              local pDriver = pVehicle.GetPassenger( 0 );
return 1;
+
              if ( pDriver ) MessagePlayer( "Vehicle Driver: " + pDriver.Name, pPlayer );
 +
          }
 +
    }
 +
   
 +
    return 1;
 
}
 
}
 
</code>
 
</code>
Line 26: Line 32:
 
=== Notes ===
 
=== Notes ===
  
The functions [[Squirrel/Server/Functions/Messages/MessagePlayer|MessagePlayer]] and [[Squirrel/Server/Functions/Vehicles/FindVehicle|FindVehicle]] and event [[Squirrel/Server/Events/Player/onPlayerCommand|onPlayerCommand]] were used in this example. More info about them in the corresponding pages.
+
The functions [[Squirrel/Server/Functions/Messages/MessagePlayer|MessagePlayer]], [[Squirrel/Server/Functions/Players/Vehicle|Player.Vehicle]] and event [[Squirrel/Server/Events/Player/onPlayerCommand|onPlayerCommand]] were used in this example. More info about them in the corresponding pages.
  
 
== Related Functions ==
 
== Related Functions ==
  
 
{{Squirrel/Server/Functions/Vehicles}}
 
{{Squirrel/Server/Functions/Vehicles}}

Revision as of 19:00, 29 September 2010

Home   |   Squirrel Scripting   |   Server Functions   |   Server Events   |   Client Functions   |   Client Events

This Vehicle class method will return the passenger pointer for the given seat. If the seat has no passenger, a null pointer will be returned.

Syntax

  1. Player Vehicle.GetPassenger( int seat )

Arguments

  • seat - The seat you wish to return the passenger for. seat is an integer from 0 to 7, 0 being the driver's seat.

Example

This example command returns who is driving the vehicle when a player types '/driver'.

  1.  
  2. function onPlayerCommand( pPlayer, szCommand, szText )
  3. {
  4. if ( szCommand == "driver" )
  5. {
  6. local pVehicle = pPlayer.Vehicle;
  7. if ( pVehicle )
  8. {
  9. local pDriver = pVehicle.GetPassenger( 0 );
  10. if ( pDriver ) MessagePlayer( "Vehicle Driver: " + pDriver.Name, pPlayer );
  11. }
  12. }
  13. return 1;
  14. }
  15.  

Notes

The functions MessagePlayer, Player.Vehicle and event onPlayerCommand were used in this example. More info about them in the corresponding pages.

Related Functions

Personal tools
Namespaces

Variants
Actions
Navigation
scripting
Toolbox