How to heal the unit triggering an ability in Jass

Status
Not open for further replies.
Level 2
Joined
Apr 28, 2023
Messages
3
The ability I am trying to make is when I use a particular ability, it would instantly heal. I was wondering how to heal the triggering unit just when it triggers an ability in Jass. I am a complete newbie at Jass so forgive me if this question is kind of obvious to do already.
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
Well, if you know how to do it in GUI then you technically know how to do it in Jass. There's an option in the Trigger Editor called Convert to Custom Text which will turn your GUI trigger into it's Jass code form. Note that the code given to you this way is usually formatted poorly and uses poor methods which you don't want to make a habit of using. It does however show you the proper function names for certain things and can be of great assistance while you're learning.

Ideally, you'll be writing your code outside of the Trigger Editor and instead use something like Visual Studio Code with a vJass plugin.

Here's code that should fully heal a unit whenever it starts the effect of an ability:
vJASS:
library Example initializer ExampleInit

    globals
        // Put your global variables here, if any
    endglobals

    function ExampleOnCast takes nothing returns nothing
        // This function runs whenever a unit starts the effect of an ability (see ExampleInit)
        local unit u = GetTriggerUnit()
        call SetWidgetLife(u, 999999)
        set u = null
    endfunction

    function ExampleInit takes nothing returns nothing
        // This function runs automatically thanks to the library initializer
        local trigger t = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
        call TriggerAddAction(t, function ExampleOnCast)
        set t = null
    endfunction

endlibrary
I'm using a library which is useful for granting more control over your code. In this case I'm using it automatically run the function ExampleInit.
 
Last edited:
Level 2
Joined
Apr 28, 2023
Messages
3
@Uncle Thank you so much! You also said about using Visual Studio with the vJass plugin. Currently, I am using Jasscraft so would you say that Visual Studio is better to program in Jass than Jasscraft?
 
Status
Not open for further replies.
Top