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

Using Queue for Destructible Respawn

Status
Not open for further replies.
Level 2
Joined
Sep 19, 2008
Messages
25
I've been working on a system for my mod that respawns crates after they have been destroyed. They are much like random pots, boxes, or chests you break in games, where you find potions or gold. I've set up a trigger to detect initial crates (which are destructibles) and add them to an array of type 'destructible'. After being added, an event for is added to a second trigger, which fires when that destructible is destroyed.

What I thought would be the most efficient way of resurrecting the crates would be in the form of a queue. The only reason for this is because of the wait clause needed (about 60 seconds before the crate resurrects). I figured the queue might be the most logical way of doing this. I'm familiar with the concept, but I'm having a bit of trouble implementing it. Any help would be much appreciated :gg:

PS: I also wanted add that I'm not dealing with leaks right now. I'd rather find out what is possible before putting the time in to dealing with leaking.

  • Detect Initial Crates
    • Events
      • Time - Elapsed game time is 0.01 seconds
    • Conditions
    • Actions
      • Set iCrateCounter = 0
      • Destructible - Pick every destructible in (Playable map area) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Destructible-type of (Picked destructible)) Equal to Crates (CUSTOM)
            • Then - Actions
              • Set dARRAYCrateRespawn[iCrateCounter] = (Picked destructible)
              • Set iCrateCounter = (iCrateCounter + 1)
              • Trigger - Add to Crate Death <gen> the event (Destructible - (Picked destructible) dies)
              • Trigger - Add to Crate Respawn <gen> the event (Destructible - (Picked destructible) dies)
            • Else - Actions
      • Set iCrateCounter = 0
  • Crate Respawn
    • Events
    • Conditions
    • Actions
      • For each (Integer A) from 0 to 176, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Dying destructible) Equal to dARRAYCrateRespawn[(Integer A)]
            • Then - Actions
              • Set iARRAYCrateQueue[iCrateCounter] = (Integer A)
              • Set iCrateCounter = (iCrateCounter + 1)
              • Game - Display to (All players) the text: (String(iCrateCounter))
              • Wait 10.00 seconds
              • Destructible - Resurrect dARRAYCrateRespawn[iARRAYCrateQueue[0]] with (Max life of dARRAYCrateRespawn[iARRAYCrateQueue[0]]) life and Show birth animation
              • For each (Integer A) from 0 to iARRAYCrateQueue[iCrateCounter], do (Actions)
                • Loop - Actions
                  • Set iARRAYCrateQueue[(Integer A)] = iARRAYCrateQueue[((Integer A) + 1)]
              • Set iCrateCounter = (iCrateCounter - 1)
              • Game - Display to (All players) the text: (String(iCrateCounter))
              • Skip remaining actions
            • Else - Actions
What I have noticed so far is that it works with multiple crates waiting to be respawned, except the third one doesn't get resurrected. I may try to do some more testing and debug stuff, but I'm not very confident in my queuing knowledge :sad:

EDIT: Let me know if there are any parts that need explaining. I'm not much of a 'comment' person, and maybe that's part of my problem!

EDIT 2: So from what I've found from testing it further, is that if you create of stack a 3 or more (meaning destroying 3 or more creates before the first destroyed crate resurrects), the problem occurs. What happens is that the first two resurrect just fine and in order. On the third one, however, it skips the resurrection. Once the counter continues onto the fourth number, the third crate finally shows up. (This was the case with 3, 4, 5, 6, etc crates on the stack). So what happens after skipping the third count, it continues on the fourth count by resurrecting the third; and on the fifth count, resurrecting the fourth crate until the counter reaches zero again.

I've added the text code so you can see what the counter is doing as the stack is being filled and emptied.

EDIT 3: WOW! Ok so I feel stupid for not noticing that the For Each loop in the respawn trigger was looping one extra time! I spent way to much time on this and felt I needed some help, but I finally managed to work it out with some persistence. Looks like this one can be deleted or marked solve, doesn't matter to me, unless someone is looking to use queues in their code :)
 
Last edited:
Level 2
Joined
Sep 19, 2008
Messages
25
What would you recommend then? I mean, I guess I'll try going back through the 'Detect Crates' trigger and see if using a 'for each' loop would allow me to access the Crate[Integer A] in the respawn trigger, but I'm guessing IntegerA gets reset after being used.

Otherwise I make a variable for each crate, which I don't think is worth doing. I'm guessing no matter what, I'll need to iterate through the crates. Even if there were a Destructible Group variable type, it would still iterate through it. Otherwise maybe a separate matrix to distinguish dead and alive crates? Any suggestions?
 
Level 3
Joined
Aug 9, 2008
Messages
60
Why wouldn't you just do this?

  • Crate Respawn
    • Events
    • Conditions
    • Actions
      • Wait 10.00 seconds
      • Destructible - Resurrect (Dying destructible) with (Max life of (Last created destructible)) life and Hide birth animation
Really don't get the point of all the other crap you have in the function.
 
Level 2
Joined
Sep 19, 2008
Messages
25
Well doesn't using a wait action erase what ever is temporarily stored as dying destructible? I guess I always thought that's why one uses variables to store event responses like triggering unit and such. Did I have this wrong all along?
 
Status
Not open for further replies.
Top