# [HELP] Create a unit at a unit's position in a unit group

Status
Not open for further replies.

#### Striker21

Level 9
Well, hi
I need you guys again...
I'm making a trigger that create a unit at a position of a unit group i picked, but created units are somehow not at picked units position
Check out my trigger:
• Trigger 1
• Events
• Unit - A unit Starts the effect of an ability
• Conditions
• (Ability being cast) Equal to Mirror Image
• Actions
• Set Casters[1] = (Triggering unit)
• Set POINTS[1] = (Position of Casters[1])
• Set Integers[1] = (Level of Mirror Image for Casters[1])
• Set Illusions_Groups[1] = (Units within 500.00 of POINTS[1] matching ((((Matching unit) is A structure) Equal to False) and ((((Matching unit) belongs to an ally of Player 1 (Red)) Equal to False) and (((Matching unit) is Magic Immune) Equal to False))))
• Unit Group - Pick every unit in Illusions_Groups[1] and do (Actions)
• Loop - Actions
• For each (Integer A) from 1 to (Number of units in Illusions_Groups[1]), do (Actions)
• Loop - Actions
• Set Effectedunits[(Integer A)] = (Picked unit)
• Set Points[(Integer A)] = (Position of Effectedunits[(Integer A)])
• Unit - Create 1 Illusion for (Owner of Casters[1]) at Points[(Integer A)] facing Default building facing degrees
• Set Illusions[(Integer A)] = (Last created unit)
• Unit Group - Add Illusions[(Integer A)] to Illusions_Groups[2]
• Unit - Order Illusions[(Integer A)] to Attack Effectedunits[(Integer A)]
• Unit - Add a (15.00 + (5.00 x (Real(Integers[1])))) second Generic expiration timer to Illusions[(Integer A)]
• Animation - Change Illusions[(Integer A)]'s vertex coloring to (100.00%, 100.00%, 100.00%) with 70.00% transparency
I know it leaks but i'll remove it after, why it's not working (the units created are not at the set position but it appears at my map's spawn point
Edit: @GangSpear: I copied my trigger and edit it, so there were some mistakes checked my trigger and it's the same point as "POINTS[1]"

Last edited:

#### GangSpear

Level 13
Unit Within POINTSS[33]? wtf is that lol.

#### Striker21

Level 9
Sr, there was some mistake . Edited the post

#### mckill2009

Level 29
remove those bloody arrays like >>> Effectedunits[(Integer A)]...use normal variables instead...

Owner of Casters[1]) >>> TriggerPlayer

remove the loop, picked unit is fine...

#### Bannar

Code Reviewer
Level 26
You do not need so many variables either, temporary references like Triggering unit or Picked unit are here for some case.

• Trigger 1
• Events
• Unit - A unit Starts the effect of an ability
• Conditions
• (Ability being cast) Equal to Mirror Image
• Actions
• Set POINTS[1] = (Position of (Triggering unit))
• Set Integers[1] = (Level of Mirror Image for (Triggering unit))
• Set Illusions_Groups[1] = (Units within 500.00 of POINTS[1] matching ((((Matching unit) is A structure) Equal to False) and ((((Matching unit) belongs to an ally of (Triggering player)) Equal to False) and (((Matching unit) is Magic Immune) Equal to False))))
• Unit Group - Pick every unit in Illusions_Groups[1] and do (Actions)
• Loop - Actions
• For each (Integer A) from 1 to (Number of units in Illusions_Groups[1]), do (Actions)
• Loop - Actions
• Set Points[(Integer A)] = (Position of (Picked unit))
• Unit - Create 1 Illusion for (Triggering player) at Points[(Integer A)] facing Default building facing degrees
• Unit Group - Add (Last created unit) to Illusions_Groups[2]
• Unit - Order (Last created unit) to Attack (Picked unit)
• Unit - Add a (15.00 + (5.00 x (Real(Integers[1])))) second Generic expiration timer to (Last created unit)
• Animation - Change (Last created unit)'s vertex coloring to (100.00%, 100.00%, 100.00%) with 70.00% transparency
• Custom script: call RemoveLocation(udg_Points[GetForLoopIndexA()])
• Custom script: call RemoveLocation(udg_Points[1])
However, I'm not sure what you want to archieve, since if your temporary group has for egzample 6 units, you gonna create 36 illusion (6 illusion per each unit).
If you want to summon just 1 for each unit in group remove For each (...) actions.

#### Striker21

Level 9
ok, problem is solved. Another trigger of mine move created units to a region that's why it's not working as i wanted. But thanks and rep

#### mckill2009

Level 29
I told you already that you dont need that arrays and loop, coz picked unit is already a loop...
• Untitled Trigger 001
• Events
• Unit - A unit Starts the effect of an ability
• Conditions
• (Ability being cast) Equal to Mirror Image
• Actions
• Set Casters = (Triggering unit)
• Set temploc = (Position of Casters)
• Set Integers = (Level of (Ability being cast) for Casters)
• Set Illusions_Group = (Units within 500.00 of temploc matching ((((Matching unit) is A structure) Equal to False) and ((((Matching unit) belongs to an ally of (Triggering player)) Equal to False) and (((Matching unit) is Magic Immune) Equal to False))))
• Unit Group - Pick every unit in Illusions_Group and do (Actions)
• Loop - Actions
• Set temploc = (Position of (Picked unit))
• Unit - Create 1 Footman for (Triggering player) at temploc facing Default building facing degrees
• Unit - Order (Last created unit) to Attack (Picked unit)
• Unit - Add a (15.00 + (15.00 + (Real(Integers)))) second Generic expiration timer to (Last created unit)
• Animation - Change (Last created unit)'s vertex coloring to (100.00%, 100.00%, 100.00%) with 70.00% transparency
• Custom script: call RemoveLocation(udg_temploc)
• Custom script: call RemoveLocation(udg_temploc)
• Custom script: call DestroyGroup(udg_Illusions_Group)

Status
Not open for further replies.

Replies
2
Views
361
[Trigger] Unit Group - Fail?
Replies
7
Views
721
Replies
12
Views
688
Replies
12
Views
770
Replies
2
Views
376