• 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.

Increasing a unit's max hp

Status
Not open for further replies.
Level 2
Joined
Apr 20, 2006
Messages
22
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...
 
Level 2
Joined
Apr 20, 2006
Messages
22
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.

JASS:
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 =].
 
Level 11
Joined
Jul 12, 2005
Messages
764
JASS:
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
 
Level 2
Joined
Apr 20, 2006
Messages
22
PurplePoot said:
are 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)
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
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 :?
 
Level 2
Joined
Apr 20, 2006
Messages
22
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
JASS:
    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?
 
Level 11
Joined
Jul 12, 2005
Messages
764
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:
JASS:
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
 
Level 2
Joined
Apr 20, 2006
Messages
22
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:

JASS:
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
 
Level 2
Joined
Apr 20, 2006
Messages
22
Aaah yes those rawcodes! Completely forgot about them :oops: . Thanks a lot! It really works now, just not perfectly, it doesn't stack yet because it keeps setting the hp back to the real local I saved, so I changed it to this now:

JASS:
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 NewHP = GetUnitState(Targ, UNIT_STATE_MAX_LIFE) + 30 * GetUnitAbilityLevel(Cast, 'A02O')
    local real HPdif = NewHP - GetUnitState(Targ, UNIT_STATE_MAX_LIFE)
    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(GetUnitState(Targ, UNIT_STATE_MAX_LIFE) - HPdif))
    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

But haven't tested it yet, but really thanks a lot all ^^.
 
Status
Not open for further replies.
Top