ID:261279
 
How do you make a meter fallow your mob from 1 tile above it.
I was thinking for the creation just have usr.meter = new /obj/meter(locate(usr.x,usr.y+1,usr.z))
But then again wouldnt it just stay in that same spot after it was made. Then I started thinking overlays since overlays fallow the mob around but how could I get it to stay 1 space above the mob?

Green Lime wrote:
How do you make a meter fallow your mob from 1 tile above it.
I was thinking for the creation just have usr.meter = new /obj/meter(locate(usr.x,usr.y+1,usr.z))
But then again wouldnt it just stay in that same spot after it was made. Then I started thinking overlays since overlays fallow the mob around but how could I get it to stay 1 space above the mob?

Just a untested few ideas. Set the meter density to 0 so it can go over anything. Make its layer FLY_LAYER so it always shows up. Then you have to override mob/Move() to make the meter move when the mob does. Something like this:
mob/Move()
. = ..()
src.meter.loc = locate(src.x, src.y+1, src.z)

Of course, there's always that special case when the mob is already at the maximum y on the map. The above code will probably leave the meter where it was when he was last below the maximum y. It's up to you to handle that case however you see fit.
Green Lime wrote:
How do you make a meter fallow your mob from 1 tile above it.
I was thinking for the creation just have usr.meter = new /obj/meter(locate(usr.x,usr.y+1,usr.z))
But then again wouldnt it just stay in that same spot after it was made. Then I started thinking overlays since overlays fallow the mob around but how could I get it to stay 1 space above the mob?


Thanks for asking i wanted to know how to do this too!!! Now BYOND has everything i need except 3-D graphics
In response to Air Mapster
Air Mapster wrote:
Just a untested few ideas. Set the meter density to 0 so it can go over anything. Make its layer FLY_LAYER so it always shows up. Then you have to override mob/Move() to make the meter move when the mob does. Something like this:
mob/Move()
. = ..()
src.meter.loc = locate(src.x, src.y+1, src.z)

Of course, there's always that special case when the mob is already at the maximum y on the map. The above code will probably leave the meter where it was when he was last below the maximum y. It's up to you to handle that case however you see fit.

I believe in that case the locate() proc returns null, which in turn will make the meter disappear. This of course is a problem, because that's probably not the desired behavior; the user will no doubt want to see their meter at all times.

There are three convenient workarounds: 1) Always have a wall or a teleport square at the top of your map, so players can't stand there. 2) Instead of y+1 in the code above, use min(world.maxy,y+1). 3) If you want the meter to appear below the player and not right on top of them (as in workaround #2), use: ((y>=world.maxy)?(world.maxy-1):y).

Lummox JR
Green Lime wrote:
How do you make a meter fallow your mob from 1 tile above it.
I was thinking for the creation just have usr.meter = new /obj/meter(locate(usr.x,usr.y+1,usr.z))
But then again wouldnt it just stay in that same spot after it was made. Then I started thinking overlays since overlays fallow the mob around but how could I get it to stay 1 space above the mob?

In addition to Air Mapster's code in his reply, you'll probably also want to change that obj to an image so only that player can see it. You'll need to download the newest beta to do this, since 306 doesn't support the new image type. Try the following:
mob
...
var/image/meter

// depends on the icons you use
// Spuzzum's meter snippet uses 0 to 30
var/const/NUM_METER_STATES=30

Login()
meter=image('meter.dmi')
src << meter // make the meter visible to this user
... // your other code including ..() here

proc/SetMeter(fraction)
fraction=min(max(fraction,0),1) // limit to 0-1
meter.icon_state="[round(fraction*NUM_METER_STATES,1)]"

Combine this with the Move() modification suggested by Air Mapster, and you should have a working meter that follows you around and only you can see. Then you can alter the meter using code like this:
  proc/Damage(amount)  // called when hit or healed
HP=min(max(HP-amount,0),maxHP)
if(HP<=0)
Die()
return
SetMeter(HP/maxHP)

Also, since I'm prone to overcomplicating answers to simple questions, I'll toss you an idea of how to do code for two meters (on the same tile):
mob
...
var/image/HPmeter
var/image/MPmeter
var/obj/meter_container // has no icon

Login()
meter_container=new
HPmeter=image('HPmeter.dmi',meter_container)
MPmeter=image('MPmeter.dmi',meter_container)
src << HPmeter
src << MPmeter
... // your other code including ..() here

Move(l)
..()
meter_container=locate(x,y+1,z)

proc/SetMeter(meter,fraction) // you have to tell it which meter
fraction=min(max(fraction,0),1) // limit to 0-1
meter.icon_state="[round(fraction*NUM_METER_STATES,1)]"

HPmeter.dmi and MPmeter.dmi should have their meters a little offset so they can both share a tile.

Hope some of this helps you.

Lummox JR