- 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
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.

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
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

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
-
-
-
-
-

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: