Warcraft III resources & community, 2003–2006 · archived

Increasing a unit's max hp

16 posts
#1

Increasing a unit's max hp

I was trying to make a spell that increases the target's max hp by 30/60/90/120/150 for 30 seconds, and increases hit point regeneration too by a little. So I based my hero spell off inner fire at first, thinking there would be a trigger to increase max hp. Sadly I couldn't find it, so I switched to making a spell based of the Manual of Health, but the problem is I couldn't figure out how to let a dummy unit cast that spell :S . So after all I switched the Manual of health to a hero spell, and let the dummy unit cast inner fire, but when I learn a new level of Manual of Health, it doesn't show up in my hero skill bar, and now I'm pretty stuck with how to fix it :oops: . So if anyone could explain me how to increase a unit's max hp with triggers or make the Manual of health spell actually work it would be much appreciated...
#2
Depents. Can the effect stack, or not?
#3
Well my initial thought was that it should, but if thats not possible I don't really mind.
#4
Here is a fully stackable one, made by Blade.dk
#5
Well that gave me a kick in the right direction, but I'm still with a problem:

I only want to increase the HP for 30 seconds, and it has to be multiinstancable, so I couldn't use normal triggers. I tried doing it in custom text with locals, but it gave an error. I copy'd it into JassCraft, and that said:

Undeclared funcion SetUnitMaxState

Well I'm a complete moron when it comes to JASS and stuff, so I'm really really bad with it. I basicly just converted parts and made them match my locals.

function Trig_White_MageHealthShield_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A02O' ) ) then
        return false
    endif
    return true
endfunction

function Trig_White_MageHealthShield_Actions takes nothing returns nothing
    local unit Targ
    local unit Cast
    local real PercHP
    local real OldHP
    local real NewHP
    set Targ = GetSpellTargetUnit()
    set Cast = GetSpellAbilityUnit()
    set PercHP = GetUnitLifePercent(Targ)
    set OldHP = GetUnitStateSwap(UNIT_STATE_MAX_LIFE, Targ)
    set NewHP = GetUnitStateSwap(UNIT_STATE_MAX_LIFE, Targ) + ( 30 * I2R(GetUnitAbilityLevelSwapped('A02O', Cast )) )
    call SetUnitMaxState(Targ, UNIT_STATE_MAX_LIFE, NewHP)
    call SetUnitLifePercentBJ( Targ, PercHP )
    call TriggerSleepAction( 30.00 )   
    set PercHP = GetUnitLifePercent(Targ)
    call SetUnitMaxState(Targ, UNIT_STATE_MAX_LIFE, OldHP) 
    call SetUnitLifePercentBJ( Targ, PercHP )
    set Targ = null
    set PercHP = 0.00
    set OldHP = 0.00
    set NewHP = 0.00
endfunction

//===========================================================================
function InitTrig_White_MageHealthShield takes nothing returns nothing
    set gg_trg_White_MageHealthShield = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_White_MageHealthShield, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_White_MageHealthShield, Condition( function Trig_White_MageHealthShield_Conditions ) )
    call TriggerAddAction( gg_trg_White_MageHealthShield, function Trig_White_MageHealthShield_Actions )
endfunction


I know its probably horrible and stuff.. But I just want it to work, so if anyone could help me it would be much appreciated =].
#6
function Trig_White_MageHealthShield_Conditions takes nothing returns boolean 
    return GetSpellAbilityId() == 'A02O'
endfunction 

function Trig_White_MageHealthShield_Actions takes nothing returns nothing 
    local unit Targ = GetSpellTargetUnit()
    local unit Cast = GetSpellAbilityUnit()
    local real PercHP = GetUnitLifePercent(Targ)
    local real OldHP = GetUnitState(Targ, UNIT_STATE_MAX_LIFE)
    local real NewHP = GetUnitState(Targ, UNIT_STATE_MAX_LIFE) + 30 * GetUnitAbilityLevel(Cast, 'A02O')
    set Cast = null
    call SetUnitMaxState(Targ, UNIT_STATE_MAX_LIFE, NewHP) 
    call SetUnitLifePercentBJ( Targ, PercHP ) 
    call TriggerSleepAction( 30.00 )    
    set PercHP = GetUnitLifePercent(Targ) 
    call SetUnitMaxState(Targ, UNIT_STATE_MAX_LIFE, OldHP) 
    call SetUnitLifePercentBJ( Targ, PercHP ) 
    set Targ = null
