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:
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.
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() == 039;A00D039; ) ) 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("+HP"), GetHandleId(u))
call GroupAddUnit(FirstCast[1], u)
endif
set CurrentHP = AddingHP + CurrentHP
set i3 = CurrentHP
set i = MaxLevel
loop
exitwhen i < 0
set i2 = R2I(Pow(I2R(2), I2R(i)))
if i2 <= CurrentHP then
call UnitAddAbility(u, HPID<i>)
set CurrentHP = (CurrentHP - i2)
endif
set i = i - 1
endloop
call SaveInteger(GlobalHashtable, StringHash("+HP"), 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.