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?
 
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?
 
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.
 
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?
 
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.
 
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
 
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.
 
Scopes need to have the same name as the trigger that they are in.
 
> 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.
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    News portal has been retired. Main page of site goes to Headline News forum now
  • The Helper The Helper:
    I am working on getting access to the old news portal under a different URL for those that would rather use that for news before we get a different news view.
  • Ghan Ghan:
    Easily done
    +1
  • The Helper The Helper:
    https://www.thehelper.net/pages/news/ is a link to the old news portal - i will integrate it into the interface somewhere when i figure it out
  • Ghan Ghan:
    Need to try something
  • Ghan Ghan:
    Hopefully this won't cause problems.
  • Ghan Ghan:
    Hmm
  • Ghan Ghan:
    I have converted the Headline News forum to an Article type forum. It will now show the top 20 threads with more detail of each thread.
  • Ghan Ghan:
    See how we like that.
  • The Helper The Helper:
    I do not see a way to go past the 1st page of posts on the forum though
  • The Helper The Helper:
    It is OK though for the main page to open up on the forum in the view it was before. As long as the portal has its own URL so it can be viewed that way I do want to try it as a regular forum view for a while
  • Ghan Ghan:
    Yeah I'm not sure what the deal is with the pagination.
  • Ghan Ghan:
    It SHOULD be there so I think it might just be an artifact of having an older style.
  • Ghan Ghan:
    I switched it to a "Standard" article forum. This will show the thread list like normal, but the threads themselves will have the first post set up above the rest of the "comments"
  • The Helper The Helper:
    I don't really get that article forum but I think it is because I have never really seen it used on a multi post thread
  • Ghan Ghan:
    RpNation makes more use of it right now as an example: https://www.rpnation.com/news/
  • The Helper The Helper:
  • The Helper The Helper:
    What do you think Tom?
  • tom_mai78101 tom_mai78101:
    I will have to get used to this.
  • tom_mai78101 tom_mai78101:
    The latest news feed looks good

      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