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

Respawn System Won't Respawn Flying Units

Status
Not open for further replies.
Level 1
Joined
Aug 4, 2019
Messages
4
Hey guys, I'm having a really frustrating problem here, I've been trying to make a respawn system for my map for the past few days and no matter what I do I can't get flying units to work.

I tried many different ways, my first respawn system was like this:
  • Respawn System 1
    • Events
      • Unit - A unit owned by Neutral Hostile Dies
      • Unit - A unit owned by Neutral Passive Dies
    • Conditions
    • Actions
      • Wait 5.00 seconds
      • Unit - Create 1 (Unit-type of (Triggering unit)) for (Triggering player) at (Position of (Triggering unit)) facing (Facing of (Triggering unit)) degrees
Which I realized respawns the unit where they died and not where they spawned so I stopped using it.

I later figured out how to use hashtables and came up with this new respawn system.
  • Map Initialization
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- Setup Respawn System --------
      • Hashtable - Create a hashtable
      • Unit Group - Pick every unit in (Units owned by Neutral Hostile) and do (Hashtable - Save Handle Of(Position of (Picked unit)) as 0 of (Key (Picked unit)) in (Last created hashtable))
      • Unit Group - Pick every unit in (Units owned by Neutral Hostile) and do (Hashtable - Save (Facing of (Picked unit)) as 1 of (Key (Picked unit)) in (Last created hashtable))
      • Unit Group - Pick every unit in (Units owned by Neutral Passive) and do (Hashtable - Save Handle Of(Position of (Picked unit)) as 0 of (Key (Picked unit)) in (Last created hashtable))
      • Unit Group - Pick every unit in (Units owned by Neutral Passive) and do (Hashtable - Save (Facing of (Picked unit)) as 1 of (Key (Picked unit)) in (Last created hashtable))[/code]
  • [code]Respawn System 2
    • Events
      • Unit - A unit owned by Neutral Hostile Dies
      • Unit - A unit owned by Neutral Passive Dies
    • Conditions
    • Actions
      • Wait 5.00 seconds
      • Unit - Create 1 (Unit-type of (Triggering unit)) for (Triggering player) at (Load 0 of (Key (Triggering unit)) in (Last created hashtable)) facing (Load 1 of (Key (Triggering unit)) from (Last created hashtable)) degrees
      • -------- Need to save the position again or they won't respawn again. --------
      • Hashtable - Save Handle Of(Position of (Last created unit)) as 0 of (Key (Last created unit)) in (Last created hashtable)
      • Hashtable - Save (Facing of (Last created unit)) as 1 of (Key (Last created unit)) in (Last created hashtable)
This one worked the way I wanted it to, it respawns the unit where they spawned and it saves them again so they can be killed over and over. But there was still 1 problem... it won't respawn flying units for some reason, it works after 5 seconds for ground units but when I kill a flying unit like a Gryphon Rider I wait 5 seconds and they never respawn.

