ID:147497
 
I coded in an experience bar, and I made all the icons and such... but heres my problem: I have no idea how to update it.
UpdateExp(mob/M) var/varLeft = new/obj/ExpBar varLeft:icon_state = "Left" varLeft:screen_loc = "11,15" M.client.screen += varLeft var/varExp1 = new/obj/ExpBar varExp1:icon_state = "12" varExp1:screen_loc = "12,15" M.client.screen += varExp1 var/varExp2 = new/obj/ExpBar varExp2:icon_state = "0" varExp2:screen_loc = "13,15" M.client.screen += varExp2 var/varExp3 = new/obj/ExpBar varExp3:icon_state = "0" varExp3:screen_loc = "14,15" M.client.screen += varExp3 var/varRight = new/obj/ExpBar varRight:icon_state = "Right" varRight:screen_loc = "15,15" M.client.screen += varRight

That's what I have so far. I'd like to have it so that it spreads over 3 bars. I only added in the icon_state part so i could view it. If anybody would mind finishing this off for me I'd greatly appreciate it.
mob
proc
UpdateExp()
var/obj/ExpBar/Left=locate("Left") in src.client.screen //this'll locate an obj/ExpBar using the tag "left"
if(!Left)
Left=new
Left.tag="Left"
Left.screen_loc="11,15"
src.client.screen.Add(Left)
var/obj/ExpBar/Middle=locate("Middle_One") in src.client.screen
if(!Middle)
Middle=new
Middle.tag="Middle_One"
Middle.screen_loc="12,15"
src.client.screen.Add(Middle)
var/obj/ExpBar/Middle_Two=locate("Middle_Two") in src.client.screen
if(!Middle_Two)
Middle_Two=new
Middle_Two.tag="Middle_Two"
Middle_Two.screen_loc="13,15"
src.client.screen.Add(Middle_Two)
var/obj/ExpBar/Middle_Three=locate("Middle_Three") in src.client.screen
if(!Middle_Three)
Middle_Three=new
Middle_Three.tag="Middle_Three"
Middle_Three.screen_loc="14,15"
src.client.screen.Add(Middle_Three)
var/obj/ExpBar/Right=locate("Right") in src.client.screen
if(!Right)
Right=new
Right.tag="Right"
Right.screen_loc="15,15"
src.client.screen.Add(Right)


I'm assuming that you'll know what to do from there, if you don't, come back and explain what doesn't work and, I'll help you some more.
In response to Goku72
what i actually mean is is show how much Exp i need to get to ExpToNext. progress bar, ya know. shoulda made that more clear sorry...
In response to InsayneWrapper
InsayneWrapper wrote:
what i actually mean is is show how much Exp i need to get to ExpToNext. progress bar, ya know. shoulda made that more clear sorry...

Well, that's easy. But, of course - to make it easy as possible, you'll have to make different icon files for each part of the exp bar, each containing the same amount of icon states, with the same names. Then, just get the percentage of the exp needed and change the icon state.

Example (assuming you have 10 icon states for each bar):

var/Exp_Needed=min(max(round(src.exp/src.maxexp,1)*10,0),10)
Left.icon_state=num2text(Exp_Needed)
In response to Goku72
ok that does one of them, how do I get it to strentch over all 3. btw i have 32 states for each icon
In response to InsayneWrapper
I use a 5 tile stat bar in one of the many projects I never work on. While I only use 9 icon_states per tile, and 5 tiles for the bar, this system should be easily modifiable for a 32 icon state 3 tile bar. My system works best when the MaxDP is a multiple of 8.
            update_dp_disp(var/init)
if(init)
DP_MeterL = new(usr.client)
DP_MeterCL = new(usr.client)
DP_MeterC = new(usr.client)
DP_MeterCR = new(usr.client)
DP_MeterR = new(usr.client)

if(DP == MaxDP)
DP_MeterL.icon_state = "boss_DPL_8"
DP_MeterCL.icon_state = "boss_DPC_8"
DP_MeterC.icon_state = "boss_DPC_8"
DP_MeterCR.icon_state = "boss_DPC_8"
DP_MeterR.icon_state = "boss_DPR_8"

if(!DP)
DP_MeterL.icon_state = "boss_DPL_0"
DP_MeterCL.icon_state = "boss_DPC_0"
DP_MeterC.icon_state = "boss_DPC_0"
DP_MeterCR.icon_state = "boss_DPC_0"
DP_MeterR.icon_state = "boss_DPR_0"

