SetObjectAttached: Difference between revisions

From Onset Developer Wiki
No edit summary
No edit summary
Line 1: Line 1:
{{Info|Function|Server|1.0}}
{{Info|Function|Server|1.0}}


{{FuncDescription|__EDIT_ME__}}
{{FuncDescription|Attaches an object to another entity.}}


{{FuncSyntax|SetObjectAttached(object, attachtype, attachid, x, y, z [, rx, ry, rz, SocketName])}}
{{FuncSyntax|SetObjectAttached(object, attachtype, attachid, x, y, z [, rx, ry, rz, SocketName])}}
Line 20: Line 20:


== 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__
__EDIT_ME__

Revision as of 18:25, 13 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__