...Pretend I didnt just post a coding problem before this one...
I have successfully created a healthbar(Go Me!)
When the mob logs in, a new health bar is created with the variable X. Then src.client.screen += X
But now I would like to make it an overlay of the mob so it moves with him/her.
I have tried the obvious:
src.overlays += X, but the overlay bar is not reacting to the update procs and what not that the on-screen heath bar is responding to.
I spent a lot of time on this and would prefer not to post any coding that it not necessary for this problem to be resolved.
---Thank you for your time!
1
2
ID:147858
Oct 26 2003, 12:49 am
|
|
Oct 26 2003, 1:01 am
|
|
Try removing the overlay before each update, and re-adding it when the bar's update is finished.
|
In response to Crispy
|
|
//here is my update proc
mob/proc/updatebars() src.overlays -= src.hpbar src.hpbar.icon_state = num2text(src.hpbarnum) src.overlays += src.hpbar |
I have bad news for you: What you're trying to do is nigh impossible with an overlay.
You're going to have to stick with something like /image instead, or an obj you move around with your mob. Lummox JR |
In response to Lummox JR
|
|
Only so long as he does not have other overlays that are difficult to keep track of. So long as it is only a few meters for health/magic power, experience or similar things, then it is simple to just empty the overlays (overlays=list()) then re-add the meters when you want them updated. In that case then it is quite simple.
|
In response to Lummox JR
|
|
Lummox JR wrote:
I have bad news for you: What you're trying to do is nigh impossible with an overlay. It was accomplished with great success in Mystic Journey and Seika. |
In response to Xallius
|
|
Xallius wrote:
Lummox JR wrote: Are you sure those were actual overlays? About the only way to do it with an overlay is rather hacky: Delete all overlays and redo them whenever health or mana change. Lummox JR |
In response to Xallius
|
|
Nevermind, I have fixed this.
But now I have a final obstacle to get over: I need one of the bars to be an overlay of the tile above my character at all times. I am using: mob/var/obj/UP for the tile above src and in the proc I am using: src.UP=get_step(src,NORTH) But this is giving me either runtime errors or is constantly making new a new bar everywhere I step Could someone please post a code snippet that would correctly allow me to place an overlay on UP that will move with the mob? |
In response to Xallius
|
|
You certainly can use overlays for a stat-bar, just make sure you remove it in Logout() and recreate in Login() (see http://developer.byond.com/forum/ index.cgi?action=message_read&id=218403&forum=8&view=0#21839 2 for sample code).
To get the one bar in the tile above, just change the pixel_x and pixel_y variables of the stat-bar accordingly. An pixel_y of 32 would put it exactly 1 tile above the mob, 16 would be half, 8 a quarter etc. By changing them you can position it to where you want to. |
In response to Nick231
|
|
Thanks, my health bar and magic bar are finally complete... well... atleast beta =P
|
In response to Xallius
|
|
hmm... a problem arose...
How do I add these overlays to all the npcs in the game? |
In response to Xallius
|
|
Make the health bar update proc common to both players and NPCs, and call it for all mobs (not just players).
|
In response to Crispy
|
|
The procs are all for all the mobs, but how do i make a new hpbar/mpbar for every mob in the world?
|
In response to Xallius
|
|
Loop through all the mobs. Then add it just like you're adding the health bar to the player. I can't be more specific without knowing exactly how you're doing it.
|
In response to Crispy
|
|
I would prefer to post the DM file via AIM rather than to the public-
If you have AIM, please contact me ("spaceshiphamster") |
In response to Xallius
|
|
You don't need to post screens and screens of code. Hey, you don't even need to post code at all (although it'd help); just describe what you're doing in detail.
And don't worry, your code isn't important enough for anyone to care about it. =) To use it, people would need to know how it worked, in which case they could just as easily write it themselves anyway. I do have AIM, but I don't generally give it out. |
In response to Xallius
|
|
If you put everything on the /mob level, you can use Login() and New() (To add the bars initially, Login() for players, New() for the NPC's) and to remove them: Logout() and Del() (Logout() for players and Del() for NPC's) Both pairs should be essentially the same thing, unless there is some PC/NPC specifics in the code.
Just make sure you call the parent for all of them (..()) unless your code requires it not to. You could also loop though all mob's in the world, however this could cause looping though a large number of mobs, and/or some problems if you make new mobs during play (ie. NPC's respawning). |
In response to Crispy
|
|
//This should be all I need to post:
mob/New() ..() var/obj/meter/hpbar/X =new src.HPBAR = X var/obj/meter/mpbar/M =new src.MPBAR = M mob/Stat() ..() src.updatebars() mob/proc/updatebars() src.overlays -= src.HPBAR src.hpbarnum=round(hp/hp_max*100,10) src.HPBAR.icon_state = num2text(src.hpbarnum) src.overlays += src.HPBAR src.overlays -= src.MPBAR src.mpbarnum=round(mp/mp_max*100,10) src.MPBAR.icon_state = num2text(src.mpbarnum) src.overlays += src.MPBAR |
In response to Xallius
|
|
I cant remember who said its impossible with overlays but it is no way near impossible.
I will share mine if you help fix my bug...up the top ^. |
In response to Nick231
|
|
I believe that I used mob/New() so why doesn't it work?
PS: Don't feel like I just don't want to do the work; I have been painfully trying to solve this for weeks before I took it to the forums |
1
2