• 🏆 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!

How to make the correct emergence of unit(1) at the place of death of unit(2)?

Status
Not open for further replies.
Level 2
Joined
Apr 27, 2022
Messages
6
I want to make a unit(1) in a given rect. If you kill him, then a unit (2) with a certain animation appears in his place.
The appearance of unit (1) works, but for some reason the conditions for the appearance of unit (2) do not want to work in case of the death of unit (1).
I tried different ways, but nothing comes out.
Help me figure out how to do this?
  • Spawn boss
    • Events
      • Time - Elapsed game time is 5.00 seconds
    • Conditions
    • Actions
      • Unit - Create 1 TEST_UNIT for Neutral Extra at (Center of Boss spawn <gen>) facing Default building facing (270.0) degrees
      • Animation - Play (Last created unit)'s stand channel animation
        • Do Multiple ActionsFor each (Integer A) from 1 to 10, do (Actions)
          • Loop - Actions
            • Custom script: (exitwhen (TEST_UNIT_INTEGER Equal to (==) 0))
              • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Last created unit) Equal to (==) (Dying unit)
                • Then - Actions
                  • Set TEST_UNIT_INTEGER = 0
                • Else - Actions
                  • Set TEST_UNIT_INTEGER = 1
        • Do Multiple ActionsFor each (Integer A) from 1 to 10, do (Actions)
          • Loop - Actions
            • Custom script: (exitwhen (TEST_UNIT_INTEGER Equal to (==) 1))
              • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • TEST_UNIT_INTEGER Equal to (==) 0
                • Then - Actions
                  • Unit - Create 1 Lootbox for Neutral Passive at (Position of (Dying unit)) facing Default building facing (270.0) degrees
                  • Animation - Play (Last created unit)'s Birth animation
                  • Set TEST_UNIT_INTEGER = 1
                • Else - Actions
                  • Set TEST_UNIT_INTEGER = 2
 
Level 39
Joined
Feb 27, 2007
Messages
4,992
I see that you're trying something with the (Last created unit) Equal to (==) (Dying unit) but what you've written will just cause a thread crash in an infinite loop while it waits for two variables that aren't the same to become the same. Second, you are causing some memory leaks (unless your map is Lua with a garbage collector trigger enabled) by not cleaing up your point/location variables. If you have no idea what I'm talking about, read these threads: Memory Leaks, Things That Leak

Third, it's possible to use a specific unit event for when a specific unit dies, rather than a 'generic unit event'. This will only fire when that specific unit does the event, which may be helpful for what you are doing. However, to use this event you must either add it to a trigger with another trigger or refer to a unit that is pre-placed on the map. Here is how I would do it using a dynamically added event:

  • Make Unit
    • Events
      • -------- Whatever the relevant event is for you, maybe this: --------
      • Time - Elapsed game-time is 5.00 seconds
    • Conditions
    • Actions
      • Set TempPoint = (Center of Biss soawb <gen>)
      • Unit - Create 1 TEST_UNIT for Neutral Extra at TempPoint facing Default building facing degrees
      • Trigger - Add to Create Box <gen> the event (Unit - (Last created unit) Dies)
      • Custom script: call RemoveLocation(udg_TempPoint)
  • Create Box
    • Events
    • Conditions
    • Actions
      • Set TempPoint = (Position of (Triggering Unit))
      • Unit - Create 1 Lootbox for Neutral Passive at TempPoint facing Default building facing degrees
      • Custom script: call SetUnitX(bj_lastCreatedUnit, GetUnitX(GetTriggerUnit()))
      • Custom script: call SetUnitY(bj_lastCreatedUnit, GetUnitY(GetTriggerUnit()))
      • Animation - Play (last created unit)'s Birth animation
Note the 2 custom script lines in the Create Box trigger. The problem that you are having with position is probably that the GUI commands to create and move units to points do not ignore collision, so the newly created lootbox will always be pushed off the center of the dying unit. Custom script SetUnitX/Y will ignore collision and all that to place the unit exactly where you want. This is, though, only relevant if they interact, which they probably won't because the death of one creates the other. Try it without the 2 script lines first, and if it still doesn't work then try adding them.

There is another way you could structure this trigger, instead of manually adding events for all units that should create lootboxes when they die (because I'd guess there isn't just one). Add the units that should spawn boxes to a unit group, and then check if a dying unit is in that group. This is better in the long run because a 'any unit dies' event isn't particularly costly but triggers with many specific unit events can hog game memory (effectively also a memory leak):
  • Make Unit
    • Events
      • -------- Whatever the relevant event is for you, maybe this: --------
      • Time - Elapsed game-time is 5.00 seconds
    • Conditions
    • Actions
      • Set TempPoint = (Center of Biss soawb <gen>)
      • Unit - Create 1 TEST_UNIT for Neutral Extra at TempPoint facing Default building facing degrees
      • Unit Group - Add (last created unit to LootboxGroup)
      • Custom script: call RemoveLocation(udg_TempPoint)
  • Create Box
    • Events
      • Unit - A unit dies
    • Conditions
      • ((Triggering Unit) is in Lootbox Group) equal to True
    • Actions
      • Unit Group - Remove (Triggering Unit) from LootboxGroup
      • Set TempPoint = (Position of (Triggering Unit))
      • Unit - Create 1 Lootbox for Neutral Passive at TempPoint facing Default building facing degrees
      • Custom script: call SetUnitX(bj_lastCreatedUnit, GetUnitX(GetTriggerUnit()))
      • Custom script: call SetUnitY(bj_lastCreatedUnit, GetUnitY(GetTriggerUnit()))
      • Animation - Play (last created unit)'s Birth animation
 
Last edited:
Level 2
Joined
Apr 27, 2022
Messages
6
Thank you for such a voluminous answer! Everything works as it should! Even double thanks for the advice with unit groups) It's really easier this way. I know about the memory leak, but now I don't give it much importance at the current stage of map development.
 
Status
Not open for further replies.
Top