Scripting/Squirrel/Functions/Vehicles/Pos
From VC-MP Wiki
This instance variable returns or sets the position of a vehicle.
Syntax
Vector vehicle.Pos vehicle.Pos = Vector newPos
Example 1. Returning
This command tells the location of a vehicle when someone types '/c carloc vehicleid'.
function onPlayerCommand( player, cmd, text ) { if ( cmd == "carloc" ) { local veh = FindVehicle( text.tointeger() ); if ( !veh ) MessagePlayer( "Error: Vehicle not found.", player ); else { local pos = veh.Pos; MessagePlayer( "Vehicle ID " + veh.ID + " location: " + GetDistrictName( pos.x, pos.y ), player ); } } }
Notes
The functions MessagePlayer, FindVehicle, vehicle.ID, GetDistrictName and call onPlayerCommand were used in in this example. More info about them in corresponding pages.
Example 2. Setting
This command drops player's vehicle if they type '/c carjump'.
function onPlayerCommand( player, cmd, text ) { if ( cmd == "carjump" ) { local veh = player.Vehicle; if ( !veh ) MessagePlayer( "Error: You are currently on foot.", player ); else { local pos = veh.Pos; pos.z += 100; veh.Pos = pos; } } }
Notes
The functions MessagePlayer, player.Vehicle and call onPlayerCommand were used in in this example. More info about them in the corresponding pages.
Related Functions
- CreateVehicle
- FindVehicle
- GetVehicleCount
- GetVehicleModelFromName
- GetVehicleNameFromModel
- Vehicle.Alarm
- Vehicle.Angle
- Vehicle.Colour1
- Vehicle.Colour2
- Vehicle.Driver
- Vehicle.Fix
- Vehicle.Health
- Vehicle.ID
- Vehicle.IsLocked
- Vehicle.KillEngine
- Vehicle.Lights
- Vehicle.Model
- Vehicle.Pos
- Vehicle.Respawn
- Vehicle.RespawnAs
- Vehicle.RespawnAt
- Vehicle.SetFlatTyres
- Vehicle.SpawnPos
- Vehicle.SpawnAngle
- Vehicle.Velocity
- Vehicle.Remove
