How do I select mirror images for player?

afisakov

You can change this now in User CP.
Reaction score
37
I want to make it so that when a unit casts mirror image, the player automatically has both the casting hero and the images selected at the end of the ability.
This way the enemy can't spot real hero as the only one running away, and u don't get stuck behind ur images.

The default on this map is that only the hero is selected, not the images, so they tend to get in the way.

I have tried to make it myself, but game crashes from my version, maybe you can tell me where I went wrong?

Code:
function Trig_2mir_Conditions takes nothing returns boolean
    return (GetSpellAbilityId()=='A004') or (GetSpellAbilityId()=='A075')
endfunction

function ilorcaster takes nothing returns boolean
    return IsUnitIllusionBJ(GetFilterUnit())
endfunction

function selections takes player p returns nothing
    call SelectUnitAddForPlayer(GetEnumUnit(),GetOwningPlayer(GetEnumUnit()))
endfunction

function Trig_2mir_Actions takes nothing returns nothing
    call TriggerSleepAction(.5)
    set tp1=GetUnitLoc(GetTriggerUnit())
    set tg=GetUnitsInRangeOfLocMatching(300,tp1,Condition(function ilorcaster))
    call ForGroup(tg,function selections)
    call DestroyGroup(tg)
    call RemoveLocation(tp1)
endfunction
...
  set udg_trigger2mir=CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(udg_trigger2mir,EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(udg_trigger2mir,Condition(function Trig_2mir_Conditions))
    call TriggerAddAction(udg_trigger2mir,function Trig_2mir_Actions)
P.S.
When I did it without the wait, it just did nothing, prob because images were not made yet (perhaps casting time of spell itself?)

Thank you in advance for the help
 

Dameon

"All the power in the world resides in the eyes"
Reaction score
127
Trigger:
  • Untitled Trigger 001
    • Events
      • Unit - A unit Spawns a summoned unit
    • Conditions
    • Actions
      • Selection - Add (Summoned unit) to selection for (Owner of (Triggering unit))
 

dracolich

TH.net Regular
Reaction score
15
event - unit enter the playable map
unit type is equal to HERO ID and isUnitIllusion==true
add trigger unit to player selection (use localplayer())
 

afisakov

You can change this now in User CP.
Reaction score
37
event - unit enter the playable map
unit type is equal to HERO ID and isUnitIllusion==true
add trigger unit to player selection (use localplayer())

Can I please have some more help getting this to work.

I tried to do this but it doesn't seem to work, not sure what I did wrong.

Code:
function Trig_2mir_Conditions takes nothing returns boolean
    return IsUnitIllusionBJ(GetTriggerUnit()) and (GetUnitTypeId(GetTriggerUnit())=='O000' or GetUnitTypeId(GetTriggerUnit())=='E001')
endfunction
 
function Trig_2mir_Actions takes nothing returns nothing
    call SelectUnitAddForPlayer(GetTriggerUnit(),GetOwningPlayer(GetTriggerUnit()))
endfunction
Code:
    set udg_trigger2mir=CreateTrigger()
    call TriggerRegisterEnterRectSimple(udg_trigger2mir,GetPlayableMapRect())
    call TriggerAddCondition(udg_trigger2mir,Condition(function Trig_2mir_Conditions))
    call TriggerAddAction(udg_trigger2mir,function Trig_2mir_Actions)
Thanks for the help

P.S. I tried testing with a special effect
Code:
function Trig_2mir_Actions takes nothing returns nothing
    call SelectUnitAddForPlayer(GetTriggerUnit(),GetOwningPlayer(GetTriggerUnit()))
    set tp1=GetUnitLoc(GetTriggerUnit())
    call AddSpecialEffectLocBJ(tp1,"Abilities\\Spells\\Human\\MassTeleport\\MassTeleportTarget.mdl")
    call RemoveLocation(tp1)
endfunction
and it does show up, so the event and condition appear to be sound
 

Dameon

"All the power in the world resides in the eyes"
Reaction score
127
its better to use the one I posted, with the version you are using now it will run the trigger every time a unit enters the map area instead of just every time a unit is summoned, mirror images are summoned units, so basically you have a trigger running hundreds or even thousands of times when it only needs to be ran like 50 to 60. if you want jass and it to only run with mirror images just use this one instead.
JASS:
function Trig_ImageSelect_Conditions takes nothing returns boolean
    if ( not ( GetUnitTypeId(GetSummonedUnit()) == GetUnitTypeId(GetSummoningUnit()) ) ) then
        return false
    endif
    return true
endfunction
 
function Trig_ImageSelect_Actions takes nothing returns nothing
    call SelectUnitAddForPlayer( GetSummonedUnit(), GetOwningPlayer(GetSummoningUnit()) )
endfunction
 
//===========================================================================
function InitTrig_ImageSelect takes nothing returns nothing
    set gg_trg_ImageSelect = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_ImageSelect, EVENT_PLAYER_UNIT_SUMMON )
    call TriggerAddCondition( gg_trg_ImageSelect, Condition( function Trig_ImageSelect_Conditions ) )
    call TriggerAddAction( gg_trg_ImageSelect, function Trig_ImageSelect_Actions )
endfunction
 

afisakov

You can change this now in User CP.
Reaction score
37
Thank you very much !!

It works now :D

I used a slight modification of the code Dameon posted.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top