• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

event if unit leaves another unit

Status
Not open for further replies.
Level 3
Joined
Sep 5, 2019
Messages
33
Hey yall, im trying to make a summoned unit die if it goes to far from the summoning hero. Its based off the blood mages phoenix. right now i have a region that centers on the hero every second, and if the summoned unit leaves, it dies. it works correctly if the phoenix moves out of range, but if the phoenix stays still and the blood mage moves away, the phoenix doesnt die. I assume this is because the unit didnt leave the region, but the region moved away from it. Havent worked with moving regions before, i dont even know if thats the way to go about this.

Here are screenshots of the triggers:

Defines the summoned units variable (theres 3 levels to the ability, each summons the next level phoenix)
Screenshot (9).png

Centers the region on the hero
Screenshot (10).png

Kills the summoned unit if it leaves the region
Screenshot (11).png


Thanks for the help!!
 
Last edited:
Level 3
Joined
Sep 5, 2019
Messages
33
Okay, so I added a second Region that centers on the summoned unit, and if the Hero leaves that then it kills the summoned unit. So thats great! Now the summoned unit dies whether its the hero or unit leaving the others region. However, after killing and summoning a few times, it stopped working, and the unit never died no matter how far away it went, which leads me to believe theres a problem with the unit variable.

Also, in general, i try to avoid continuous period timers, but i see no other way to do this so here i am. If someone sees a different way to do it, i would appreciate suggestions.
 
Level 3
Joined
Sep 5, 2019
Messages
33
Also, some questions about the trigger. What will happen when the hero dies? the region stays where he died at and then changes when he respawns? Whats happens if the hero moves away while the phoenix is in egg form? i have also given this hero the Blink ability (teleporting short distances) what happens if he Blinks over the region boundary?
 
Level 39
Joined
Feb 27, 2007
Messages
5,016
Havent worked with moving regions before, i dont even know if thats the way to go about this.
No, it's not the right way. You should just calculate the distance between the 2 units and if it's greater than your threshold, kill the phoenix. Also you are leaking a point that you will need to clean up; here's a good resource to understand memory leaks: Things That Leak.

  • Events
    • Time - Every 1.00 seconds of game-time
  • Conditions
    • PhoenixUnit not equal to No Unit //so the trigger doesn't run when the unit doesn't exist
  • Actions
    • Set TempPoint1 = (Position of HeroMerlinU)
    • Set TempPoint2 = (Position of PhoenixUnit)
    • If (All conditions are true) then do (Then actions) else do (Else actions)
      • If - Conditions
        • (Distance between TempPoint1 and TempPoint2) greater than THRESHOLD //this is a real comparison
      • Then - Actions
        • Unit - Kill PhoenixUnit
        • Set PhoenixUnit = (No unit)
      • Else - Actions
    • Custom script: call RemoveLocation(udg_TempPoint1) //cleaning leaks
    • Custom script: call RemoveLocation(udg_TempPoint2) //change the names to match your variable names but keep the udg_ prefix
Note that this solution is not MUI; if you want that you'll have to use some arrayed variables. There's one scenario that can bug this out: what happens if the player casts the summon skill a second time while they already have a phoenix? Depending on what skill you based this summon on either the old one will be automatically killed (based on Rexxar's Summon Misha) or it won't (based on Summon Water Elemental). If a duplicate is created, the original summon will become untethered from the trigger.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,555
  • Phoenix Summon
    • Events
      • Unit - A unit Spawns a summoned unit
    • Conditions
      • Put your conditions here
    • Actions
      • Set PhoenixSummoner = (Summoning unit)
      • Set PhoenixSummon = (Summoned unit)
      • -------- - --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Phoenix Timer <gen> is on) Equal to False
        • Then - Actions
          • Trigger - Turn on Phoenix Timer <gen>
        • Else - Actions
  • Phoenix Timer
    • Events
      • Time - Every 0.50 seconds of game time
    • Conditions
    • Actions
      • Set PhoenixPoint1 = (Position of PhoenixSummoner)
      • Set PhoenixPoint2 = (Position of PhoenixSummon)
      • Set PhoenixDistance = (Distance between PhoenixPoint1 and PhoenixPoint2)
      • Custom script: call RemoveLocation (udg_PhoenixPoint1)
      • Custom script: call RemoveLocation (udg_PhoenixPoint2)
      • -------- - --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • PhoenixDistance Greater than 600.00
        • Then - Actions
          • Unit - Remove PhoenixSummon from the game
          • Trigger - Turn off (This trigger)
        • Else - Actions
  • Phoenix Dies
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Triggering unit) Equal to PhoenixSummon
    • Actions
      • Trigger - Turn off Phoenix Timer <gen>

@Pyrogasm lol, I was a moment too late
 

Attachments

  • Phoenix Test.w3x
    36 KB · Views: 22
Status
Not open for further replies.
Top