How do i code this?

NetherHawk

New Member
Reaction score
26
Ok i have coded an ability that creates an illusion at every enemy hero and the illusion will keep attacking that specific enemy hero.

i have a function that groups all these enemy heroes and sets them to a variable -- Hero[A] where a is an integer variable.

once this is done, a dummy is spawned to create an illusion of the caster.

Hence i have another trigger that registers when a unit is summoned having the illusion buff. The Illusion is then moved to the Hero[A] position. How do i set the target hero for this summoned illusion.

Ive tried every time the trigger is registered to set A = A - 1, however this way only 1 hero is attacked by the illusion, the rest are moved to the centre of the map.


JASS:
scope Haunt initializer Init

//Objects Used:
// 'A045' = Haunt (Spectre : Mercurial)
// 'A046' = Reality (Spectre : Mercurial)
// 'A047' = Haunt Effect
// 'B028' = Haunt Illusion Buff

globals
    private unit Hcaster
    private boolean Hboolean    
    private unit array Htarget    
    private integer Hint
endglobals

private struct haunt
    unit hx
    unit ht
    real hr
    
    method onDestroy takes nothing returns nothing
        set .ht = null
        set .hx = null
    endmethod
endstruct

private function Haunt_Conditions takes nothing returns boolean
    return GetLearnedSkill() == 'A045'
endfunction

private function Haunt_Check takes nothing returns boolean
    return GetSpellAbilityId() == 'A045'
endfunction

private function Haunt_Illusion takes nothing returns boolean
    return GetUnitAbilityLevel(GetSummonedUnit(),'B028') > 0
endfunction

private function Haunt_Filter takes nothing returns boolean  
    local unit f = GetFilterUnit()
    local unit d
    
    if IsUnitType(f,UNIT_TYPE_HERO) == true and IsUnitEnemy(f,GetOwningPlayer(Hcaster)) == true then
        set Hint = Hint + 1
        set Htarget[Hint] = f   // the targets are set here
        set d = CreateUnit(GetOwningPlayer(Hcaster),'h00A',GetUnitX(Hcaster),GetUnitY(Hcaster),bj_UNIT_FACING)
        call SetUnitInvulnerable(d,true)
        call UnitAddAbility(d,'A047')
        call SetUnitAbilityLevel(d,'A047',GetUnitAbilityLevel(Hcaster,'A045'))
        call IssueTargetOrderById(d,852274,Hcaster)
        call UnitApplyTimedLife(d,'BTLF',2.)        
        set Hboolean = true        
    endif
    
    set f = null
    set d = null
    return false
endfunction

private function Haunt_Sound takes nothing returns nothing
  // there is a groupenumunits in range function here with Haunt_Filter as the boolexpr
  // this trigger creates a sound if there are enemy heroes detected, the sound is always played. so its working. no necessary
endfunction

private function Haunt_Chase takes nothing returns boolean
   // i removed this as it is not necessary
endfunction

private function Haunt_Main takes nothing returns nothing // this is the actions when a summon is registered.
    local haunt h = haunt.create()
    local trigger th
    local real x
    local real y    
        
    set h.hx = GetSummonedUnit()
    set h.ht = Htarget[Hint]      // how do i set this target? i either get 1 target or all having the same target.   
    set Hint = Hint - 1  
    set h.hr = 0.
        
    call SetUnitPathing(h.hx,false)
    call SetUnitMoveSpeed(h.hx,400)
    set x = GetUnitX(h.ht)
    set y = GetUnitY(h.ht)
    call SetUnitPosition(h.hx,x,y)
    call SetUnitVertexColor(h.hx,255,255,255,50)
    call PauseUnit(h.hx,true)
    
    set th = CreateTrigger()
    call SetTriggerStructA(th,h)
    call TriggerRegisterUnitEvent(th,h.hx,EVENT_UNIT_ISSUED_TARGET_ORDER)
	call TriggerRegisterUnitEvent(th,h.hx,EVENT_UNIT_ISSUED_POINT_ORDER)
	call TriggerRegisterUnitEvent(th,h.hx,EVENT_UNIT_DEATH)
	call TriggerRegisterUnitEvent(th,h.ht,EVENT_UNIT_DEATH)
	call TriggerRegisterTimerEvent(th,0.5,true)
	call TriggerAddCondition(th,Condition(function Haunt_Chase))
    
    set th = null
endfunction

private function Haunt_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local trigger tr    
    local trigger tx
    
    if GetUnitAbilityLevel(u,'A045') == 1 then
        set tr = CreateTrigger()
        call TriggerRegisterUnitEvent(tr,u,EVENT_UNIT_SPELL_EFFECT)
        call TriggerAddCondition(tr,Condition(function Haunt_Check))
        call TriggerAddAction(tr,function Haunt_Sound)
        
        set tx = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(tx,EVENT_PLAYER_UNIT_SUMMON)
        call TriggerAddCondition(tx,Condition(function Haunt_Illusion))
        call TriggerAddAction(tx,function Haunt_Main)
        
        call UnitAddAbility(u,'A046')
    endif
    
    set tr = null    
    set tx = null
    set u = null
endfunction

private function Init takes nothing returns nothing
    set gg_trg_Haunt = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(gg_trg_Haunt,EVENT_PLAYER_HERO_SKILL)
    call TriggerAddCondition(gg_trg_Haunt, Condition(function Haunt_Conditions))
    call TriggerAddAction(gg_trg_Haunt,function Haunt_Actions)
    call CreateSound("Abilities\\Spells\\Other\\ANsa\\SacrificeUnit.wav",false,false,false,10,10,"DefaultEAXON")
endfunction

endscope
 

NetherHawk

New Member
Reaction score
26
sorry i found a solution, i created a struct which contains the target unit every time a suitable filter unit is found and attach it to an individual trigger. Mods can delete this thread.
 
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