Skip to content

objects.attach

Places the object relative to its target and turns it with the target. It follows the target into its interior and is visible to nearby players who can see the target. Attached objects have no collision. Attaching ends any active move.

objects.attach(id: number, target: ScriptObjectAttachmentTarget, offset?: Vector3, rotationDegrees?: Vector3): Promise<ActionResult>
Name Type Description
id number The ID from objects.create.
target ScriptObjectAttachmentTarget A player, vehicle or script object. A player or vehicle must be in the object’s virtual world. An object target may also be in every virtual world.
offset Vector3 Metres from the target along its own axes. Each component must be within ±25 and defaults to 0.
rotationDegrees Vector3 Rotation in the target’s frame, with each angle within ±3600 degrees. Defaults to [0, 0, 0].

An ActionResult. A missing target, one without a position, or a target in another virtual world returns attachment-target-unavailable. Cycles return object-attachment-cycle. Chains may be at most eight links long (object-attachment-depth), and the gamemode can have up to 256 attachments (object-attachment-limit).

gamemodes/my-mode.ts
import { commands, objects } from "nativemp";
commands.register("wearprop", async (player, args) => {
await objects.attach(Number(args), { kind: "player", player }, [0, 0, 1.25]);
});