• 🏆 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!

UI hero icons bars

Status
Not open for further replies.
Level 12
Joined
Jan 30, 2020
Messages
875
Well no need for hackery stuff, you just need to access the related origin frames.

It's better to hide them with setting the alpha to 0:
Lua:
    local fh=BlzGetOriginFrame(ORIGIN_FRAME_HERO_HP_BAR, 0)
    BlzFrameSetAlpha(fh, 0)
    fh=BlzGetOriginFrame(ORIGIN_FRAME_HERO_MANA_BAR, 0)
    BlzFrameSetAlpha(fh, 0)

If you're a GUI user, you could probably use custom script lines.
I have no idea if these natives have been added to GUI and I don't have WE at hand right now.
And unless you already use Jass stuff already, I'd advise to change the scripting language of your map to Lua.

EDIT :
Note that this example was for the first hero icon, to access the other ones you need to change the context like this for example : BlzGetOriginFrame(ORIGIN_FRAME_HERO_HP_BAR, 1)
 
Level 9
Joined
Apr 18, 2012
Messages
90
Maybe you can instead use a dummy hero icon with a fake health and mana value.
That's exactly what I'm aiming for. It will essentially serve a purpose of an on-screen button. Hero will get deselected and removed right after selecting. I just need to get rid of these bars because it's distracting and even if hero has near no health, the bar is full black.

I don't think I use any jass, Macadamia. Could you hand me a link to good tutorial how to set up Lua into map? Kind of a newbee on that stuff.
 
Level 12
Joined
Jan 30, 2020
Messages
875
I don't think I use any jass, Macadamia. Could you hand me a link to good tutorial how to set up Lua into map? Kind of a newbee on that stuff.

Well there's no real tutorial. But Lua has a reference manual, and note that, if you use Reforged, it uses Lua version 5.3 IIRC.
Now before being able to use Lua in a map, you could probably start easy :

Create a GUI trigger with Map Initialization as event, then a custom script line that could start a Lua function, name it as you please, call it GameStart or whatever.

Just to give you an example of how things can be made, let's say we'd start the map with creating a Paladin for Player 1, that is Player(0) for the game, at the player's start location, then give him some experience. Then start a 5 seconds timer that will start the next function that will create a trigger that displays the text "Hello Lua World" when the paladin casts Divine Shield.

  • Lua test
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Custom script: GameStart()

Now in a right-click -> New Custom Script entry, add :


Lua:
function FirstTrigger()
    local message="Hello Lua World"
    local hello=CreateTrigger()
    TriggerRegisterUnitEvent(hello, Hero, EVENT_UNIT_SPELL_EFFECT)
    TriggerAddCondition(hello, Condition(function()
        if (GetSpellAbilityId()==FourCC("AHds")) then
            return true
        else
            return false
        end
    end))
    TriggerAddAction(hello, function()
        print(message)
    end)
end

function GameStart()
    Hero=CreateUnit(Player(0), FourCC("Hpal"), GetStartLocationX(0), GetStartLocationY(0), 270.0)
    SetHeroXP(Hero, 1000, false)
    TimerStart(CreateTimer(), 5.0, false, FirstTrigger)
end

Note "Hero" is a global variable because it is not declared "local". A local variable is a variable that only exists in the current "scope" or context if you prefer.
Also note that the Raw codes for units or abilities have to be converted to an integer in Lua, thus we use the "FourCC" native function for that.
You also noticed we call a function by its name with no brackets in the TimerStart.
But to add a condition and an action to the trigger "hello", we define the function directly with no name. It is called an anonymous function, and the advantage is huge : you can use the local variables defined in the "mother" function in it. Like the string "Hello Lua World" in this case.

If you are not familiar with scripting, you will desperately need to grab the common.j file from the game - actually I have attached it to this message for you - because it contains all the native functions that Warcraft III adds to Lua to help you make Lua triggers and do things game-related.

