• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!

Problem with lifebloom spell

Status
Not open for further replies.
Level 3
Joined
Dec 20, 2007
Messages
44
Hey, I'm working on a lifebloom type spell that doesn't seem to be working right (basically it's a HoT that when the HoT is either dispelled or wears off from time the unit is healed for a larger amount). Cast_Bloom, setBloomAmount and setBloomTick all work correctly, the issue is that the loop is gone through twice, doing the periodic healing, then is gone through a third time doing the final healing, even though the unit still has the buff. Any ideas?



JASS:
function Trig_Lifebloom_Conditions takes nothing returns boolean
    return GetSpellAbilityId()=='A012'
endfunction

function Cast_Bloom takes real h returns nothing
    local real l = GetUnitStateSwap(UNIT_STATE_LIFE, GetSpellTargetUnit())
    set h = h + l
    call SetUnitLifeBJ(GetSpellTargetUnit(),h)
endfunction
    
function setBloomAmount takes nothing returns real
    local real r = I2R(udg_SpellHealing[GetConvertedPlayerId(GetOwningPlayer(GetSpellAbilityUnit()))])
    set r = r*(1+.15*I2R(GetUnitAbilityLevel(GetSpellAbilityUnit(),'A012')))+250
    return r
endfunction

function setBloomTick takes nothing returns real
    local real r = I2R(udg_SpellHealing[GetConvertedPlayerId(GetOwningPlayer(GetSpellAbilityUnit()))])
    set r = r * .25+10
    return r
endfunction

function Trig_Lifebloom_Actions takes nothing returns nothing
    local real h = setBloomAmount()
    local real t = setBloomTick()
    local integer i = 0

    call TriggerSleepAction(1.00)
    call Cast_Bloom(t)
    
    loop
        exitwhen ( i > 15 )
        if ( GetUnitAbilityLevel(GetSpellTargetUnit(),'B004') > 0 ) then
            call Cast_Bloom(t)
            call TriggerSleepAction(1.00)
        else
            call Cast_Bloom(h)
            return
        endif
        set i = i + 1
    endloop
    
endfunction

//===========================================================================
function InitTrig_Lifebloom takes nothing returns nothing
    set gg_trg_Lifebloom = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ(gg_trg_Lifebloom, EVENT_PLAYER_UNIT_SPELL_CAST)
    call TriggerAddCondition( gg_trg_Lifebloom, Condition( function Trig_Lifebloom_Conditions) )
    call TriggerAddAction( gg_trg_Lifebloom, function Trig_Lifebloom_Actions )
endfunction
 
Last edited:
Level 11
Joined
Aug 25, 2006
Messages
971
First of all, we'd like to see ALL your functions not just the one. The problem might be in another for all you know.
Second UnitHasBuffBJ can be simplified to GetUnitAbilityLevel(GetSpellTargetUnit(),'B004') > 0
Third, a loop without an exitwhen can be dangerous. However your loop is pretty slow so that shouldn't be a problem.
 
Level 11
Joined
Aug 25, 2006
Messages
971
First what I think the problem might be is that GetSpellAbilityId() and GetSpellAbilityUnit() don't always return correctly after a wait. So I think the problem is they stop returning correctly thus it thinks the unit lost the buff. I suggest you use local variables instead.

Ok recommended changes
JASS:
GetUnitStateSwap(UNIT_STATE_LIFE, GetSpellTargetUnit()) //Replaces this with
GetWidgetLife(GetSpellTargetUnit())
SetUnitLifeBJ(GetSpellTargetUnit(),h) //Replace with
SetWidgetLife(GetSpellTargetUnit(),h)
I2R() //Remove this, its completely unneeded
 
Status
Not open for further replies.
Top