(See the best response by Kaiochao.)
parent_type = /obj
density = 0

New(atom/o, bx, by, bh, bw)
owner = o
loc = o.loc
bound_x = bx
bound_y = by
bound_height = bh
bound_width = bw


if(!istype(owner, /mob))

// I had things here to update the location of the hitbox on a mob, but then i made it so that it moves when the mob moves.

spawn(world.tick_lag) update()

if(ismob(o) && o:client)
o:client.images += owner.self_overlay

if(ismob(o) && o:client)
o:client.images -= owner.self_overlay

var/self_overlay, hitbox/hitbox

self_overlay = image(src.icon, src, src.icon_state, MOB_LAYER + 0.02, src.dir)

Problem description:
Above is the code I'm using to create a pseudo-3D effect in my game. It allows your character to appear over a building when you walk in front of it, and the building to appear over you when you walk behind it.

My problem is making this support multiple players. The way it is now, if you walk behind a building and someone walks in front of the building, you will see the building above them, instead of them being above the building.

I'm trying to brainstorm the best way of solving this issue without creating efficiency problems. The hitbox needs to search through itself and find what hitboxes are above and what are below it, I imagine, and adjust the layering on the images before displaying it to the player. I've been toying with different ways to do this for a while now, and nothing seems to work quite right. Any suggestions?
Best response
I've had a layering solution for this circulating around the forums for a while. Search the forum for "standing layer" (no quotes) and you'll see a few versions of it.

Basically, the object's layer is updated whenever it moves in a way that relates its layer to its absolute y position on the map, so that things more south are higher up in layer. Standing objects stand on the bottom edge of their bounding box.

It's what SIDE_MAP should be, but isn't.
Couldn't have asked for a better solution, it works perfectly. Thanks a ton.