• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Help with Customizing a Vjass system

Status
Not open for further replies.

Sverkerman

Hosted Project: BoW
Level 17
Joined
Feb 28, 2010
Messages
1,325
Hello there!
ProgressBars v2.0.1

I would like to use this system to display mana bars above all units in my map. This system comes with that function, just that it is bundled with a health bar function as well and I have too little knowledge of Vjass to edit it to my needs.

I do not want the health bar function and I do not want to disable any health bars. (To disable the health bars showing for the dummy units displaying the graphics I will simply put their selection to -1.)

Could someone help me edit the code so that only the mana bar function is used?

+4 rep to all helpers :)
 
Level 17
Joined
Mar 21, 2011
Messages
1,597
you dont need to edit the system, you can simply not create a health bar. removing some lines of code in the example should do it. i commented them out in this case.


JASS:
scope HealthBar initializer onInit
  
    private struct unitdata
        //ProgressBar hp
        ProgressBar mp
        unit u
        timer t
    endstruct
  
    native UnitAlive takes unit id returns boolean
  
    private function update takes nothing returns nothing
        local timer t      = GetExpiredTimer()
        local unitdata d   = GetTimerData(t)
        local real life//    = GetUnitState(d.u, UNIT_STATE_LIFE)+0.405
        local real percent
      
        //set percent = (life / GetUnitState(d.u, UNIT_STATE_MAX_LIFE) * 100.0)
          
        if (not UnitAlive(d.u)) then
            call ReleaseTimer(d.t)
            //call d.hp.setPercentage(0, 1)
            call d.mp.setPercentage(0, 1)
            call d.mp.destroy()
            //call d.hp.destroy()
            call d.destroy()
            return
        /*elseif (percent <= 30) then
            set d.hp.color = PLAYER_COLOR_RED
        elseif (percent <= 50) then
            set d.hp.color = PLAYER_COLOR_ORANGE
        elseif (percent <= 60) then
            set d.hp.color = PLAYER_COLOR_YELLOW
        elseif (percent > 60) then
            set d.hp.color = PLAYER_COLOR_GREEN*/
        endif
      
        //call d.hp.setPercentage(percent, 1)
      
        set life = GetUnitState(d.u, UNIT_STATE_MAX_MANA)
      
        if (life > 0) then
            set percent = GetUnitState(d.u, UNIT_STATE_MANA) / life * 100.0
          
            call d.mp.setPercentage(percent, 1)
        endif
      
    endfunction
  
    private function onEnum takes nothing returns boolean
        local unit u       = GetFilterUnit()
        local unitdata d   = unitdata.create()
        //local ProgressBar bar
        local ProgressBar mana
      
        /*set bar            = ProgressBar.createEx('hpbr')
        set bar.xOffset    = -14.5
        set bar.zOffset    = 135
        set bar.size       = .7
        set bar.color      = PLAYER_COLOR_GREEN
        set bar.targetUnit = u
        call bar.setPercentage(100, 1)
      
        set d.hp = bar*/
        set d.t  = NewTimerEx(d)
        set d.u  = u
      
        if ( GetUnitState(d.u, UNIT_STATE_MAX_MANA) > 0 ) then
            set mana            = ProgressBar.createEx('mpbr')
            set mana.xOffset    = -14.5
            set mana.zOffset    = 110
            set mana.size       = .7
            set mana.color      = PLAYER_COLOR_BLUE
            set mana.targetUnit = u
            call mana.setPercentage(100, 1)
            set d.mp = mana
        endif
      
      
        call TimerStart(d.t, 0.25, true, function update)
        set u = null
      
        return false
    endfunction
  
    private function gamestart takes nothing returns nothing
        local group g = CreateGroup()
        call GroupEnumUnitsInRect(g, bj_mapInitialPlayableArea, Filter(function onEnum))
        call DestroyGroup(g)
        set g = null
        call DestroyTimer(GetExpiredTimer())
    endfunction
  
    private function onInit takes nothing returns nothing
        //call EnablePreSelect(false, false) // hides default HP bars
        call TimerStart(CreateTimer(), 0, false, function gamestart)
    endfunction
  
endscope
 

Sverkerman

Hosted Project: BoW
Level 17
Joined
Feb 28, 2010
Messages
1,325
@GIMLI_2 Thanks for the fast reply! I'm currently importing the system into my map and I've copy pasted your code! I still have some demo things going on, a random message with 1-100% keeps appearing in my map, do you know what more lines I need to disable in order to get this to stop? Thanks :)
Fixed.
 
Last edited:

Sverkerman

Hosted Project: BoW
Level 17
Joined
Feb 28, 2010
Messages
1,325
81zLVRu.jpg
I'm having a bug after importing it, do you know what it might be?
The mana isn't full but it is being displayed as full. It is updated when I cast.
Here is a link to the map:
https://www.hiveworkshop.com/attachments/try-to-import-w3x.279369/
 
Last edited:
Level 17
Joined
Mar 21, 2011
Messages
1,597
hmm, that's weird. it seems to be a general problem, as the same bug occurs in the progressBar map. it might be an animation problem from blizzards side, an error in the demo code or an error in the system. .destroy() also does not seem to work. i will take a closer look at the system later on, maybe i can find something
 

Sverkerman

Hosted Project: BoW
Level 17
Joined
Feb 28, 2010
Messages
1,325
@GIMLI_2 Thank you so much for your patience and interest! I am looking for a system to display mana bars above all units with mana, this one seemed to do the trick but perhaps there is a better one? Once again, thank you for looking into the problem and helping me :) Hopefully you can come up with something!
 
Level 17
Joined
Mar 21, 2011
Messages
1,597
there seems to be a problem with the interval where the animation needs to change. It is too fast for the animation to catch up? and then it messes up? i'm not a 100% sure. It works fine for me when increasing the interval, you might try it yourself on which interval it stops working.
JASS:
call TimerStart(d.t, 0.25, true, function update)

-->

call TimerStart(d.t, 1.00, true, function update)
 
Status
Not open for further replies.
Top