Adding Maximum HP

jhnam95

Active Member
Reaction score
12
I'm trying to figure out a way to add maximum HP to a unit. I'm using the +Maximum HP spells that are based on items that give bonus hp. Since those abilities can only have 1 level, I used binaries to add the specific amount. For some reason, the trigger won't add the amount I tell it to.

I just made a simple ability on warstomp to test it out. It's supposed to give 250 HP. Unfortunately, it doesn't give any.

MaxLevel is just however many base abilities I made. I made 13 because I got lazy, but with 13, up to 8095 HP can be added...

HPID are just the list of the abilities. HPID[1] is +1 HP, HPID[2] is +2, HPID[3] is +4 and so on.

Here's the code:

JASS:
function Trig_Add_HP_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A00D' ) ) then
        return false
    endif
    return true
endfunction

function Trig_Add_HP_Actions takes nothing returns nothing
    local integer i = 1
    local integer i2
    local integer i3
    local integer CurrentHP
    local unit u = GetTriggerUnit()
    local integer AddingHP = 250
    loop
        exitwhen i > MaxLevel
        if GetUnitAbilityLevel(u, HPID<i>) == 1 then
            call UnitRemoveAbility(u, HPID<i>)
        endif
        set i = i + 1
    endloop
    if (IsUnitInGroup(u, FirstCast[1]) == false) then
        set CurrentHP = 0
    else
        set CurrentHP = LoadInteger(GlobalHashtable, StringHash(&quot;+HP&quot;), GetHandleId(u))
        call GroupAddUnit(FirstCast[1], u)
    endif
    set CurrentHP = AddingHP + CurrentHP
    set i3 = CurrentHP
    set i = MaxLevel
    loop
        exitwhen i &lt; 0
        set i2 = R2I(Pow(I2R(2), I2R(i)))
        if i2 &lt;= CurrentHP then
            call UnitAddAbility(u, HPID<i>)
            set CurrentHP = (CurrentHP - i2)
        endif
        set i = i - 1
    endloop
    call SaveInteger(GlobalHashtable, StringHash(&quot;+HP&quot;), GetHandleId(u), i3)
    set u = null
endfunction

//===========================================================================
function InitTrig_Add_HP takes nothing returns nothing
    set gg_trg_Add_HP = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Add_HP, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Add_HP, Condition( function Trig_Add_HP_Conditions ) )
    call TriggerAddAction( gg_trg_Add_HP, function Trig_Add_HP_Actions )
endfunction

</i></i></i>


I'm really not good at JASS, so if the solution requires some sophisticated JASS or vJASS, I'd appreciate it if you clarified the various functions and steps.
 

Igor_Z

You can change this now in User CP.
Reaction score
61
I can give you a GUI version on how to passively increase your maximum hp.
The spell gives you 1/2/3/4 Hp for each unit killed and 5/10/15/20 for each hero killed. The spell was originally made by Tom_Kazansky. I'm not taking any credit for this spell. He just helped me so now I would like to help you. Do you want it?
 

Igor_Z

You can change this now in User CP.
Reaction score
61
Hmm for some strange reason the spell isn't working very well. Wait give me a minute. I think I can fix it up. Sorry for the technical difficulties ;)

Edit: Seems like the spell works only if the hero is on full health. You can get the general idea though. I will upload the map below.
 

Attachments

  • [Spell] Vampiric Touch.w3x
    19.6 KB · Views: 176

jhnam95

Active Member
Reaction score
12
So theoretically, if I wanted to add 500 HP, I'd just have to run the loop 500 times, assuming each loop gave 1 bonus HP?

I'm still curious on why my +HP system didn't work.
 

jhnam95

Active Member
Reaction score
12
Yes I already got my question answered via the alternative method. My question now is: why didn't my previous trigger work?
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      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