I double checked the unit, its owned by right player (Neutral Hostile) its the same the ground units in every way except that its flying. So I started to think maybe it just can't use the same position of ground units so I tried another way...
  • Map Initialization
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- New way of saving positions. --------
      • Hashtable - Create a hashtable
      • Unit Group - Pick every unit in (Units owned by Neutral Hostile) and do (Hashtable - Save (X of (Position of (Picked unit))) as 0 of (Key (Picked unit)) in (Last created hashtable))
      • Unit Group - Pick every unit in (Units owned by Neutral Hostile) and do (Hashtable - Save (Y of (Position of (Picked unit))) as 1 of (Key (Picked unit)) in (Last created hashtable))
      • Unit Group - Pick every unit in (Units owned by Neutral Hostile) and do (Hashtable - Save (Facing of (Picked unit)) as 2 of (Key (Picked unit)) in (Last created hashtable))
      • Unit Group - Pick every unit in (Units owned by Neutral Passive) and do (Hashtable - Save (X of (Position of (Picked unit))) as 0 of (Key (Picked unit)) in (Last created hashtable))
      • Unit Group - Pick every unit in (Units owned by Neutral Passive) and do (Hashtable - Save (Y of (Position of (Picked unit))) as 1 of (Key (Picked unit)) in (Last created hashtable))
      • Unit Group - Pick every unit in (Units owned by Neutral Passive) and do (Hashtable - Save (Facing of (Picked unit)) as 2 of (Key (Picked unit)) in (Last created hashtable))
  • Respawn System 3
    • Events
      • Unit - A unit owned by Neutral Hostile Dies
      • Unit - A unit owned by Neutral Passive Dies
    • Conditions
    • Actions
      • Wait 5.00 seconds
      • Unit - Create 1 (Unit-type of (Triggering unit)) for (Triggering player) at (Point((Load 0 of (Key (Triggering unit)) from (Last created hashtable)), (Load 1 of (Key (Triggering unit)) from (Last created hashtable)))) facing (Load 2 of (Key (Triggering unit)) from (Last created hashtable)) degrees
      • -------- Need to save the position again or they won't respawn again. --------
      • Hashtable - Save (X of (Position of (Last created unit))) as 0 of (Key (Last created unit)) in (Last created hashtable)
      • Hashtable - Save (Y of (Position of (Last created unit))) as 1 of (Key (Last created unit)) in (Last created hashtable)
      • Hashtable - Save (Facing of (Last created unit)) as 2 of (Key (Last created unit)) in (Last created hashtable)
It worked exactly the same as the old respawn system, it worked for ground units but it doesn't work for flying units...

At this point I'm getting really frustrated, I tried just making a simple chat command to spawn a Gryphon Rider at my position and that works fine so its not the create unit action that's bugged, so the hashtable must not be saving the position of flying units for some reason, I tried changing pick units owned by player to pick all units in entire map and that still does the same thing, it works for ground units but not for flying units, I tried seeing if there was a Z value or elevation or something but the create unit action doesn't use those values, it only uses a point and facing so I don't know what the problem is, nothing I do will get flying units to respawn...

Please help. I've been a lurker here for years but I finally had to make an account to get help for this problem, any help would be much appreciated.
 
Last edited:
Level 39
Joined
Feb 27, 2007
Messages
4,994
  • Use [trigger][/trigger] tags: How To Post Your Trigger
  • You are leaking lots of groups and locations: Things That Leak
  • Don't use the Map Init event; if too many things use it the init thread can crash and not everything will run. Instead use an elapsed game-time = 0.10 event.
  • The way you are doing unit group loops is silly--instead of multiple Pick actions, use the Pick .. and do (Actions) that allows multiple lines inside the pick.
  • You don't actually need to use a hashtable for this information, you can get by with some parallel arrays. Here's how I would do it:
  • Events
    • Time - Elapsed game-time is 0.10 seconds
  • Conditions
  • Actions
    • Set CreepCount = 0
    • Custom script: set bj_wantDestroyGroup = true
    • Set TempGroup = (Units owned by Neutral Hostile)
    • Custom script: set bj_wantDestroyGroup = true //cleans leak in next line
    • Unit Group - Add all units of (Units owned by Neutral Passive) to TempGroup
    • Custom script: set bj_wantDestroyGroup = true //so TempGroup is automatically destroyed after the next pick line
    • Unit Group - Pick every unit in TempGroup and do (Actions)
      • Loop - Actions
        • Set CreepCount = CreepCount + 1
        • Set CreepU[CreepCount] = (Picked Unit)
        • Set CreepT[CreepCount] = (Unit-type of CreepU[CreepCount]) //needed in case some creeps decay while the 5s wait to respawn them happens
        • Set CreepL[CreepCount] = (Position of CreepUnit[CreepCount])
        • Set CreepF[CreepCount] = (Facing of CreepUnit[CreepCount])
        • Set CreepO[CreepCount] = (Owner of CreepUnit[CreepCount])
        • Custom script: call RemoveLocation(udg_TempPoint) //clean point leak
  • Events
    • Unit - A unit owned by Neutral Hostile dies
    • Unit - A unit owned by Neutral Passive dies
  • Conditions
  • Actions
    • Custom script: local integer udg_CreepSpawn //This shadows the global CreepSpawn variable locally so it isn't overwritten. It must be the first line of the trigger
    • For each (Integer A) from 1 to CreepCount do (Actions)
      • Loop - Actions
        • If (All conditions are true) then do (Then actions) else do (Else actions)
          • If - Conditions
            • (Triggering Unit) equal to CreepU[(Integer A)]
          • Then - Actions
            • Set CreepSpawn = (Integer A)
          • Else - Actions
    • Wait 5.00 seconds
    • Unit - Create 1 CreepT[CreepSpawn] for CreepO[CreepSpawn] at CreepL[CreepSpawn] facing CreepF[CreepSpawn] degrees
    • Set CreepU[CreepSpawn] = (Last created unit)
