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

[JASS] JASS spell triggers simplify

Status
Not open for further replies.
Level 11
Joined
Sep 14, 2009
Messages
284
I have a non-MUI spell that consists of two JASS triggers, but I want to make my map more compact and make spells consist of only one trigger (all code in one trigger). I have seen more advanced spells in only one trigger and I figure if I get some help with this one maybe I can figure out how to do it with the others as well.

Here are the triggers:

JASS:
function MeditationCast_Conditions takes nothing returns boolean
    return GetIssuedOrderIdBJ() == String2OrderIdBJ("immolation") and GetUnitAbilityLevelSwapped('A014', GetTriggerUnit()) >= 1
endfunction

function MeditationCast_Actions takes nothing returns nothing
    set udg_MeditationCaster = GetTriggerUnit()
    call StartTimerBJ(udg_MeditationTimer, false, 0.50)
endfunction

//===========================================================================
function InitTrig_MeditationCast takes nothing returns nothing
    set gg_trg_MeditationCast = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(gg_trg_MeditationCast, EVENT_PLAYER_UNIT_ISSUED_ORDER)
    call TriggerAddCondition(gg_trg_MeditationCast, Condition(function MeditationCast_Conditions))
    call TriggerAddAction(gg_trg_MeditationCast, function MeditationCast_Actions)
endfunction

JASS:
function MeditationHeal_Actions takes nothing returns nothing
    if IsUnitAliveBJ(udg_MeditationCaster) == true and UnitHasBuffBJ(udg_MeditationCaster, 'B003') == true then
        call GetSpellPower(udg_MeditationCaster)
        set udg_HealAmount = 7.00 + (3.00 * I2R(GetUnitAbilityLevelSwapped('A014', udg_MeditationCaster))) + (0.15 * udg_GetSpellPowerAmount)
        call Heal(udg_MeditationCaster, udg_MeditationCaster, udg_HealAmount)
        call StartTimerBJ(udg_MeditationTimer, false, 1.00)
    endif
endfunction

//===========================================================================
function InitTrig_MeditationHeal takes nothing returns nothing
    set gg_trg_MeditationHeal = CreateTrigger()
    call TriggerRegisterTimerExpireEventBJ(gg_trg_MeditationHeal, udg_MeditationTimer)
    call TriggerAddAction(gg_trg_MeditationHeal, function MeditationHeal_Actions)
endfunction
 
Level 37
Joined
Mar 6, 2006
Messages
9,243
JASS:
function MeditationCast_Conditions takes nothing returns boolean
    return GetIssuedOrderIdBJ() == String2OrderIdBJ("immolation") and GetUnitAbilityLevelSwapped('A014', GetTriggerUnit()) >= 1
endfunction

function MeditationCast_Actions takes nothing returns nothing
    set udg_MeditationCaster = GetTriggerUnit()
    call StartTimerBJ(udg_MeditationTimer, false, 0.50)
endfunction

function MeditationHeal_Actions takes nothing returns nothing
    if IsUnitAliveBJ(udg_MeditationCaster) == true and UnitHasBuffBJ(udg_MeditationCaster, 'B003') == true then
        call GetSpellPower(udg_MeditationCaster)
        set udg_HealAmount = 7.00 + (3.00 * I2R(GetUnitAbilityLevelSwapped('A014', udg_MeditationCaster))) + (0.15 * udg_GetSpellPowerAmount)
        call Heal(udg_MeditationCaster, udg_MeditationCaster, udg_HealAmount)
        call StartTimerBJ(udg_MeditationTimer, false, 1.00)
    endif
endfunction

//===========================================================================
function InitTrig_MeditationCast takes nothing returns nothing
    set gg_trg_MeditationCast = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(gg_trg_MeditationCast, EVENT_PLAYER_UNIT_ISSUED_ORDER)
    call TriggerAddCondition(gg_trg_MeditationCast, Condition(function MeditationCast_Conditions))
    call TriggerAddAction(gg_trg_MeditationCast, function MeditationCast_Actions)

    set gg_trg_MeditationHeal = CreateTrigger()
    call TriggerRegisterTimerExpireEventBJ(gg_trg_MeditationHeal, udg_MeditationTimer)
    call TriggerAddAction(gg_trg_MeditationHeal, function MeditationHeal_Actions)
endfunction
 
Level 11
Joined
Sep 14, 2009
Messages
284
JASS:
function MeditationCast_Conditions takes nothing returns boolean
    return GetIssuedOrderIdBJ() == String2OrderIdBJ("immolation") and GetUnitAbilityLevelSwapped('A014', GetTriggerUnit()) >= 1
endfunction

function MeditationCast_Actions takes nothing returns nothing
    set udg_MeditationCaster = GetTriggerUnit()
    call StartTimerBJ(udg_MeditationTimer, false, 0.50)
endfunction

function MeditationHeal_Actions takes nothing returns nothing
    if IsUnitAliveBJ(udg_MeditationCaster) == true and UnitHasBuffBJ(udg_MeditationCaster, 'B003') == true then
        call GetSpellPower(udg_MeditationCaster)
        set udg_HealAmount = 7.00 + (3.00 * I2R(GetUnitAbilityLevelSwapped('A014', udg_MeditationCaster))) + (0.15 * udg_GetSpellPowerAmount)
        call Heal(udg_MeditationCaster, udg_MeditationCaster, udg_HealAmount)
        call StartTimerBJ(udg_MeditationTimer, false, 1.00)
    endif
endfunction

//===========================================================================
function InitTrig_MeditationCast takes nothing returns nothing
    set gg_trg_MeditationCast = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(gg_trg_MeditationCast, EVENT_PLAYER_UNIT_ISSUED_ORDER)
    call TriggerAddCondition(gg_trg_MeditationCast, Condition(function MeditationCast_Conditions))
    call TriggerAddAction(gg_trg_MeditationCast, function MeditationCast_Actions)

    set gg_trg_MeditationHeal = CreateTrigger()
    call TriggerRegisterTimerExpireEventBJ(gg_trg_MeditationHeal, udg_MeditationTimer)
    call TriggerAddAction(gg_trg_MeditationHeal, function MeditationHeal_Actions)
endfunction


Yes, this was my thought as well, however it gives this syntax error:
Line 6974: Undeclared variable gg_trg_MeditationHeal
 
gg_trg_ stands for a generated global, and it is only generated automatically if a trigger under that name exists.

So you would have to change the init function to:
JASS:
function InitTrig_MeditationCast takes nothing returns nothing
    local trigger meditationHeal = CreateTrigger()
    set gg_trg_MeditationCast = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(gg_trg_MeditationCast, EVENT_PLAYER_UNIT_ISSUED_ORDER)
    call TriggerAddCondition(gg_trg_MeditationCast, Condition(function MeditationCast_Conditions))
    call TriggerAddAction(gg_trg_MeditationCast, function MeditationCast_Actions)

    call TriggerRegisterTimerExpireEventBJ(meditationHeal, udg_MeditationTimer)
    call TriggerAddAction(meditationHeal, function MeditationHeal_Actions)
endfunction
 
Status
Not open for further replies.
Top