• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Double Cast Passive, dummy doesn't cast.

Status
Not open for further replies.
Level 14
Joined
Jul 26, 2008
Messages
1,009
I have created a Double Cast passive. What it does is when the unit casts any spell whatsoever, the spell will be cast a second time by a dummy unit. Simple enough.

So I give the dummy unit the ability cast. This works out just fine. When it comes to ordering the unit to cast the spell what I tried didn't work. Any help or ideas?

JASS:
function Trig_DoubleCast_Conditions takes nothing returns boolean
    return GetUnitAbilityLevel(GetTriggerUnit(), 'DblC') > 0
endfunction

function Trig_DoubleCast_Actions takes nothing returns nothing
    local unit c = GetTriggerUnit()
    local unit t = GetSpellTargetUnit()
    local unit d
    local real tX = GetSpellTargetX()
    local real tY = GetSpellTargetY()
    local real x = GetUnitX(c)
    local real y = GetUnitY(c)
    local integer SPELLID = GetSpellAbilityId()
    local string id = AbilityId2String(GetSpellAbilityId())
    
    set d = CreateUnit(GetOwningPlayer(c), 'hsor', x, y, AngleBetweenPoints(Location(x, y), Location(tX,tY)))
    call SetUnitState(d, UNIT_STATE_MANA, 9999)
    call UnitAddAbility(d, SPELLID)
    call UnitApplyTimedLife(d, 'BTLF', 2.)
    call IssueImmediateOrder(d, id)
    call IssueTargetOrder(d, id, t)
    call IssuePointOrder(d, id, tX, tY)
    
endfunction

//===========================================================================
function InitTrig_DoubleCast takes nothing returns nothing
    set gg_trg_DoubleCast = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_DoubleCast, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_DoubleCast, Condition( function Trig_DoubleCast_Conditions ) )
    call TriggerAddAction( gg_trg_DoubleCast, function Trig_DoubleCast_Actions )
endfunction
 
Your spell was also leaking two points...

JASS:
function Trig_DoubleCast_Actions takes unit c,unit d returns nothing
    local string id = OrderId2String(GetUnitCurrentOrder(c))
 
    set d = CreateUnit(GetTriggerPlayer(),'hsor',GetUnitX(c),GetUnitY(c),GetUnitFacing(c))
    call SetUnitState(d,UNIT_STATE_MANA,9999)
    call UnitAddAbility(d,GetSpellAbilityId())
    call UnitApplyTimedLife(d,'BTLF',2.)
    if not IssueImmediateOrder(d,id) then
        if not IssueTargetOrder(d,id,GetSpellTargetUnit()) then
            call IssuePointOrder(d,id,GetSpellTargetX(),GetSpellTargetY())
        endif
    endif
 
endfunction
 
function Trig_DoubleCast_Conditions takes nothing returns boolean
    if GetUnitAbilityLevel(GetTriggerUnit(),'DblC') > 0 then
        call Trig_DoubleCast_Actions(GetTriggerUnit(),null)
    endif
    return false
endfunction
 
//===========================================================================
function InitTrig_DoubleCast takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(t,Condition(function Trig_DoubleCast_Conditions))
endfunction
 
Level 14
Joined
Jul 26, 2008
Messages
1,009
You're right. I got it to work through a inneffecient attempt. basically I create 3 casters and order them to do a different type of order for each. However spells like shockwave tend to become triple casted because it's both a unit order and a ground order, so the ground order dummy and the unit order dummy both cast.

What's your method of checking?
 
Level 14
Joined
Jul 26, 2008
Messages
1,009
Hmm. For whatever reason it's not working perfectly. Only on certain spells, like shockwave. Going over the if statements it doesn't look like there should be a reason it's doing this.

Whatdo you think?

JASS:
function Trig_DoubleCast_Conditions takes nothing returns boolean
    return GetUnitAbilityLevel(GetTriggerUnit(), 'DblC') > 0
endfunction

function Trig_DoubleCast_Actions takes nothing returns nothing
 local unit c = GetTriggerUnit()
 local unit t = GetSpellTargetUnit()
 local unit d
 local string id = OrderId2String(GetUnitCurrentOrder(c))
 local real tX = GetSpellTargetX()
 local real tY = GetSpellTargetY()
 local real x = GetUnitX(c)
 local real y = GetUnitY(c)
 local real MP
 local integer i = GetRandomInt(3, 10)
 local integer SPELLID = GetSpellAbilityId()
    
    if i <= 3 then
     set d = CreateUnit(GetOwningPlayer(c), 'e002', x, y, AngleBetweenPoints(Location(x, y), Location(tX,tY)))
        call UnitAddAbility(d, SPELLID)
        call SetUnitState(d, UNIT_STATE_MANA, 9999)
        call UnitApplyTimedLife(d, 'BTLF', 5.)
        
     set MP = GetUnitState(d, UNIT_STATE_MANA)

        if t == null and tX == null then
            call IssueImmediateOrder(d, id)
        elseif t != null then
            call IssueTargetOrder(d, id, t)
        else
            call IssuePointOrder(d, id, tX, tY)
        endif
    
     set MP = MP - GetUnitState(d, UNIT_STATE_MANA) * 0.50
        call SetUnitState(c, UNIT_STATE_MANA, GetUnitState(c, UNIT_STATE_MANA) - MP)
    endif

    set t = null
    set d = null
    set c = null
    set id = null
endfunction

