Spell Help: Cannot Retrieve Attached Trigger

AceLegend90

New Member
Reaction score
6
After much time spent debugging this code, I've figured out that the problem is that GetCSData(GetTriggeringTrigger()) isn't actually getting the struct that I attached.

Does anyone see the problem with my code? (It uses Vexorian's Caster System.)

JASS:
scope Envision

private struct Envision
    unit caster
    unit target
    real damage
    trigger effects
    timer clock
    
    static method Conditions takes nothing returns boolean
        if GetSpellAbilityId() == 'A077' and GetTriggerEventId() == EVENT_PLAYER_UNIT_SPELL_CAST then
            if GetUnitAbilityLevel(GetSpellTargetUnit(), 'B01E') > 0 then
                call PauseUnit(GetTriggerUnit(), true)
                call IssueImmediateOrder(GetTriggerUnit(), "stop")
                call PauseUnit(GetTriggerUnit(), false)
                call DisplayErrorToPlayer(GetTriggerPlayer(), "Cannot stack Envision.")
            endif
            return false
        endif
        return GetSpellAbilityId() == 'A077'
    endmethod
    
    static method Start takes nothing returns nothing
        local Envision spell = Envision.allocate()
        
        set spell.caster = GetTriggerUnit()
        set spell.target = GetSpellTargetUnit()
        set spell.damage = 0.
        set spell.effects = CreateTrigger()
            call SetCSData(spell.effects, spell)
        
        call TriggerRegisterTimerEvent(spell.effects, .05, true)
        call TriggerRegisterUnitEvent(spell.effects, spell.target, EVENT_UNIT_DAMAGED)
        call TriggerAddCondition(spell.effects, Condition(function Envision.TimerEnd))
    endmethod
    
    static method TimerEnd takes nothing returns boolean
        local Envision spell = GetCSData(GetTriggeringTrigger())
        
        if GetTriggerEventId() == EVENT_UNIT_DAMAGED then
            call spell.DamageTarget()
        else
            call spell.IncreaseDamage()
        endif
        return false
    endmethod
    
    method IncreaseDamage takes nothing returns nothing
        if .damage < 50. then
            set .damage = .damage + .05 + .0375 * GetUnitAbilityLevel(.caster, 'A077')
        endif
        if IsUnitFogged(.target, GetOwningPlayer(.caster)) or GetWidgetLife(.target) <= 0. then
            call .destroy()
        endif
    endmethod
    
    method DamageTarget takes nothing returns nothing
        call DisableTrigger(.effects)
        if GetEventDamageSource() == .caster and GetEventDamage() > 5. then
            call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Other\\Stampede\\StampedeMissileDeath.mdl", .target, "chest"))
            call UnitDamageTarget(.caster, .target, .damage, true, true, ATTACK_TYPE_HERO, DAMAGE_TYPE_NORMAL, null)
        endif
        call EnableTrigger(.effects)
    endmethod
    
    method onDestroy takes nothing returns nothing
        call UnitRemoveAbility(.target, 'B01E')
        call SafeDestroyTrigger(.effects)
    endmethod
endstruct

function Start_Envision takes nothing returns nothing
    local trigger init = CreateTrigger()
    call TriggerRegisterAnyUnitEvent(init, EVENT_PLAYER_UNIT_SPELL_CAST)
    call TriggerRegisterAnyUnitEvent(init, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(init, Condition(function Envision.Conditions))
    call TriggerAddAction(init, function Envision.Start)
endfunction

endscope

function InitTrig_Envision takes nothing returns nothing
endfunction
 

Artificial

Without Intelligence
Reaction score
326
You should try moving TimerEnd above Start.
Because currently a new function is generated, and that function is set as the condition of the trigger of yours. What that function does is evaluate a trigger that has TimerEnd as condition (so a different trigger fires it), and return the value it returned. Or at least that's what happens IIRC.
This won't happen when TimerEnd is above Start. :p
 

AceLegend90

New Member
Reaction score
6
Thank you! That solved the problem. Another question, should non-static methods be placed above their caller methods as well? It does not seem to be a problem when they are below.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top