Squirrel/Server/Functions/Vehicles/Driver

From Liberty Unleashed Wiki
(Difference between revisions)
Jump to: navigation, search
(Example)
(fixed some possible dodgy possibilities (like driver: null))
Line 11: Line 11:
  
 
== 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 == "driver" )
+
    if ( szCommand == "driver" )
{
+
    {
local pVehicle = FindVehicle( 0 );
+
          local pVehicle = pPlayer.Vehicle;
if ( pVehicle ) MessagePlayer( "Vehicle ID (0) Driver: " + pVehicle.Driver, pPlayer );
+
          if ( pVehicle )
}
+
          {
+
              local pDriver = pVehicle.Driver;
return 1;
+
              if ( pDriver ) MessagePlayer( "Vehicle Driver: " + pDriver.Name, pPlayer );
 +
          }
 +
    }
 +
   
 +
    return 1;
 
}
 
}
 
</code>
 
</code>

Revision as of 18:57, 29 September 2010

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

This Vehicle class member returns a pointer to the vehicle driver, or if the vehicle has no driver, null.

Syntax

  1. Player Vehicle.Driver

Arguments

  • none

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.Driver;
  10. if ( pDriver ) MessagePlayer( "Vehicle Driver: " + pDriver.Name, pPlayer );
  11. }
  12. }
  13. return 1;
  14. }
  15.  

Notes

The functions MessagePlayer and FindVehicle 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