Making a channeling spell in vJASS

Embrace_It

New Member
Reaction score
9
Hi all,

I'm making a spell that is channeled. Each instance of the spell has a struct to store caster, duration etc.

There is one tiny problem though. The spell is interruptible and I need to know when the caster stops channeling to stop the effect of the spell. I can register the event to a trigger member, but since you can't pass a method as an action for TriggerAddAction and can't make a normal function for it (how will it know which instance to stop?), I am out of ideas. So I'm writing here :)

I was also considering some sort of attachment system (Event comes to mind, but I'm not sure if it can be used here), but is it not possible to do without one?

Ask me to post the code if you need it.

Thanks in advance!
 

MasterOfRa

New Member
Reaction score
10
The best way to do this is checking each loop/timer period if the casters order id is still equal to what it was when they started.

I made a custom repair spell like this, using TimerTicker.

JASS:
library Repair initializer Init uses AID

globals
    private constant integer AID_SPELL = AID_REPAIR
    private constant real BASE_RATE = 20.00
    private constant integer FXCOOL = R2I(1 / TT_PERIOD)
endglobals

//===========================================================================
public struct Data
    unit target
    unit caster
    real amount
    integer fxCool = 0
    static method create takes unit target, unit caster, real amount returns Data
        local Data this = Data.allocate()
        set .target = target
        set .caster = caster
        set .amount = amount * TT_PERIOD
        return this
    endmethod
    method onDestroy takes nothing returns nothing
        set .target = null
        set .caster = null
    endmethod
endstruct

//===========================================================================
public function Periodic takes nothing returns boolean
    local Data data = TT_GetData()
    local Tower tower = Tower[data.target]
    local real life = GetUnitState(data.target,UNIT_STATE_LIFE)
    local real maxlife = GetUnitState(data.target,UNIT_STATE_MAX_LIFE)
    if (tower.u != data.target) or (tower.u == null) then
        call data.destroy()
        return true
    endif
    if GetUnitCurrentOrder(data.caster) == OID_repair then
        if life == maxlife then
            call IssueImmediateOrderById(data.caster,OID_stop)
            call data.destroy()
            return true
        endif
        call SetUnitState(data.target,UNIT_STATE_LIFE,life + data.amount)
        call RecordDamageRepaired(data.caster,data.amount)
        if data.fxCool <= 0 then
            call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Undead\\VampiricAura\\VampiricAuraTarget.mdl",GetUnitX(data.target),GetUnitY(data.target)))
            set data.fxCool = FXCOOL
        else
            set data.fxCool = data.fxCool - 1
        endif
    else
        return true
    endif
    return false
endfunction
//===========================================================================
private function Actions takes nothing returns nothing
    local unit caster = GetTriggerUnit()
    local unit target= GetSpellTargetUnit()
    local integer level = GetUnitAbilityLevel(caster,AID_SPELL)
    local real amount = BASE_RATE * (ModuloInteger(level - 1,5) + 1)
    if level > 10 then
        set amount = amount * 100
    elseif level > 5 then
        set amount = amount * 10
    endif
    if GetUnitCurrentOrder(caster) == OID_smart then
        call IssueTargetOrderById(caster,OID_repair,target)
        return
    endif
    call TT_Start(function Periodic,Data.create(target,caster,amount))
    set caster = null
    set target = null
endfunction

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

//===========================================================================
private function Init takes nothing returns nothing
    local trigger trig = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(trig, EVENT_PLAYER_UNIT_SPELL_CHANNEL)
    call TriggerAddCondition( trig, Condition( function Conditions ) )
    call TriggerAddAction( trig, function Actions )
endfunction

endlibrary
 

Viikuna

No Marlo no game.
Reaction score
265
Id use ENDCAST event, but I guess that works too. ( And if you need periodic timer anyways, its not so bad )
 

Embrace_It

New Member
Reaction score
9
Ok, my timer runs every 0.5s should it should hardly be noticable if there is a delay. Thanks! :) and thanks for the example MasterOfRa

@ Viikuna: I did start out with an event, but as I explain in my original post, I see no way to use this. If you do have a solution, please post it.
 

Viikuna

No Marlo no game.
Reaction score
265
Well, a simple UnitIndexing stuff works neatly usually.

Check this spell for example: link
 
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