Scripting/Server/Classes/Vehicle/AttachTo
(v0.3.1-r2+; objects v0.5-rc2+) Glues the player to a vehicle - or to a script object (FindObject(id) / CreateObject(...): a moving platform, a lift, a swing) - at the offset (x right, y forward, z up, in the vehicles frame - e.g. 0, -0.3, 1.0 for the roof); returns true when it worked. The player stays a normal on-foot player (aims, shoots, turns), the vehicle carries him and every client shows it. Detached by player.Detach(), entering a vehicle, a respawn or a virtual world change.
Syntax
player.AttachTo(vehicle | object, x, y, z [, heading])player.AttachTo(vehicle | object, Vector offset [, heading])player.Detach()Arguments
- any vehicle | object
- float x
- float y
- float z
- float heading (optional)
- Vector offset
Example
function onPlayerCommand( player, cmd, params )
{
if ( cmd == "ride" )
{
local obj = CreateObject( 1362, player.Pos );
player.AttachTo( obj, Vector( 0.0, 0.0, 1.0 ) ); // stand on the object (0.5-rc2: objects too)
obj.MoveTo( Vector( player.Pos.x + 40.0, player.Pos.y, player.Pos.z ), 5.0 );
}
else if ( cmd == "unride" ) player.Detach();
}Related pages
- vehicle.Remove
- vehicle.Respawn
- vehicle.Fix
- vehicle.Explode
- vehicle.SetBurstableTyres
- object.AttachTo
- object.AttachToBone
- vehicle.SetComponentStatus
- vehicle.SetComponentStatus
- vehicle.SetComponentAngle
- vehicle.SetComponentColour
- vehicle.TurretRotation
Section: Vehicle
Categories: Server methods | Vehicle