SetObjectAttached: Difference between revisions

From Onset Developer Wiki
No edit summary
No edit summary
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Info|Function|Server|1.0}}
{{Info|Function|Server|1.0}}


{{FuncDescription|__EDIT_ME__}}
{{FuncDescription|Attaches an object to another entity.
 
This function disables object collision. See [[Enabling_Attached_Object_Collision]] on how to enable them again.}}


{{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]].}}
Line 20: Line 24:


== Example ==
== Example ==
__EDIT_ME__
<syntaxhighlight lang="Lua">
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)
</syntaxhighlight>


{{RelatedFunctions}}
{{RelatedFunctions}}
__EDIT_ME__
{{ObjectFunctions}}

Latest revision as of 16:36, 8 October 2020

SetObjectAttached

Type: Function
Context: Server
Introduced: v1.0

Description

Attaches an object to another entity.

This function disables object collision. See Enabling_Attached_Object_Collision on how to enable them again.

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