SetObjectAttached: Difference between revisions

From Onset Developer Wiki
No edit summary
No edit summary
Line 4: Line 4:


{{FuncSyntax|SetObjectAttached(object, attachtype, attachid, x, y, z [, rx, ry, rz, SocketName])}}
{{FuncSyntax|SetObjectAttached(object, attachtype, attachid, x, y, z [, rx, ry, rz, SocketName])}}
 
<div class="noprint" style="float:right;">
[[File:AttachToilet.png|250px]]
</div>
{{FuncParameters}}
{{FuncParameters}}
{{FuncParam|object|The object identifier from [[CreateObject]].}}
{{FuncParam|object|The object identifier from [[CreateObject]].}}

Revision as of 08:53, 25 October 2019

SetObjectAttached

Type: Function
Context: Server
Introduced: v1.0

Description

Attaches an object to another entity.

Syntax

SetObjectAttached(object, attachtype, attachid, x, y, z [, rx, ry, rz, SocketName])

Parameters

  • object
    The object identifier from CreateObject.
  • attachtype
    AttachType
  • attachid
    The identifier of the other entity you want to attach to.
  • x
    Relative X location.
  • y
    Relative Y location.
  • z
    Relative Z location.
  • rx (optional)
    Relative pitch rotation.
  • ry (optional)
    Relative yaw rotation.
  • rz (optional)
    Relative roll rotation.
  • SocketName (optional)
    Socket where to attach to (PlayerBones). Can be empty.

Return Value

  • Returns true on success.

Example

function cmd_hat(player, hatobject)
	if (PlayerData[player].hat ~= 0) then
		DestroyObject(PlayerData[player].hat)
		PlayerData[player].hat = 0
	end

	local hatModel = 0

	if hatobject == nil then
		local startHats = 398
		local endHats = 477

		hatModel = Random(startHats, endHats)
	else
		hatModel = math.tointeger(hatobject)
	end

	local x, y, z = GetPlayerLocation(player)
	PlayerData[player].hat = CreateObject(hatModel, x, y, z)

	SetObjectAttached(PlayerData[player].hat, ATTACH_PLAYER, player, 14.0, 0.0, 0.0, 0.0, 90.0, -90.0, "head")
	SetObjectAttached(PlayerData[player].hat, ATTACH_PLAYER, player, 14.0, 0.0, 0.0, 0.0, 90.0, -90.0, "head")

	AddPlayerChat(player, "Attached object model id as hat: "..hatModel)
end
AddCommand("hat", cmd_hat)

See also

__EDIT_ME__