Say you have a map that involves multiple weighted storage cubes, but only one box dropper.
Triggering the box dropper every time a cube gets destroyed can cause interesting things if two cubes get destroyed simultaneously or near-simultaneously. For instance, you might end up with two cubes stuck inside the dropper (instead of the usual one cube that is waiting for the next trigger), or something else. Either way, while you're likely to get one cube back, you're not likely to get all of them.
My solution was this:
1. Create a math_counter. Give it an initial value of -1, min and max of 0.
2. On the env_entity_maker part of the boxdropper (i.e. CP4P_dropper_boxmaker_1 if you are using CP4P prefabs), add an output for:
My output named: OnEntitySpawned
Target: name_of_math_counter
Target Input: add
Target Value: 1
-
Create a logic_compare. Set its Initial Value to 0 and Compare Value to the minimum number of boxes that should be existing at the time.
For its outputs, add:
My output named: OnLessThan
<<stuff to trigger your boxdropper here. For example (CP4P): CP4P_boxdropper_trigger=>Trigger>> -
On the math_counter, add:
OutValue => name_of_logic_compare => SetValue
with no parameter override -
Create a trigger_multiple covering the area around the box dropper. Set its Delay Before Reset to 4.
The only Flags that should be set are "Client". For its outputs, add
OnTrigger => name_of_logic_compare => Compare -
On any object that destroys a box, add the appropriate outputs to Subtract 1 from the math_counter.
If all works well, you'll have a box dropper that will replenish destroyed (or not yet spawned) boxes at a rate of 1 every 4 seconds until the requisite number has been made.
Notes:
1. Make sure there's space for all your boxes to be created, else you may clog the dropper.
2. It's important that the math_counter start at -1 instead of 0, since the boxdropper has always spawned one more box than is really available (the box that is 'waiting' at the bottom)
3. I tried doing this without the logic_compare using min/max values on the counter and SetHitMin/SetHitMax trickery. Don't try it, it doesn't work. If a counter has a max of 3 and a min of 2 with OnHitMin set to change min to -1, and has a current value of 3 and receives two Subtract(1) events simultaneously, the second will be clamped (thus keeping it at a value of 2, not 1) before the SetHitMin event fires, thus only one replacement box will be issued.


Besides, I'm sure some idiot will manage to make a map where the triggers and logic are more costly than the physics and graphics, so it doesn't hurt to think about these things. (NB: I don't intend to be that idiot.)