I could also attach the blizzard.j file but I would strongly advise you to stay away from these as they're just extra functions blizzard made with the common.j natives to help making GUI, and it can't do anything that you couldn't do yourself.

Now for the rest, here is the link to the Lua manual : Lua 5.3 Reference Manual

Not really a full tutorial, but I hope this will help you taking a good start.

Never forget that it is really worth learning Lua, because it is so powerful (much more than Jass for example), and once you will master it, your only limit will be the game limits itself.

Also Lua is a very commonly used language, so all what you will learn can be used in the future for other things.

Good Luck !!!

EDIT : fixed a small mistake and attached the corresponding map.
 

Attachments

  • common.j
    351.3 KB · Views: 44
  • FirstLuaMap.w3x
    22.4 KB · Views: 39
Last edited:
Level 12
Joined
Jan 30, 2020
Messages
875
This is not instructions on using vJass (aka decorated Jass), just helping people who want to learn a more efficient, potent and useful scripting language.

To be honest, there is a plethora of reasons one should choose Lua over vJass, or even real typed languages, if this last part did not require the users to stay away from Word Editor.

It would be nice if Jass returned to its cave.

As far as I am concerned, I had to endure its flaws for much too long already.

In other words, helping people to start using a modern scripting language when they are only used to GUI is a positive action.

Avoid them having to go through the entire Jass-hassle is a benevolent action :)

EDIT : typos
 
Level 9
Joined
Apr 18, 2012
Messages
90
Is there something I have to do first before I can start using lua script? I copy pasted your code, done everything just like it is on your temp map but I'm stopped by map triggers getting validated. I noticed your map broke the validation and completely skips it.
 
Level 12
Joined
Jan 30, 2020
Messages
875
Yes in map options, you need to set the scripting language to Lua :

Lua.png


But you must do this before adding your custom script code.

World Editor only accepts changing the map script when there are only GUI triggers or no triggers at all.

Note that Lua is very powerful, but there is a price to pay :
You need to be very careful with your variables, because for Lua variables have no type, only values do.
So it is very easy to end up with nightmares if you make typos or are not careful enough.

I suppose this is the price to pay for a potent language.

I suppose when you will be more comfortable you could move to other potent languages that are strongly typed just like TypeScript, but this requires external tools and using WE only for terrain and objects. It also requires working in folder mode in World Editor.
 
Last edited:
Level 12
Joined
Jan 30, 2020
Messages
875
The same as with Jass, except un Lua you don't call a function with "call functionname()" but just "functionname()"

The good thing is in Lua you only need to destroy the agents (units, sfx, sounds, destructables, etc...) but you don't need to null them.
By the way "null" in Lua is "nil".
 
Level 1
Joined
Apr 8, 2020
Messages
110
You should stop using GUI, because it is shitty and productivity is poor
Just to give a preview of what's coming next, I've been searching around for other Damage libraries to write compatibility scripts for and - while I've been mostly successfuly - there are a few features that don't work.

1) I will be adding a Damage.enabled "variable" which will actually disable both damage event triggers when set to True and re-enable them when set to False. This will not interrupt the ongoing damage but will ensure the subsequent damage is ignored.

2) I will be adding an ability to un-register triggers (for whoever thinks that's a good idea)

3) I will be adding some more syntax sugar so you don't have to use Damage.index.source/target/amount and can just use Damage.source/target/amount if you want.

And one final mention, I've noticed an interesting feature that's gaining a bit of popularity, and that is to have embedded conditions into the damage library and have branching events off of those. Now this would normally be incredibly difficult to pull off in GUI with so many different events already in the system (DamageModifierEvent, DamageEvent, etc.) so what will I do? Make this a vJass-specific feature...

JUST KIDDING!

I love GUI and would never abandon it! Thanks to the magic of how DamageEngine hooks the GUI events, I bring to you this:

