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: 378

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.
  • WildTurkey WildTurkey:
    is there a stephen green in the house?
    +1
  • The Helper The Helper:
    What is up WildTurkey?
  • The Helper The Helper:
    Looks like Google fixed whatever mistake that made the recipes on the site go crazy and we are no longer trending towards a recipe site lol - I don't care though because it motivated me to spend alot of time on the site improving it and at least now the content people are looking at is not stupid and embarrassing like it was when I first got back into this like 5 years ago.
  • The Helper The Helper:
    Plus - I have a pretty bad ass recipe collection now! That section of the site is 10 thousand times better than it was before
  • The Helper The Helper:
    We now have a web designer at my job. A legit talented professional! I am going to get him to redesign the site theme. It is time.
  • Varine Varine:
    I got one more day of community service and then I'm free from this nonsense! I polished a cop car today for a funeral or something I guess
  • Varine Varine:
    They also were digging threw old shit at the sheriff's office and I tried to get them to give me the old electronic stuff, but they said no. They can't give it to people because they might use it to impersonate a cop or break into their network or some shit? idk but it was a shame to see them take a whole bunch of radios and shit to get shredded and landfilled
  • The Helper The Helper:
    whatever at least you are free
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top