Scripting/Server/Classes/Vehicle/AttachToBone

(v0.3.3+) Glues the object to a body part of a player - a hat on the head, a weapon on the back, glasses, a bag on the spine - like attached objects in SA-MP. The object follows the animated bone, so it turns and bends with the player through every animation (run, crouch, aim ...). GTA III has no bone system, but a ped is a hierarchy of animated frames; bone is one of them: BONE_SPINE (1), BONE_HEAD (2), BONE_LEFT_UPPER_ARM (3), BONE_RIGHT_UPPER_ARM (4), BONE_LEFT_HAND (5), BONE_RIGHT_HAND (6), BONE_LEFT_THIGH (7), BONE_RIGHT_THIGH (8), BONE_LEFT_FOOT (9), BONE_RIGHT_FOOT (10), BONE_RIGHT_CALF (11). The offset is in metres and the rotation in degrees, measured from the bone origin in the axes of the player standing idle: x = to his right, y = forward, z = up. So an object with rotation 0 stands upright and faces the way the player faces, and AttachToBone(player, BONE_HEAD, 0, 0, 0.1) puts it on top of the head. The head, spine and leg bones keep that orientation while they move; the hand and arm bones turn with the arm. Use object.Detach() to take it off. The object editor (EditObject) works on it and saves the offset relative to the bone. Objects glued to a player disappear with the object, not with the player: remove them when the player leaves (onPlayerPart).

Syntax

object.AttachToBone(player, bone, x, y, z [, rx, ry, rz])
(player, bone, Vector offset [, Vector rotation])

Arguments

Returns

true when attached

Example

function onPlayerCommand( player, cmd, params )
{
	if ( cmd == "attachtobone" )
	{
		local pos = player.Pos;
		local obj = CreateObject( 1362, player.Pos );
		local result = obj.AttachToBone( player, 0, pos.x, pos.y, pos.z );
		MessagePlayer( "object.AttachToBone returned: " + result, player );
	}
}

This sample was generated from the signature – adapt the values to your gamemode.

Section: Vehicle

Categories: Server methods | Vehicle