Unit Finish Casting Issue

Naga'sShadow

Ultra Cool Member
Reaction score
49
I've got a spell that needs to detect after its finished casting. Except the data I need includes the target of the ability cast, not something included in the EVENT_PLAYER_UNIT_SPELL_FINISH. Right now I think that using structs would be the fastest way of getting this data from a trigger the stores the target on spell effect but I have no idea how to use structs and as I have it does not work. I'll post the code could someone tell me where I've gone wrong?

Main Trigger
JASS:

function BoW_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A004'
endfunction

function BoW_Actions takes nothing returns nothing
    local unit targ 
    local integer array spell 
    local integer level = GetUnitAbilityLevel(GetTriggerUnit(), 'A004')
    local player p = GetOwningPlayer(GetTransportUnit())
    local BattleTarget data = BattleTarget.create()
    
    set targ = data.targ
    set spell[1] = 'A00P'
    set spell[2] = 'A00Q'
    set spell[3] = 'A00R'
    set spell[4] = 'A00S'
    set spell[5] = 'A00T'
    
    call CasterCastAbility(p, spell[ level ], "doom", targ, false)
    
    set targ = null

endfunction
//=======================================================================
function InitTrig_Battle_of_Wits takes nothing returns nothing
    local trigger gg_trg_BoW
    set gg_trg_BoW = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_BoW, EVENT_PLAYER_UNIT_SPELL_FINISH)
    call TriggerAddCondition(gg_trg_BoW, Condition(function BoW_Conditions))
    call TriggerAddAction(gg_trg_BoW, function BoW_Actions)
    set gg_trg_BoW = null
endfunction

Secondary Trigger
JASS:

function BoW2_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A004'
endfunction

function BoW2_Actions takes nothing returns nothing
    local BattleTarget data = BattleTarget.create()
    set data.targ = GetSpellTargetUnit()
endfunction

//=======================================================================
function InitTrig_Battle_of_Wits2 takes nothing returns nothing
    local trigger gg_trg_BoW2
    set gg_trg_BoW2 = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ(gg_trg_BoW2, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(gg_trg_BoW2, Condition(function BoW2_Conditions))
    call TriggerAddAction(gg_trg_BoW2, function BoW2_Actions)
    set gg_trg_BoW2 = null
endfunction

I've currently got the strut sitting in an otherwise empty library but due to the syntax checker going crazy whenever I attempt to use it I have no idea where it should go. Does in belong in either of these triggers?
 

Flare

Stops copies me!
Reaction score
662
local BattleTarget data = BattleTarget.create()
set targ = data.targ
There isn't (well, there shouldn't be) a value for data.targ, so how can you set targ to data.targ?

And which syntax checker are you going by? The one that appears when you click Save, or the one called Syntax Check in the Trigger Editor window?
 

Naga'sShadow

Ultra Cool Member
Reaction score
49
The Secondary Trigger was supposed to set data.targ, and I'm referring to the syntax checker in the editor, it saves fine but does nothing.
 

Joker(Div)

Always Here..
Reaction score
86
Why do you need 2 triggers for this? Plus, where are you setting your struct? Also, why are you using structs, but nothing else from vJASS?
 

Naga'sShadow

Ultra Cool Member
Reaction score
49
Why do you need 2 triggers for this? Plus, where are you setting your struct? Also, why are you using structs, but nothing else from vJASS?

Two triggers because the event unit finishes casting doesn't recall the targeted unit. The first trigger is to find the targeted unit on cast and give it to the second unit.

The struct is sitting in a library because I have no idea where it should be. As for why structs because I know nothing at all about VJass and all the tutorials on this page say that structs are the easiest way to transfer data between triggers without using globals.
 

Joker(Div)

Always Here..
Reaction score
86
Two triggers because the event unit finishes casting doesn't recall the targeted unit. The first trigger is to find the targeted unit on cast and give it to the second unit.
Um...I'm still not sure what your doing.

The struct is sitting in a library because I have no idea where it should be. As for why structs because I know nothing at all about VJass and all the tutorials on this page say that structs are the easiest way to transfer data between triggers without using globals.
Heres a basic vJASS template
JASS:
scope <NAME> initializer Init

//globals can be declared here, i.e.
//
//globals
//  private integer CD = 0
//endglobals

//structs would be declared here, i.e.
//
//  struct ABC
//      unit a
// 
//      method bla..
//  endstruct


//private prefixes are there so that these functions can only be used inside their declared scope
//you can use "public" prefixes if you want it declared outside the scope or you could use no
//prefix at all. When you use things when the public prefix outside the scope it is declared in,
//you need to declare it as: ScopeName_YourFunction/Global/Struct

private function Conditions takes nothing returns boolean
    return ...
endfunction

private function Actions takes nothing returns nothing
    Do stuff...
endfunction

private function Init takes nothing returns nothing //Your Init, obviously
    local trigger t = CreateTrigger()
    call TriggerRegister...
    call TriggerAddCondition(t, Condition(function Conditions))
    call TriggerAddAction(t, function Actions)
    //you can null t if you want, I prefer not to
endfunction

endscope

Here's your 2 triggers in one.
JASS:
scope BattleOfWits initializer Init //I don't think your allowed underscores in scope names

private function BoW_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A004'
endfunction

private function BoW_Actions takes nothing returns nothing
    local unit targ = GetSpellTargetUnit()
    local integer array spell 
    local integer level = GetUnitAbilityLevel(GetTriggerUnit(), 'A004')
    local player p = GetOwningPlayer(GetTransportUnit())
    local BattleTarget data = BattleTarget.create()

    set spell[1] = 'A00P'
    set spell[2] = 'A00Q'
    set spell[3] = 'A00R'
    set spell[4] = 'A00S'
    set spell[5] = 'A00T'
    
    call CasterCastAbility(p, spell[ level ], "doom", targ, false)
    
    set targ = null

endfunction
//=======================================================================
private function Init takes nothing returns nothing
    local trigger trig = CreateTrigger()
    //set gg_trg_BoW = CreateTrigger()  We do not need this
    call TriggerRegisterAnyUnitEventBJ( trig, EVENT_PLAYER_UNIT_SPELL_EFFECT)  //Just use this event so that you can get the target unit
    call TriggerAddCondition(trig, Condition(function BoW_Conditions))
    call TriggerAddAction(trig, function BoW_Actions)
    set trig = null
endfunction

endscope
 

Naga'sShadow

Ultra Cool Member
Reaction score
49
Thanks for the template but as for the spell, the spell is based of channel and has a casting time as part of the balance of a doom spell that targets heroes. But if you use any casting time the hero just stands there and doesn't play any animation. In other words doesn't place the large "stun me!" sign on his head i want him to. I'm going to just do the thing in Gui and not worry about it, thanks for all the help.
 

T.s.e

Wish I was old and a little sentimental
Reaction score
133
Scopes need to have the same name as the trigger that they are in.
 

Artificial

Without Intelligence
Reaction score
326
> Scopes need to have the same name as the trigger that they are in.
No they don't, as long as you ain't using a public InitTrig and hoping for it to work. :p
Although it makes it easier to find them if they are named the same.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top