ID:158606
 
Greetings,

I am trying to add overlays to a turf that also overlay any objects and mobs which enter the turf, but obviously since the turf is below the mob the overlay is also..

At first I tried spawning a lot of objects to do it and it worked but it's way too CPU intensive. Simply adding the icon to a turfs overlays fixed the CPU problem but didn't overlay mobs and objects with the icon as well.

Is there a CPU friendly way to overlay an area with an icon that also is on a higher layer than mobs and objects?
The easiest way would be to make the overlays an object or turf, and to simply set them to have a higher layer than everything else. Examine this, which is something I just cooked up then:

obj
circle
icon='Hear demo.dmi'
icon_state="circle"
layer=5
mob/verb
Overlay()
for(var/turf/T in range())
T.overlays+=new /obj/circle
spawn(60)
T.overlays -= /obj/circle


Notice how I've set the circle's layer to 5? This is the higher than the highest pre-defined layer, the highest being MOB_LAYER at 4. Simple think of layers as an ordering system of importance, where the atom with the highest layer is shown at the top, and atom's with similar layers are displayed depending on which was put their last.
In response to Demon_F0rce
Hmm thanks yeah I tried that and it works but I can't get it off afterwards T.overlays -= /obj/circle didn't work.
In response to Liens
Which I find strange, since that works for me. Did you wait the full 6 seconds (assuming you're testing out the test code I used)?
In response to Demon_F0rce
obj/Block
icon= 'block.dmi'
layer= MOB_LAYER+6
New(mob/M)
..()
if(M && M.colour)
icon+= M.colour

//This is cut out from the verb
for(T in view())
T.icon= 'dirt.dmi'
T.overlays+= new/obj/Block(usr)
spawn(5+rand(10))
world << 1
T.overlays-= /obj/Block


That's the code I'm using to do it, I put a world << 1 in to see if it is actually getting that far and it does, so I don't see what is stopping it from removing the overlay...
In response to Liens
That's because you've changed the icon from the default, so removing the type path will no longer work (as that simply fetches the default icon for the type). You'll need to store the created obj in a variable and then remove that one specifically (speaking of which: create the obj BEFORE the loop, not within it):

var/obj/Block/B = new(usr)
for(T in view())
T.overlays += B
spawn(5)
T.overlays -= B


Note that you can use image objects instead of objs in this case, which just makes more sense.
In response to Garthor
Yes, but also if you want the overlays to do more, for example:

obj/pithole
Entered(atom/A)
src<<"You fell down a hole!"


It would be much easier, not sure if even possible, to simply add the obj (I don't know why you'd want some like this, but eh...).
In response to Demon_F0rce
If you want overlays to do anything but look pretty then you should not be using overlays, because that's all they can do.

Not even going to go into how you managed to pack in as many errors as lines of code, there.
In response to Garthor
Thanks man, that was a big help!