ID:264912
 
Code:
mob
proc
Targeting(var/mob/M as mob)
if(src.target)
var/mob/M2 = src.target
M2.overlays-=/image/target_pointer/
world << "[M2]=M2"
src.target=M
var/image/target_pointer/I = new
M.overlays+=I
src.client.images+=I


Problem description:

The first attempt at targeting doesn't work, the target var is set, but the overlays don't work. The second time targeting something (and any time after that), it works as it should, it removes the previous target's overlay, and places one on the new target. But that's not the only problem, if I remove the:
world << "[M2] M2"

The overlays don't work at all, it was there simply as a debugger. I thought it might be doing that because it could be sending the overlays(image) with M2 to the world, making it visible. But if it was, it should be showing the pointer on the previous target, not the active target. I'm sure I'm missing something obvious, or going about it the wrong way, but I can't figure it out.
You are not using image objects properly. You do not add them to the overlays of an object, you instead supply the object to attach them to in the image() procedure. So, in this case, you would be doing var/image/I = new('someicon.dmi', M, "someiconstate"), then output it with just src << I. Though, you'd probably want to give the mob a variable to hold the image instead of just storing it in local variable I, so you can remove it later (with client.images -= myimage).

Creating a subtype of /image may be causing some issues, as that's not actually intended use.
In response to Garthor
I guess I misunderstood the use of image overlays in references, also didn't realize that an image can attach to an obj by just placing it's loc to an obj. Though I'm wondering, can you change it's loc to another object after it's initialized and still have it attached? I'm still curious as to why mine semi worked in those situations, though I guess it doesn't matter anymore.