endfunction 

//=========================================================================== 
function InitTrig_White_MageHealthShield takes nothing returns nothing 
    set gg_trg_White_MageHealthShield = CreateTrigger(  ) 
    call TriggerRegisterAnyUnitEventBJ( gg_trg_White_MageHealthShield, EVENT_PLAYER_UNIT_SPELL_EFFECT ) 
    call TriggerAddCondition( gg_trg_White_MageHealthShield, Condition( function Trig_White_MageHealthShield_Conditions ) ) 
    call TriggerAddAction( gg_trg_White_MageHealthShield, function Trig_White_MageHealthShield_Actions ) 
endfunction


I haven't tested it, but it is supposed to work...
But you'd better change those SetUnitLifePercentBJ-s to SetUnitState-s (needs a little calculation).
Be sure to copy Blade.dk's code into your map's custom script section!!

edit: sry for that long post... :D
#7
are you sure that you copied the SetUnitMaxState function ( and all its child funcs ) to your map's script section?
#8
what the hell is this???? it's not me...
#9
PurplePootare you sure that you copied the SetUnitMaxState function ( and all its child funcs ) to your map's script section?


I had no clue about that o-o, I'm a bit new to all this so I don't know how to import scripts (only found the export button =S)
#10
in the trigger editor, click on the map's name, and on the right you will have a space that looks just like the space for text in a JASS trigger.

paste the script there :D

and pask, idk what that is, try editing your post and seeing what happened. Thats most likely a dumb bug in the site's script :?
#11
Ok I'm really lost now.. I pasted the script in the map now, but when I try to save it it gives the error

Invalid arguement type (real)

and points out the error in the 2 similar lines

    call SetUnitLifePercentBJ( Targ, PercHP )


Even with paskovich's script it gives the same error, even if I remove the 2 lines and the local it gives the same error, but then about the line TriggerSleepAction :S . Whats going on?
#12
Sometimes (i dunno why), it marks the wrong line to be uncorrect. Here,
call SetUnitMaxState(Targ, UNIT_STATE_MAX_LIFE, NewHP)
is wrong, because you must give an integer (instead of real) to life. NewHP is a real you must convert it into an integer. So correct them like this:
call SetUnitMaxState(Targ, UNIT_STATE_MAX_LIFE, R2I(NewHP))

-->R2I converts reals to integers. That's what you need.

And again, sry for the long post, i forgot to put a '/' into the [_jass]... :D
#13
wow... thats a MASSIVE site bug :D... it should go brserk just cuz you missed a / in the jass tag :roll:
#14
HURRAY! The script finally works, to bad the spell doesn't :lol: for some reason the spell doesnt add the hit points, nor removes them. I have checked the rawcode of the spell already and that is right so.. I don't know what is wrong with it anymore :oops: .

Current code is like this:

function Trig_White_MageHealthShield_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A02O'
endfunction


function Trig_White_MageHealthShield_Actions takes nothing returns nothing
    local unit Targ = GetSpellTargetUnit()
    local unit Cast = GetSpellAbilityUnit()
    local real PercHP = GetUnitLifePercent(Targ)
    local real OldHP = GetUnitState(Targ, UNIT_STATE_MAX_LIFE)
    local real NewHP = GetUnitState(Targ, UNIT_STATE_MAX_LIFE) + 30 * GetUnitAbilityLevel(Cast, 'A02O')
    set Cast = null
    call SetUnitMaxState(Targ, UNIT_STATE_MAX_LIFE, R2I(NewHP))
    call SetUnitLifePercentBJ( Targ, PercHP )
    call TriggerSleepAction( 30.00 )
    set PercHP = GetUnitLifePercent(Targ)
    call SetUnitMaxState(Targ, UNIT_STATE_MAX_LIFE, R2I(OldHP))
    call SetUnitLifePercentBJ( Targ, PercHP )
    set Targ = null
endfunction


//===========================================================================
function InitTrig_White_MageHealthShield takes nothing returns nothing
    set gg_trg_White_MageHealthShield = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_White_MageHealthShield, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_White_MageHealthShield, Condition( function Trig_White_MageHealthShield_Conditions ) )
    call TriggerAddAction( gg_trg_White_MageHealthShield, function Trig_White_MageHealthShield_Actions )
endfunction
#15
be sure to follow Blade.dk's instructions. your problem could be that:
-you don't have the custom abilities (HP, and mana gain)
-you didn't set their raw codes in the script (!!)