ID:273890
 
Right now I am working on putting clothing my NPCs during runtime. More specifically, during world/New(). Is there any way to make sure that an object is fully created before the mob/New() calls on my NPCs? Right now I create a shirt for my NPCs during world/New() like so...
var/obj/item/shirt/npc_shirt
world/New()
..()
npc_shirt = new /obj/item/shirt(null)
var/icon/i = npc_shirt.icon
i += rgb(175,0,0)
npc_shirt.icon = i

...and then in my mob/npc/New() I have...
mob/npc/New()
..()
src.overlays += npc_shirt

However, this only works if I put a spawn() delay before adding the shirt overlay because the problem is that the NPC is getting the overlay BEFORE the npc_shirt object is created. What I want to do is make sure the shirt object is fully created before my NPC object is created :\
I think this should create shirt before other objects, but I'm not entirely sure:
> var/obj/item/shirt/npc_shirt
> world/New()
> npc_shirt = new /obj/item/shirt(null)
> var/icon/i = npc_shirt.icon
> i += rgb(175,0,0)
> npc_shirt.icon = i
> ..()
try call a proc to make the shirt in /mob/npc/New()
maybe
mob/npc/proc/Make_shirt(npc_shirt)
npc_shirt = new /obj/item/shirt(null)
var/icon/i = npc_shirt.icon
i += rgb(175,0,0)
npc_shirt.icon = i
return npc_shirt


mob/npc/New()
..()
var/obj/item/shirt/npc_shirt
Make_shirt(npc_shirt)
src.overlays += npc_shirt
In response to Prf X
That is what I am avoiding doing because then EVERY mob created as such will create a new shirt object which takes up unnecessary resources. If I have 100 NPCs, with your method, I would have 100 different shirt objects created. With my method, I would have ONE shirt object that all 100 NPCs share.
In response to Spunky_Girl
Then it would require a slight modification.

world
proc
NPCShirt() // Make NPC Shirt proc + Equip
// Make shirt
for(var/mob/NPC/N in world) // Loop through all NPCs in world
N.overlays += // Whatever you set shirt as //
In response to Lugia319
That works o.o I can't believe I never thought of using a loop after creating the shirt like that haha. Thank you, Lugia. Although it does seem like it would be resource-intensive if given enough NPCs...
In response to Spunky_Girl
Well, there is a way to expand the code to only give shirts to NPCs that are being seen and do not have shirts already. But really, in the end, every NPC is going to get a shirt one way or another, might as well do it all at once.
In response to Spunky_Girl
What if you try to create an NPC at runtime?