• Check out the results of the Techtree Contest #19!
  • 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.
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!

[JASS] Simple Heal Spell but Doesn't work

Status
Not open for further replies.
JASS:
function SotL_Actions takes nothing returns nothing
//***Locals***
    local unit u = GetTriggerUnit()
    local integer i  = GetUnitAbilityLevelSwapped(GetSpellAbilityId(),u)
    local real r1
    local real r2= 10 + 2 * i
    local integer loop1end = 10
    local integer loop1int = 0
    local effect e
//************
    loop
        exitwhen loop1int > loop1end
        set loop1int = loop1int + 1
        set r1 = GetUnitStateSwap(UNIT_STATE_LIFE, u)
         call TriggerSleepAction( 1 )
         call SetUnitLifeBJ( u, ( r1 + r2 ) )
         set e = AddSpecialEffectTargetUnitBJ( "origin", u, "Abilities\\Spells\\Human\\Heal\\HealTarget.mdl" )
         call DestroyEffectBJ( e )
    endloop
endfunction

function Trig_SotL_Actions takes nothing returns nothing
if ( GetSpellAbilityId() == 'A000'  )
then
call ExecuteFunc(function SotL_Actions)
else
endif
endfunction

//===========================================================================
function InitTrig_SotL takes nothing returns nothing
    local trigger gg_trg_SotL = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_SotL, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddAction( gg_trg_SotL, function SotL_Actions )
    call TriggerAddAction( gg_trg_SotL, function Trig_SotL_Actions )
endfunction
When I am trying to save this it says that the Spell Ability ID is not a valid syntax.
Why?
 
You could try this.


JASS:
function SotL_Actions takes nothing returns nothing
//***Locals***
    local unit u = GetTriggerUnit()
    local integer i = GetUnitAbilityLevel(u, GetSpellAbilityId())
    local real r1 = GetUnitState(u, UNIT_STATE_LIFE)
    local real r2 = 10. + 2. * i
    local integer loop1end = 10
    local integer loop1int = 1
    local effect e
//************
    loop
        exitwhen loop1int > loop1end
        set loop1int = loop1int + 1
        call SetUnitState(u, UNIT_STATE_LIFE, r1 + (loop1int * r2)) // Loop will now run 10 times and this is a faster way.
        set e = AddSpecialEffectTarget("Abilities\\Spells\\Human\\Heal\\HealTarget.mdl", u, "origin")
        call TriggerSleepAction(1) // Shouldn't you want to show the healing effect while the hp adding is done?
        call DestroyEffect(e)
    endloop
    set e = null
    set u = null
endfunction

function SotL_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A000'
endfunction

//===========================================================================
function InitTrig_SotL takes nothing returns nothing
    local trigger gg_trg_SotL = CreateTrigger()

    call TriggerRegisterAnyUnitEventBJ( gg_trg_SotL, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(gg_trg_SotL, Condition(function SotL_Conditions))
    call TriggerAddAction(gg_trg_SotL, function SotL_Actions)
    set gg_trg_SotL = null
endfunction


ps... Answer to your question ~.~

You didn't gave a string as argument to ExecuteFunc, that's why you get the error message there.
It's better to use the spell in the example I showed you though.
 
JASS:
function Trig_SotL_Actions takes nothing returns nothing
if ( GetSpellAbilityId() == 'A000' )
then
call ExecuteFunc(function SotL_Actions)
else
endif
endfunction

after that GetTriggerUnit() wont work also you leak some and GetUnitAbilityLevelSwapped(GetSpellAbilityId(),u) dont work neither

this is how i would do it even thou i could been improved with timer ect ect

JASS:
function SotL_Conds takes nothing returns boolean
    return GetSpellAbilityId() == 'A000'
endfunction

function SotL_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local integer i = GetUnitAbilityLevel(GetTriggerUnit(),'A000')
    local real r= 12 * i
    local integer loops = 10

    loop
        exitwhen loops <= 0
        set loops = loops - 1
        call TriggerSleepAction( 1 )
        call SetUnitState(u, UNIT_STATE_LIFE, GetUnitState(u,UNIT_STATE_LIFE)+r)
        call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Human\\Heal\\HealTarget.mdl",u,"origin"))
    endloop
    set u = null     
endfunction


//===========================================================================
function InitTrig_SotL takes nothing returns nothing
    local trigger gg_trg_SotL = CreateTrigger( )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_SotL, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddAction( gg_trg_SotL, function SotL_Actions )
    call TriggerAddCondition(gg_trg_SotL,Filter(function SotL_Conds))
endfunction
 
:-)

Multiply before adding. 10 + 2 * i != 12i
Getting the unit state in a loop can be avoided here and should be avoided since it's slower than simply adding the factor.

This can be done without a timer. Destroying this effect after creating it won't show much of an effect. It's best to put the wait in between in this case.
 
Status
Not open for further replies.
Back
Top