Here's an explanation of the local variable shadowing: local udg_
 
Last edited:
Level 1
Joined
Aug 4, 2019
Messages
4
Thank you for all of the tips, I didn't know that I had so many mistakes. I never looked at any tutorials for War3Edit, I was already familiar with other game engines and flow graphs and just jumped right in. I will start working on correcting all of these and come back with the results later.
 
Last edited:
Level 1
Joined
Aug 4, 2019
Messages
4
So... I took all the advice, learned a lot of new things, came up with a completely new respawn system.

  • Post Initialization
    • Events
      • Time - Elapsed game time is 0.10 seconds
    • Conditions
    • Actions
      • -------- Setup Respawn System --------
      • Set UnitGroup = (Units owned by Neutral Hostile)
      • Unit Group - Add all units of (Units owned by Neutral Passive) to UnitGroup
      • Unit Group - Pick every unit in UnitGroup and do (Actions)
        • Loop - Actions
          • Set Creep_Z = (Creep_Z + 1)
          • Unit - Set the custom value of (Picked unit) to Creep_Z
          • Custom script: set udg_Creep_X[udg_Creep_Z] = GetUnitX(GetEnumUnit())
          • Custom script: set udg_Creep_Y[udg_Creep_Z] = GetUnitY(GetEnumUnit())
      • Custom script: call DestroyGroup (udg_UnitGroup)
      • -------- Clean up this trigger after everything is done. --------
      • Custom script: call DestroyTrigger (GetTriggeringTrigger())
  • Respawn System
    • Events
      • Unit - A unit Dies
    • Conditions
      • (((Owner of (Triggering unit)) Equal to Neutral Hostile) and (((Triggering unit) is Summoned) Not equal to True)) or (((Owner of (Triggering unit)) Equal to Neutral Passive) and (((Triggering unit) is Summoned) Not equal to True))
    • Actions
      • Wait 10.00 seconds
      • Unit - Create 1 (Unit-type of (Triggering unit)) for (Triggering player) at ((Center of (Entire map)) offset by (Creep_X[(Custom value of (Triggering unit))], Creep_Y[(Custom value of (Triggering unit))])) facing (Random angle) degrees
      • Unit - Set the custom value of (Last created unit) to (Custom value of (Triggering unit))
And guess what... it works EXACTLY the same as my old respawn system, it works for ground units but it doesn't work for flying units.... omg jeeeeeeeeeeeeeeeeeeeeeeeeeeeeez lol

I'm thinking the problem has something to do with (Triggering unit) it doesn't remember the unit that dies after the Wait command, but for some reason it only does that with some units, not all units, particularly flying units for some reason...

I'm going to have to try something new, I'm thinking of spawning the mobs right away but sending them to a "prison" and then moving them in place after the wait command, that way any references to the unit don't get lost after the wait command.
 
Level 39
Joined
Feb 27, 2007
Messages
4,994
If the flying units are something like harpies that explode on death and leave no corpse, then yeah that could be the reason. If you look, you’ll notice I addressed this possible issue with my suggested triggers using a local variable to store the information during the wait. You can adapt this method to your trigger, but note just storing the unit will not work; you will actually have to store its type, since trying to compute that would return 0 if the unit doesn’t exist after the wait.

You’re still leaking many locations and it would be better just to store those instead of storing X/Y values and then generating a new location with an offset from map center.
 
Status
Not open for further replies.
Top