Snippet Floating Mana Bar

Sirroelivan

Gunnerkrigg Court
Reaction score
95
Here's a very simple trigger to add a floating mana bar above units. It uses only 4 variables, pg(player group), ug (unit group),p (point array) and mana (integer). To change the color of the mana bar change the color code in the bold part. Hope someone finds a use for it.

Code:
Mana Trigger
    Events
        Time - Every 0.03 seconds of game time
    Conditions
    Actions
        Set ug = (Units in (Playable map area) matching ((((Matching unit) is alive) Equal to True) and ((Max mana of (Matching unit)) Greater than 0.50)))
        Unit Group - Pick every unit in ug and do (Actions)
            Loop - Actions
                Set String = <Empty String>
                Set Mana = (Integer(((Percentage mana of (Picked unit)) / 2.00)))
                For each (Integer A) from 1 to 50, do (Actions)
                    Loop - Actions
                        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            If - Conditions
                                Mana Greater than or equal to (Integer A)
                            Then - Actions
                                Set String = (String + |cff0000FF'|r)
                            Else - Actions
                                Set String = (String + ')
                Set p[1] = (Position of (Picked unit))
                Set p[2] = (p[1] offset by (-75.00, 0.00))
                Floating Text - Create floating text that reads String at p[2] with Z offset 210.00, using font size 10.00, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
                Set pg = (All enemies of (Owner of (Picked unit)))
                Floating Text - Hide (Last created floating text) for pg
                Floating Text - Change (Last created floating text): Disable permanence
                Floating Text - Change the lifespan of (Last created floating text) to 0.06 seconds
                Custom script:   call DestroyGroup(udg_ug)
                Custom script:   call DestroyForce(udg_pg)
                Custom script:   call RemoveLocation(udg_p[1])
                Custom script:   call RemoveLocation(udg_p[2])


screenshot1-1.jpg
 

Attachments

  • Floating Mana Bar.w3x
    13.9 KB · Views: 377

Flare

Stops copies me!
Reaction score
662
Code tags?

And you've got a leak here
Code:
Set p = ((Position of (Picked unit)) offset by (-75.00, 0.00))
There's 2 locations involved there (Position of (Picked Unit) and the resulting offset point) so you need 2 variables (or an arrayed variable, doesn't really matter) to deal with it properly

Still leaking :\
Code:
                Set p[1] = ((Position of (Picked unit))
                Set p[2] = ([B](Position of (Picked unit))[/B] offset by (-75.00,0.00))
Change bolded to p[1]

Code:
                Custom script:   call DestroyGroup(udg_ug)
The group should be destroyed OUTSIDE the Unit Group loop (or else you're destroying it once for every unit in the group, even though it was only created once)

@Exide: It's MUI, but it's not very selective in what it allows :p
 

Exide

I am amazingly focused right now!
Reaction score
448
It's a nice idea.
You should make it MUI, though. And most importantly: Show screenshots! :p
 

Exide

I am amazingly focused right now!
Reaction score
448
Cool. Yea, it looks MUI enough to me. My bad. :p
+rep. :thup:

EDIT:
You should add a bar, above the mana bar, for the HP. =)
 
Reaction score
86
Very nice, looks smooth, MUI, what more could you want?
To change the color all you have to do is change:
Code:
Set String = (String + |cff995500'|r)
Change the color code to whatever you want :p
 

ImmortaL_GoD

New Member
Reaction score
4
Just wondering what this part of the trigger does exactly (such as the " ' "?

Code:
If - Conditions
                                Mana Greater than or equal to (Integer A)
                            Then - Actions
                                Set String = (String + |cff995500'|r)
                            Else - Actions
                                Set String = (String + ')

And also, how would I select the condition to set the variable to 6 specific units exactly (with the is alive and greater than 0.50 conditions as well)?
 

cleeezzz

The Undead Ranger.
Reaction score
268
i believe ' is the bar itself.

so the bar your looking at is really

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

except color coded.
 

Fluffball

Well-Known Member
Reaction score
35
Wow... very nice system... I believe you can change the life of the floating text and the periodic timer, although it's fine just as it is... I will use this in my map, might make it health though and add fading age (So as you walk, will fade behind you) +rep... Thanks
 

Sirroelivan

Gunnerkrigg Court
Reaction score
95
Thx all for the good remarks.

@Undaddy, i'm not sure, but if it overlaps, you can adjust the height of the mana bar by changing the bolded part in this line.

Code:
                Floating Text - Create floating text that reads String at p[2] with [B]Z offset 210.00[/B], using font size 10.00, color (100.00%, 100.00%, 100.00%), and 0.00% transparency

@ Immortal_God, as cleezzz said, the ' makes up the actual bar. In order to make it only visible above some units, just set "ug" to whatever you want. Put the units you want to give a mana bar in another unit group, then just check "all units in playable map area matching mana greater than 0.50 and matching unit is alive equal to true and unit is in <your unitgroup> equal to true.
 

ImmortaL_GoD

New Member
Reaction score
4
Ok, thanks a lot, I wasn't sure quite how to compress the trigger (so you didn't have to set each and every one alive/greater than .50).

Code:
Mages
    Events
        Time - Every 0.03 seconds of game time
    Conditions
    Actions
        Set temp_group = (Units in (Playable map area)((((Matching unit) is A Hero) Equal to True) and ((((Matching unit) is alive) Equal to True) and ((Max life of (Matching unit)) Greater than 0.50))))
        Unit Group - Pick every unit in temp_group and do (Actions)
            Loop - Actions
                Set String = Empty String
                Set Life = (Integer(((Percentage life of (Picked unit)) / 2.00)))
                For each (Integer A) from 1 to 50, do (Actions)
                    Loop - Actions
                        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            If - Conditions
                                Life Greater than or equal to (Integer A)
                            Then - Actions
                                Set String = (String + |cff995500'|r)
                            Else - Actions
                                Set String = (String + ')
                Set p[1] = (Position of (Picked unit))
                Set p[2] = ((Position of (Picked unit)) offset by (-75.00, 0.00))
                Floating Text - Create floating text that reads String at p[2] with Z offset 210.00, using font size 10.00, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
                Floating Text - Change (Last created floating text): Disable permanence
                Floating Text - Change the lifespan of (Last created floating text) to 0.06 seconds
                Custom script: call RemoveLocation (udg_p[1])
                Custom script: call RemoveLocation (udg_p[2])
                Custom script: call DestroyGroup (udg_temp_group)

Lol, all it shows is "String" in white above the unit, and it also changed his color from red --> blue, o_O. Any ideas?
 

ImmortaL_GoD

New Member
Reaction score
4
Yeah, I thought I did that, second I'll recheck.

EDIT: Oh shit, I see where I messed up, haha. I useds String variable for the first two, then for reason not for the third (floating text) one. Thanks.

Which measurement would you adjust to move the bar left a little? Since I need to center it on a mage type,
smaller unit.

Code:
Mages
    Events
        Time - Every 0.03 seconds of game time
    Conditions
    Actions
        [B]Set temp_group = (Units in (Playable map area)(((Unit-type of (Matching unit)) Equal to |c00ff0000Mage) and (((Unit-type of (Matching unit)) Equal to |c00800080Mage) and (((Unit-type of (Matching unit)) Equal to |c00000000Mage) and (((Unit-type of (Matching unit)) Equal to |c
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                (((Matching unit) is alive) Equal to True) and ((Max life of (Matching unit)) Greater than 0.50)
            Then - Actions
                Unit Group - Pick every unit in temp_group and do (Actions)[/B]                    Loop - Actions
                        Set String = Empty String
                        Set Life = (Integer(((Percentage life of (Picked unit)) / 2.00)))
                        For each (Integer A) from 1 to 50, do (Actions)
                            Loop - Actions
                                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                    If - Conditions
                                        Life Greater than or equal to (Integer A)
                                    Then - Actions
                                        Set String = (String + |c00880000'|r)
                                    Else - Actions
                                        Set String = (String + ')
                        Set p[1] = (Position of (Picked unit))
                        Set p[2] = ((Position of (Picked unit)) offset by (-75.00, 0.00))
                        Floating Text - Create floating text that reads String at p[2] with Z offset 210.00, using font size 10.00, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
                        Floating Text - Change (Last created floating text): Disable permanence
                        Floating Text - Change the lifespan of (Last created floating text) to 0.06 seconds
                        Custom script: call RemoveLocation (udg_p[1])
                        Custom script: call RemoveLocation (udg_p[2])
                        Custom script: call DestroyGroup (udg_temp_group)
            Else - Actions
                Do nothing

Was that how you were saying to set up the first part to select specific units? Probably not, but that didn't work anyways, not sure how to select and put that condition on ALL of them. =/
 

Sirroelivan

Gunnerkrigg Court
Reaction score
95
@ immortalGodz, are those mages you want a mana bar to appear above the only mages on the map, if so, just add "unit-type of matching unit equal to mage" only once to the "set unit group" line.

To put it to the left or right, change to x value in "set p[2] is p[1] with offset (-75.00,0.00)
 

vypur85

Hibernate
Reaction score
803
Hmmm... This seems to have been done before but I can't remember :p (similar to Ace's Hatchery Havoc?). Seems interesting and nice. But provide a map so that we don't have to recreate the trigger ourself just to see the effect.

+R
 

Sirroelivan

Gunnerkrigg Court
Reaction score
95
I've added a demo map. I've also changed the code a bit, now it doens't show the mana bar to enemies of the player. In single player this doens't matter, but in multiplayer, you can use the mana bars to determine the position of your enemy under the fog of war.

Edit: I'm trying to convert it to JASS, so you only have to copy the code then.
 

ImmortaL_GoD

New Member
Reaction score
4
@ immortalGodz, are those mages you want a mana bar to appear above the only mages on the map, if so, just add "unit-type of matching unit equal to mage" only once to the "set unit group" line.

To put it to the left or right, change to x value in "set p[2] is p[1] with offset (-75.00,0.00)
Nah, there's 6 different specific mages, I changed it to simply "Unit Comparison", then I tried something else, and forgot to change it back the same way, so sec, trying again.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top