//===========================================================================
function InitTrig_DoubleCast takes nothing returns nothing
    set gg_trg_DoubleCast = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_DoubleCast, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_DoubleCast, Condition( function Trig_DoubleCast_Conditions ) )
    call TriggerAddAction( gg_trg_DoubleCast, function Trig_DoubleCast_Actions )
endfunction
 
Level 14
Joined
Nov 18, 2007
Messages
1,084
Using your trigger seems to work fine for me, though I haven't tested it extensively with other spells. (I tested with Summon Water Elemental, Howl of Terror, Carrion Swarm, Shockwave, and Banish)
Do you think something could be wrong with your dummy unit?

Sort of off-topic, but I think you should do the random integer check in the Conditions function to avoid setting all those variables in the Actions function for no reason.
 
This works flawlessly:

JASS:
function Trig_DoubleCast_Actions takes unit c,unit t,unit d returns nothing
    local real x = GetUnitX(c)
    local real x2 = GetSpellTargetX()
    local string id = OrderId2String(GetUnitCurrentOrder(c))
    set d = CreateUnit(GetTriggerPlayer(),'hsor',x,GetUnitY(c),GetUnitFacing(c))
    call SetUnitState(d,UNIT_STATE_MANA,9999)
    call UnitAddAbility(d,GetSpellAbilityId())
    call UnitApplyTimedLife(d,'BTLF',2.)
    if t == null then
        if x != x2 then
            call IssuePointOrder(d,id,x2,GetSpellTargetY())
        else
            call IssueImmediateOrder(d,id)
        endif
    else
        call IssueTargetOrder(d,id,t)
    endif
 
endfunction
 
function Trig_DoubleCast_Conditions takes nothing returns boolean
    if GetUnitAbilityLevel(GetTriggerUnit(),'A000') > 0 and IsUnitType(GetTriggerUnit(),UNIT_TYPE_HERO) then
        call Trig_DoubleCast_Actions(GetTriggerUnit(),GetSpellTargetUnit(),null)
    endif
    return false
endfunction
 
//===========================================================================
function InitTrig_DoubleCast takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(t,Condition(function Trig_DoubleCast_Conditions))
endfunction
 
Level 14
Joined
Jul 26, 2008
Messages
1,009
Whether it's the sorceress or the XE default caster, the result is the same. However it casts for point and unit order. For some reason the immediate orders like clap and feralspirit don't work.

I'll try them in a different map to see if it works. It may be some unknown component in my map causing the issue (Thought that'd be unusual.)
 
Level 11
Joined
Sep 30, 2009
Messages
698
JASS:
scope DoubleCast initializer init

private function Actions takes unit c returns nothing
    local real x = GetUnitX(c)
    local real y = GetUnitY(c)
    local real x2 = GetSpellTargetX()
    local real y2 = GetSpellTargetY()
    local string id = OrderId2String(GetUnitCurrentOrder(c))
    local widget target = GetOrderTarget()
    
    local unit d = CreateUnit(GetOwningPlayer(c),'hsor',x,y,GetUnitFacing(c))
    call SetUnitState(d,UNIT_STATE_MANA,9999)
    call UnitAddAbility(d,GetSpellAbilityId())
    //call UnitRemoveAbility(d, 'Amov')
    call UnitApplyTimedLife(d,'Basl',2.)
    if target == null and x2 == null then
        call IssueImmediateOrder(d,id) 
    elseif target != null then
        call IssueTargetOrder(d,id,GetSpellTargetUnit())
    else
        call IssuePointOrder(d,id,x2,y2)
    endif
    set c = null
    set d = null
endfunction
 
private function Conditions takes nothing returns boolean
    if GetUnitTypeId(GetTriggerUnit()) != 'hsor' then
        call Actions(GetTriggerUnit())
    endif
    return false
endfunction
 
//===========================================================================
private function init takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(t,Condition(function Conditions))
endfunction

endscope

Thats what I am using right now i changed the unit to a widget as the order target :) vJass right now but nearly same as jass for now
 
@ Axion --> setting parameters to null defeats the whole purpose. Parameters aren't like locals.

@ OP --> That was my bad for not testing "immediate order". Tested the other two. I just did a bunch of tests with all of them and this will work unless the unit is standing at 0,0:
JASS:
function Trig_DoubleCast_Actions takes unit c,unit t,unit d returns nothing
    local real x = GetUnitX(c)
    local real x2 = GetSpellTargetX()
    local string id = OrderId2String(GetUnitCurrentOrder(c))
 
    set d = CreateUnit(GetTriggerPlayer(),'hsor',x,GetUnitY(c),GetUnitFacing(c))
    call SetUnitState(d,UNIT_STATE_MANA,9999)
    call UnitAddAbility(d,GetSpellAbilityId())
    call UnitApplyTimedLife(d,'BTLF',2.)
 
    if x2 == 0 and x != 0 then
        call IssueImmediateOrder(d,id)
    elseif t != null then
        call IssueTargetOrder(d,id,t)
    else
        call IssuePointOrder(d,id,x2,GetSpellTargetY())
    endif
 
endfunction
 
function Trig_DoubleCast_Conditions takes nothing returns boolean
    if GetUnitAbilityLevel(GetTriggerUnit(),'A000') > 0 and IsUnitType(GetTriggerUnit(),UNIT_TYPE_HERO) then
        call Trig_DoubleCast_Actions(GetTriggerUnit(),GetSpellTargetUnit(),null)
    endif
    return false
endfunction
 
//===========================================================================
function InitTrig_DoubleCast takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(t,Condition(function Trig_DoubleCast_Conditions))
endfunction
 
Status
Not open for further replies.
Top