Spell help once again.

Larcenist

REP: Respect, Envy, Prosperity?
Reaction score
211
Once again I've run into some problems with one of my spells. The spell is called Fire Pillar, and it creates a visible dummyunit at the targetted location, then it's supposed to hit the first enemy unit who comes in range of that dummy with 10 firebolts. The problem seems to occur in the loop that orders the dummies to firebolt the unit who enters.
JASS:

scope FirePillar

globals
    private constant integer SpellAID = 'A000'          //The hero spell ID
    private constant integer DummyAID = 'A001'         //The dummyspell ID
    private constant integer EffectDummyID = 'u000'   //The visible dummy's ID
    private constant integer DummyID = 'u001'        //The regular dummy's ID
    private constant real Duration = 12.0           //The duration of the spell
endglobals

struct SpellData
    unit caster
    unit dummy
    real x
    real y
    trigger inrange
    timer fptimer
    boolean check
    method onDestroy takes nothing returns nothing
        call ClearTriggerStructA(.inrange)
        call DestroyTrigger(.inrange)
        call ClearTimerStructA(.fptimer)
        call DestroyTimer(.fptimer)
    endmethod
endstruct

private function TimerActions takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local SpellData data = GetTimerStructA(t)
    
    call BJDebugMsg("Effect runs out")
    if GetWidgetLife(data.dummy) > 5.0 then
        call KillUnit(data.dummy)
    endif
    call data.destroy()
    
    set t = null
endfunction

private function InRangeActions takes nothing returns nothing
    local SpellData data = GetTriggerStructA(GetTriggeringTrigger())
    local unit Victim = GetTriggerUnit()
    local integer Loop = 0
    local unit Dummy
    
    call BJDebugMsg("Unit Entered Range")
    if data.check == false then
        if IsPlayerEnemy(GetOwningPlayer(data.caster), GetOwningPlayer(Victim)) == true then
            set data.check = true
            call BJDebugMsg("Entering unit is enemy")
            loop
                exitwhen Loop >= 10
                    set Loop = Loop + 1
                    set Dummy = CreateUnit(GetOwningPlayer(data.caster), DummyID, data.x, data.y, 0)
                    call UnitAddAbility(Dummy, DummyAID)
                    call IssueTargetOrder(Dummy, "thunderbolt", Victim)
                    call UnitApplyTimedLife(Dummy, 'BTLF', 1.0)
                    call TriggerSleepAction(.1)
            endloop
            call KillUnit(data.dummy)
        endif
    endif
    
    set Victim = null
    set Dummy = null
endfunction

private function Conditions takes nothing returns boolean
    return GetSpellAbilityId() == SpellAID
endfunction

private function Actions takes nothing returns nothing
    local SpellData data = SpellData.create()
    local location Point = GetSpellTargetLoc()
    local unit Caster = GetTriggerUnit()
    local real x = GetLocationX(Point)
    local real y = GetLocationY(Point)
    
    call BJDebugMsg("Effect started")
    set data.dummy = CreateUnit(GetOwningPlayer(Caster), EffectDummyID, x, y, 0)
    set data.fptimer = CreateTimer()
    set data.caster = Caster
    set data.inrange = CreateTrigger()
    set data.check = false
    set data.x = x
    set data.y = y
    
    call SetTimerStructA(data.fptimer, data)
    call TimerStart(data.fptimer, Duration, false, function TimerActions)
    call SetTriggerStructA(data.inrange, data)
    call TriggerRegisterUnitInRangeSimple(data.inrange, 150, data.dummy)
    call TriggerAddAction(data.inrange, function InRangeActions)
    call RemoveLocation(Point)
    
    set Point = null
    set Caster = null
endfunction

//===========================================================================
public function InitTrig takes nothing returns nothing
    local trigger trig = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( trig, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( trig, Condition( function Conditions ) )
    call TriggerAddAction( trig, function Actions )
endfunction

endscope


Note that this is my first time fooling around with methods and adding secondary triggers/TriggerStruct attachents and so on, so please correct me if I did something wrong there.

This seems to be the problem:
JASS:

   if data.check == false then
        if IsPlayerEnemy(GetOwningPlayer(data.caster), GetOwningPlayer(Victim)) == true then
            set data.check = true
            call BJDebugMsg("Entering unit is enemy")
            loop
                exitwhen Loop >= 10
                    set Loop = Loop + 1
                    set Dummy = CreateUnit(GetOwningPlayer(data.caster), DummyID, data.x, data.y, 0)
                    call UnitAddAbility(Dummy, DummyAID)
                    call IssueTargetOrder(Dummy, "thunderbolt", Victim)
                    call UnitApplyTimedLife(Dummy, 'BTLF', 1.0)
                    call TriggerSleepAction(.1)
            endloop
            call KillUnit(data.dummy)
        endif


I get the DebugMsg "Entering unit is enemy", but nothing else is working properly.

Thanks in advanced.
 

Larcenist

REP: Respect, Envy, Prosperity?
Reaction score
211
Just for safety if it magically would jump over 10 due to something stupid done by me, doesn't really matter since it has to become 10 in order to pass 10.

edit: It seems to be working fine now. Could someone tell me if this leaks or anything? I'm not very used to the method using etc so I don't really know how it works.
 
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