JASS:
EQUAL                 // Any damage type permitted (no change to your code needed, it will work as it always has)
NOT_EQUAL             // Same as including IsDamageCode   Equal to True
GREATER_THAN          // Same as including IsDamageSpell  Equal to True
LESS_THAN             // Same as including IsDamageAttack Equal to True
GREATER_THAN_OR_EQUAL // Same as including IsDamageRanged Equal to True
LESS_THAN_OR_EQUAL    // Same as including IsDamageMelee  Equal to True

This will provide syntax like:

  • Spell Damage Detector
    • Events
      • Game - DamageModifierEvent becomes Greater than 1
    • Conditions
      • -------- No conditions needed if IsDamageSpell was your only condition --------
    • Actions
  • Melee Damage Detector
    • Events
      • Game - DamageEvent becomes Less than or Equal to 1
    • Conditions
      • -------- No conditions needed if IsDamageMelee was your only condition --------
    • Actions
See you guys in the near future with Damage Engine 5.7.0.0 !
 
Level 12
Joined
Jan 30, 2020
Messages
875
And yet he uses vJass ... lol

Seriously : there is nothing wrong with using GUI, and 99% of all modders started with it.

The problem is, as soon as you want to start making real advanced things, GUI quickly starts becoming to show serious limitations.
And I am not even mentioning the necessity to add custom script lines to prevent leaks.

If you work seriously on a project and want to give it advanced features, and not end up with a messy code, GUI simply can't give you that :
It's like trying to manufacture a microchip with some barb wire and a lighter.

I just looked at a full GUI TD map, and in spite of the fact that the triggers were much more tidy than what we often see with GUI, it has about 5x more code than mine with about 5x less functionalities.

It doesn't mean the maker has less talent than me, it just means that he/she is crippled by the limitations of GUI.

This said, I never forget that without GUI, the modders community would be quite ridiculously small !!
 
Level 9
Joined
Apr 18, 2012
Messages
90
I have managed to convert my map into lua. Everything does seem to work as intented including the code to get rid of hero bars. However one thing is broke. Custom script that I've been using to remove locust abiity now breaks the game.

Custom script: UnitRemoveAbilityBJ( 'Aloc', udg_Unit )

Is there a some other script to remove it?
 
Level 12
Joined
Jan 30, 2020
Messages
875
First advice : check all BJ functions in your code, then look for them in Blizzard.j and replace them with your own, it will make your life easier when trying to find out issues.

As for UnitRemoveAbilityBJ it is just a wrapper for the native :
JASS:
function UnitRemoveAbilityBJ takes integer abilityId, unit whichUnit returns boolean
    return UnitRemoveAbility(whichUnit, abilityId)
endfunction

this said, it seems you are trying to use ability codes directly. It is not a problem in Jass as it considers some strings as integers, but lua needs you to explicitely convert all object ids this way :

FourCC("objectid")

So replace your custom script line with :

  • Custom script: UnitRemoveAbility( udg_Unit , FourCC("'Aloc"))
You should do that in every line of custom script that uses an object id

EDIT :
You could probably start exporting your map script into a .lua file to look at how the game translates your GUI triggers into Lua, n order to be able to take control, following the example map I gave you.
Doing so, you won't ever need to use "custom script" in front of all the lines of custom script you are using within your GUI triggers.

Don't rush, do this when you have time, and the more you will do this, the more you will be able to optimize your code and make it performant, leak free and much smaller.
 
Last edited:
Level 9
Joined
Apr 18, 2012
Messages
90
Thanks for all the help and effort you put into replies <3

Probably not gonna straight up jump into learning what's what but at least now I've got a clue where to look at when it comes to lua.

Even though creating a completely new ability that would be part of player's UI would be even better, having hero icon will do just fine.

Also you made small typos in the custom script. Should have been UnitRemoveAbility( udg_Unit , FourCC('Aloc')) . Took me couple moments to realize why it's not behaving :D
 
Level 12
Joined
Jan 30, 2020
Messages
875
Yes, I am happy to help.

You should do as you say, never is any need to rush, learn within your comfort zone or when you feel using Lua could help you solve tricky triggers.

The good think is now you have real options :)
 
Status
Not open for further replies.
Top