Squirrel/Server/Functions/Vehicles/GetPassenger

From Liberty Unleashed Wiki
(Difference between revisions)
Jump to: navigation, search
(We don't like null passengers)
(Example)
 
Line 11: Line 11:
 
== Example ==
 
== Example ==
  
This example command returns who is driving the vehicle when a player types '/driver'.
+
This example command returns the passenger who is sat in seat ID 0 of the current vehicle when a player types '/passenger'.
  
 
<code lang="squirrel">
 
<code lang="squirrel">
 
function onPlayerCommand( pPlayer, szCommand, szText )
 
function onPlayerCommand( pPlayer, szCommand, szText )
 
{
 
{
     if ( szCommand == "driver" )
+
     if ( szCommand == "passenger" )
 
     {
 
     {
 
           local pVehicle = pPlayer.Vehicle;
 
           local pVehicle = pPlayer.Vehicle;
 
           if ( pVehicle )
 
           if ( pVehicle )
 
           {
 
           {
               local pDriver = pVehicle.GetPassenger( 0 );
+
               local pPassenger = pVehicle.GetPassenger( 0 );
               if ( pDriver ) MessagePlayer( "Vehicle Driver: " + pDriver.Name, pPlayer );
+
               if ( pPassenger ) MessagePlayer( "Vehicle Driver: " + pPassenger.Name, pPlayer );
 
           }
 
           }
 
     }
 
     }

Latest revision as of 20:34, 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.

[edit] Syntax

  1. Player Vehicle.GetPassenger( int seat )

[edit] 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.

[edit] Example

This example command returns the passenger who is sat in seat ID 0 of the current vehicle when a player types '/passenger'.

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

[edit] Notes

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

[edit] Related Functions

Personal tools
Namespaces

Variants
Actions
Navigation
scripting
Toolbox