diff --git a/code/modules/projectiles/gun.dm b/code/modules/projectiles/gun.dm index 14412db63746..91a323abad26 100644 --- a/code/modules/projectiles/gun.dm +++ b/code/modules/projectiles/gun.dm @@ -72,6 +72,9 @@ //* Attachments *// /// Installed attachments + /// + /// * Set to list of typepaths to immediately install them on init. + /// * Do not set this. var/list/obj/item/gun_attachment/attachments /// Attachment alignments. /// @@ -232,6 +235,23 @@ if(attachment_alignment) attachment_alignment = typelist(NAMEOF(src, attachment_alignment), attachment_alignment) + //* handle attachments *// + if(length(attachments)) + var/list/translating_attachments = attachments + attachments = list() + for(var/obj/item/gun_attachment/casted as anything in translating_attachments) + var/obj/item/gun_attachment/actual + if(IS_ANONYMOUS_TYPEPATH(casted)) + actual = new casted + else if(ispath(casted, /obj/item/gun_attachment)) + actual = new casted + else if(istype(casted)) + actual = casted + if(actual.attached != src) + if(!install_attachment(actual)) + stack_trace("[actual] ([actual.type]) couldn't be auto-installed on initialize despite being in list.") + qdel(actual) + //! LEGACY: firemodes for(var/i in 1 to firemodes.len) var/key = firemodes[i]