Trigger help

Level 8
Joined
Nov 24, 2016
Messages
218
im doing trigger that if you pick a dialogue option your starting units and building will get replaced with alternative one, but for some reason my tree of life is
First of all displaced and second of all it destroys entangled gold mine. Any idea how i can start game with tree in right place and my custom made gold mine?
 

Attachments

  • 1737156972124.png
    1737156972124.png
    1.1 MB · Views: 13
  • 1737156992796.png
    1737156992796.png
    1 MB · Views: 13
  • 1737157194932.png
    1737157194932.png
    61.4 KB · Views: 13
Level 29
Joined
Sep 26, 2009
Messages
2,594
Ok, so you have two problems:
1. custom town hall unit's location is misplaced after replacing original town hall unit.
2. gold mine is no longer entangled after replacing original town hall unit.

Ad 1:
Misplacement happens due to Wisp units being too close to the town hall unit (most likely, they already entered the "blue" part of its pathing map).
What worked for me was to simply hide workers of that player, then replace town hall and finally unhide workers.
Second, a bit more scripted but more universal option, is to store town hall's position into variable, then replace the town hall, then move the town hall to the location given by variable (using custom script SetUnitX and SetUnitY commands) and finally hiding and unhiding the town hall (SetUnitX/Y does not update pathing map, but hiding and unhiding the structure does update it).

Here are examples for both options:
  • Test 1
    • Events
      • Player - Player 1 (Red) skips a cinematic sequence
    • Conditions
    • Actions
      • Set VariableSet WorkersGroup = (Units owned by Player 1 (Red) matching (((Matching unit) is A peon-type unit) Equal to True).)
      • Unit Group - Pick every unit in WorkersGroup and do (Actions)
        • Loop - Actions
          • Unit - Hide (Picked unit)
      • Unit - Replace Ancient of War 0002 <gen> with a Tree of Life using The old unit's relative life and mana
      • Unit Group - Pick every unit in WorkersGroup and do (Actions)
        • Loop - Actions
          • Unit - Unhide (Picked unit)
      • Custom script: call DestroyGroup(udg_WorkersGroup)
  • Test 2
    • Events
      • Player - Player 1 (Red) skips a cinematic sequence
    • Conditions
    • Actions
      • Set VariableSet TH = Ancient of War 0002 <gen>
      • Set VariableSet loc = (Position of TH)
      • Unit - Replace TH with a Tree of Life using The old unit's relative life and mana
      • Set VariableSet TH = (Last replaced unit)
      • Custom script: call SetUnitX(udg_TH, GetLocationX(udg_loc))
      • Custom script: call SetUnitY(udg_TH, GetLocationY(udg_loc))
      • Unit - Hide TH
      • Unit - Unhide TH

Ad 2:
Entangled Gold Mine is bound to the Tree of Life that entangled it. Replacing that Tree of Life is same as if you destroyed it during game -> Entangled Gold Mine will become a standard Gold Mine.
You can see here what happens when you start as a Night Elf player: Doc - MeleeStartingUnitsNightElf
Of note is this part of the script:
JASS:
set nearestMine = MeleeFindNearestMine(startLoc, bj_MELEE_MINE_SEARCH_RADIUS)
if (nearestMine != null) then
    // Spawn Tree of Life near the mine and have it entangle the mine.
    // Project the Tree's coordinates from the gold mine, and then snap
    // the X and Y values to within minTreeDist of the Gold Mine.
    set nearMineLoc = MeleeGetProjectedLoc(GetUnitLoc(nearestMine), startLoc, 650, 0)
    set nearMineLoc = MeleeGetLocWithinRect(nearMineLoc, GetRectFromCircleBJ(GetUnitLoc(nearestMine), minTreeDist))
    set tree = CreateUnitAtLoc(whichPlayer, 'etol', nearMineLoc, bj_UNIT_FACING)
    call IssueTargetOrder(tree, "entangleinstant", nearestMine)
...
So they determine the location of a nearby Gold Mine, create a Tree of Life next to it and then order that Tree of Life to cast "entangle instant" on the Gold Mine.

In your case, you already know the position, etc. since you are just replacing Tree of Life with your custom one. So what you just need to do is find the nearest Gold Mine and order your town hall to cast entangle instant:
  • Unit - Order Your_Custom_TreeOfLife to Night Elf Tree Of Life - Entangle (Instant) Some_Gold_Mine
 
Top