SetObjectAttached: Difference between revisions
From Onset Developer Wiki
Created page with "{{Info|Function|Server|1.0}} {{FuncDescription|__EDIT_ME__}} {{FuncSyntax|SetObjectAttached(object, attachtype, attachid, x, y, z [, rx, ry, rz])}} {{FuncParameters}} {{Fun..." |
No edit summary |
||
(5 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{{Info|Function|Server|1.0}} | {{Info|Function|Server|1.0}} | ||
{{FuncDescription| | {{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])}} | |||
<div class="noprint" style="float:right;"> | |||
[[File:AttachToilet.png|250px]] | |||
</div> | |||
{{FuncParameters}} | {{FuncParameters}} | ||
{{FuncParam|object| | {{FuncParam|object|The object identifier from [[CreateObject]].}} | ||
{{FuncParam|attachtype| | {{FuncParam|attachtype|[[AttachType]]}} | ||
{{FuncParam|attachid| | {{FuncParam|attachid|The identifier of the other entity you want to attach to.}} | ||
{{FuncParam|x| | {{FuncParam|x|Relative X location.}} | ||
{{FuncParam|y| | {{FuncParam|y|Relative Y location.}} | ||
{{FuncParam|z | | {{FuncParam|z|Relative Z location.}} | ||
{{ | {{FuncParamOptional|rx|Relative pitch rotation.}} | ||
{{ | {{FuncParamOptional|ry|Relative yaw rotation.}} | ||
{{FuncParamOptional|rz| | {{FuncParamOptional|rz|Relative roll rotation.}} | ||
{{FuncParamOptional|SocketName|Socket where to attach to ([[PlayerBones]]). Can be empty.}} | |||
{{FuncReturnValue| | {{FuncReturnValue|Returns '''true''' on success.}} | ||
== Example == | == Example == | ||
<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}} | ||
{{ObjectFunctions}} |
Latest revision as of 16:36, 8 October 2020
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
- CreateObject
- DestroyObject
- IsValidObject
- GetObjectCount
- GetObjectModel
- IsObjectStreamedIn
- EnableObjectStreamEvents
- SetObjectStreamDistance
- SetObjectLocation
- GetObjectLocation
- SetObjectRotation
- GetObjectRotation
- SetObjectScale
- GetObjectScale
- SetObjectAttached
- SetObjectDetached
- IsObjectAttached
- GetObjectAttachmentInfo
- IsObjectMoving
- SetObjectMoveTo
- StopObjectMove
- SetObjectRotateAxis
- GetObjectModelCount
- GetObjectMass
- GetStreamedObjects
- GetObjectBoundingBox
- GetObjectSize
- EnableObjectHitEvents
- SetObjectEditable
- SetObjectOutline
- SetObjectColor
- SetObjectEmissiveColor
- SetObjectTexture
- SetObjectAnimatedTexture
- SetObjectCastShadow
- SetObjectDimension
- GetObjectActor
- GetAllObjects
- SetObjectModel