• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!
  • ✅ The POLL for Hive's Texturing Contest #34 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!
  • ✅ The POLL for Hive's Techtree Contest #20 is OPEN! Vote for the TOP 3 FACTIONS! 🔗Click here to cast your vote!

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.
 
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:
Status
Not open for further replies.
Back
Top