if((DP < MaxDP) && (DP >= MaxDP/5*4))
var/state = round((DP-MaxDP/5*4)/(MaxDP/36))
DP_MeterL.icon_state = "boss_DPL_[state]"
DP_MeterCL.icon_state = "boss_DPC_8"
DP_MeterC.icon_state = "boss_DPC_8"
DP_MeterCR.icon_state = "boss_DPC_8"
DP_MeterR.icon_state = "boss_DPR_8"

if((DP < MaxDP/5*4) && (DP >= MaxDP/5*3))
DP_MeterL.icon_state = "boss_DPL_0"
var/state = round((DP-MaxDP/5*3)/(MaxDP/36))
DP_MeterCL.icon_state = "boss_DPC_[state]"
DP_MeterC.icon_state = "boss_DPC_8"
DP_MeterCR.icon_state = "boss_DPC_8"
DP_MeterR.icon_state = "boss_DPR_8"

if((DP < MaxDP/5*3) && (DP >= MaxDP/5*2))
DP_MeterL.icon_state = "boss_DPL_0"
DP_MeterCL.icon_state = "boss_DPC_0"
var/state = round((DP-MaxDP/5*2)/(MaxDP/36))
DP_MeterC.icon_state = "boss_DPC_[state]"
DP_MeterCR.icon_state = "boss_DPC_8"
DP_MeterR.icon_state = "boss_DPR_8"

if((DP < MaxDP/5*2) && (DP >= MaxDP/5*1))
DP_MeterL.icon_state = "boss_DPL_0"
DP_MeterCL.icon_state = "boss_DPC_0"
DP_MeterC.icon_state = "boss_DPC_0"
var/state = round((DP-MaxDP/5*1)/(MaxDP/36))
DP_MeterCR.icon_state = "boss_DPC_[state]"
DP_MeterR.icon_state = "boss_DPR_8"

if(DP < MaxDP/5)
DP_MeterL.icon_state = "boss_DPL_0"
DP_MeterCL.icon_state = "boss_DPC_0"
DP_MeterC.icon_state = "boss_DPC_0"
DP_MeterCR.icon_state = "boss_DPC_0"
var/state = round(DP/(MaxDP/36))
DP_MeterR.icon_state = "boss_DPR_[state]"
~X
In response to Xooxer
Hmmm, it doesn't even need to be that complicated... Here's how DBTC does it:

HPmeter
layer = MOB_LAYER + 11
icon_state = "HP16"
var/min
var/max
proc
HPMeterAdjust(mob/M)
var/HPDrop = 40-round((M.HPSet()-M.HP)/(round(M.HPSet()/40,1)),1)
if (HPDrop >= min)
if (HPDrop >= max)
icon_state = "HP16"
else
icon_state = "HP[HPDrop-min]"
else
icon_state = "HP0"
a
screen_loc = "SOUTH,4"
min = 0
max = 8
b
screen_loc = "SOUTH,5"
min = 8
max = 16
c
screen_loc = "SOUTH,6"
min = 16
max = 24
d
screen_loc = "SOUTH,7"
min = 24
max = 32
e
screen_loc = "SOUTH,8"
min = 32
max = 40


That spreads the meter over 5 tiles, with 8 states each, for a total of 40 "notches"...

Here's how it works:

The HPMeterAdjust() proc is called whenever the player's HP is changed, obviously...

The HPDrop var delcared and used in that proc is what calculates what ratio (in 40th's) of their HP is remaining... (HPSet() is a proc that returns their max HP)...

Once that number is found, each meter section checks to see if that value is within its measurement limits (assigned by "min" and "max" vars... not to be confused with min() and max() procs)... If the value is below the tiles min value, then the tile will be empty, and its icon_State is set to such ("HP0")... If the value is higher than its max, then the tile will be completely full ("HP16")... If the value is somewhere in the middle, then that tile will only be partially full, and it uses the HPdrop value to see just how full it should be ("HPdrop-min" which says how much over the tile's min limit it should be displaying), and this is used in assigning the proper partially full icon_state...

The proc is called for all 5 tiles:

EX:
for(var/obj/HUD/HPMeter/HP in client.screen)
HP.HPMeterAdjust(src)

This could be easily adjusted for any number of tiles, and for any number of "notches" total in the meter... I'll leave those numbers to you guys to figure out...
In response to SuperSaiyanGokuX
Hrm, the only real benefit I can see to your aproach (which you don't seem to be taking advantage of) is being able to not call an update on a piece of the stat bar if it does not change. Seeing as how more often a change will span two tiles, this can reduce a bit of the overhead. As my system is only for a single-player game, and only 3 of these bars are in use at any given time, the overhead is nothing to worry about. In a large MMOG, though, where everyone has one or two of these such bars, your approach is much more suited to keeping the lag down.

~X