Skip to content

Instantly share code, notes, and snippets.

@spotco
Last active December 2, 2022 01:30
Show Gist options
  • Save spotco/d48e850caab45cfdda7df5400c0896c3 to your computer and use it in GitHub Desktop.
Save spotco/d48e850caab45cfdda7df5400c0896c3 to your computer and use it in GitHub Desktop.
accessory_to_lua.lua
local accessory = game.Selection:Get()[1]
while accessory.ClassName ~= "Accessory" do
accessory = accessory.Parent
end
local function fill_list_of_direct_children_of_classname(obj,type,list)
for _,child in pairs(obj:GetChildren()) do
if child.ClassName == type then
list[#list+1] = child
end
end
end
local function first_child_of_type(obj,type)
local __first_child_of_type = {}
fill_list_of_direct_children_of_classname(obj,type,__first_child_of_type)
local rtv = nil
if #__first_child_of_type > 0 then
rtv = __first_child_of_type[1]
end
return rtv
end
assert(accessory.ClassName == "Accessory")
local handle = first_child_of_type(accessory,"Part")
local attachment = first_child_of_type(handle,"Attachment")
local specialmesh = first_child_of_type(handle,"SpecialMesh")
local msg = [[
]]
msg = msg .. string.format([[
local neu_accessory, neu_attachment, neu_mesh = SPAvatarEquipmentBase:create_accessory_base(
character,
"%s",
"%s",
"%s",
"%s"
)
]],
accessory.Name,
attachment.Name,
specialmesh.MeshId,
specialmesh.TextureId
)
msg = msg .. string.format([[
neu_accessory.AttachmentForward = Vector3.new(%s)
neu_accessory.AttachmentPos = Vector3.new(%s)
neu_accessory.AttachmentRight = Vector3.new(%s)
neu_accessory.AttachmentUp = Vector3.new(%s)
]],
tostring(accessory.AttachmentForward),
tostring(accessory.AttachmentPos),
tostring(accessory.AttachmentRight),
tostring(accessory.AttachmentUp)
)
msg = msg .. string.format([[
neu_attachment.Orientation = Vector3.new(%s)
neu_attachment.Position = Vector3.new(%s)
]],
tostring(attachment.Orientation),
tostring(attachment.Position)
)
msg = msg .. string.format([[
neu_mesh.Offset = Vector3.new(%s)
neu_mesh.Scale = Vector3.new(%s)
neu_mesh.VertexColor = Vector3.new(%s)
]],
tostring(specialmesh.Offset),
tostring(specialmesh.Scale),
tostring(specialmesh.VertexColor)
)
msg = msg .. [[
SPAvatarEquipmentBase:attach_character_accessory(character,neu_accessory)
]]
print(msg)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment