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

[Trigger] [Problem] Unit Respawn Code (Mob Respawn)

Status
Not open for further replies.
Level 3
Joined
Dec 31, 2008
Messages
46
[Problem] Unit Respawn Code (Mob Respawn) [NOT SOLVED]

Its difficult to explain what's going wrong with these triggers but I will try.

I tried to apply this into the map I'd currently working on, but some reason it just... glitches up. I have 3 test units set up and it'll respawn them all once, with 2 of the enemies in the right location, but one will be in the wrong location (at the location of one of the other ones) and if they're killed again they just won't respawn. This is with all 3 of them dying in the save time window as the first one.

I'd appreciate any help on this, I've been working on it for a while, and I'd really like to be able to set this up and give it out to everyone to use, but sadly I'm having a really difficult time, both with this, and real life. As I previously mentioned, any help on this would be great.

  • Unit Respawn Init
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set HostileUnitGroup = (Units owned by Player 11 (Dark Green))
      • Unit Group - Pick every unit in HostileUnitGroup and do (Actions)
        • Loop - Actions
          • Set i = (i + 1)
          • Set HostileUnit[i] = (Picked unit)
          • Set HostileUnitType[i] = (Unit-type of (Picked unit))
          • Set HostileUnitXY[i] = (Position of (Picked unit))
          • Set HostileAngle[i] = (Facing of (Picked unit))
          • Custom script: set udg_HostileRezTimer[udg_i] = CreateTimer()
          • Unit - Remove (Picked unit) from the game
          • Countdown Timer - Start HostileRezTimer[i] as a One-shot timer that will expire in (1.00 + ((Real(i)) x 0.05)) seconds
          • Set HostileUnitIsDead[i] = True
          • Trigger - Add to Unit Respawn <gen> the event (Time - HostileRezTimer[i] expires)
      • Set UnitCount = i
  • Unit Death
    • Events
      • Unit - A unit owned by Player 11 (Dark Green) Dies
    • Conditions
    • Actions
      • Game - Display to (All players) the text: Target died
      • For each (Integer i) from 1 to UnitCount, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • HostileUnit[i] Equal to (Triggering unit)
            • Then - Actions
              • Game - Display to (All players) the text: Target found
              • Set j = i
              • Set i = UnitCount
            • Else - Actions
      • Unit - Remove (Triggering unit) from the game
      • Countdown Timer - Start HostileRezTimer[j] as a One-shot timer that will expire in 90.00 seconds
      • Set HostileUnitIsDead[j] = True
  • Unit Respawn
    • Events
    • Conditions
    • Actions
      • Game - Display to (All players) the text: Target respawn
      • For each (Integer i) from 1 to UnitCount, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Remaining time for HostileRezTimer[i]) Equal to 0.00
              • HostileUnitIsDead[i] Equal to True
            • Then - Actions
              • Game - Display to (All players) the text: Target found
              • Unit - Create 1 HostileUnitType[i] for Player 11 (Dark Green) at HostileUnitXY[i] facing HostileAngle[i] degrees
              • Set HostileUnit[i] = (Last created unit)
              • Set HostileUnitIsDead[i] = False
              • Set i = UnitCount
            • Else - Actions
 
Last edited:
Level 25
Joined
Sep 26, 2009
Messages
2,381
First trigger:
If you have this:
  • Set TempLoc = Position of (unit)
  • Set Loc1 = TempLoc
Then TempLoc and Loc1 point at one and the very same location; it does not create new location.

Thus if you have this
  • Set TempLoc = Position of (unit)
  • Set Loc1 = TempLoc
  • Custom script: call RemoveLocation(udg_TempLoc)
then both TempLoc and Loc1 will point at nothing (will point at null), because both these variables pointed at the same location (better said: at location with same ID).

Also, having the custom script outside the group loop block means that you will remove only the location which was stored inside TempLoc1 last.
Thus after the first trigger is finished, you will have created (n-1) locations for n units, because you remove the n-th location via custom script.

Also, timers do not cease to exist once they expire.
A one-shot timer means that the timer expires and it won't start again, unless a trigger action forces it to start. On the other hand, repeating timer will expire and start anew automatically and will continue this cycle unless paused/ordered to be one-shot timer.

So using
  • Custom script: set udg_HostileRezTimer[udg_i] = CreateTimer()
actually causes leak, because the timer saved inside this variable still exists, yet you make the variable point to the newly created timer, so you lose all pointers to the old timer.

---
Possible problems may be:
Is the unit created at position of other unit or is it actually center of map?
Are your test units same unit-types or different?

I would do this myself through hashtable.
 
Level 3
Joined
Dec 31, 2008
Messages
46
First trigger:
If you have this:
  • Set TempLoc = Position of (unit)
  • Set Loc1 = TempLoc
Then TempLoc and Loc1 point at one and the very same location; it does not create new location.

Thus if you have this
  • Set TempLoc = Position of (unit)
  • Set Loc1 = TempLoc
  • Custom script: call RemoveLocation(udg_TempLoc)
then both TempLoc and Loc1 will point at nothing (will point at null), because both these variables pointed at the same location (better said: at location with same ID).

Also, having the custom script outside the group loop block means that you will remove only the location which was stored inside TempLoc1 last.
Thus after the first trigger is finished, you will have created (n-1) locations for n units, because you remove the n-th location via custom script.

Also, timers do not cease to exist once they expire.
A one-shot timer means that the timer expires and it won't start again, unless a trigger action forces it to start. On the other hand, repeating timer will expire and start anew automatically and will continue this cycle unless paused/ordered to be one-shot timer.

So using
  • Custom script: set udg_HostileRezTimer[udg_i] = CreateTimer()
actually causes leak, because the timer saved inside this variable still exists, yet you make the variable point to the newly created timer, so you lose all pointers to the old timer.

---
Possible problems may be:
Is the unit created at position of other unit or is it actually center of map?
Are your test units same unit-types or different?

I would do this myself through hashtable.

Same Units because I didn't think about it, give me a few and I'll give it a shot to fix it real quick with what you posted.

EDIT: Alright, what you posted about the TempLoc1 helped fix the respawn location glitch. I swapped to 3 different units, they all spawn properly the first time, but not a 2nd time, I'll repost my triggers.

EDIT: I'm still not able to get this running, it will respawn them once. I really need some help with this.

EDIT: It looks like the problem is with the timer if statement, I'll continue to fiddle with it.\

EDIT: FIXED IT, the problem was with the fact that if you initialized a timer and paused it, then re assigned the variable a timer, as soon as it expires it takes on the paused timer. so when it was checking for an expired timer, it was already false, I fixed this by just adding a boolean to check if the unit is considered dead or not.
 
Last edited:
Status
Not open for further replies.
Top