I have a setup where whenever an enemy unit is killed, it runs a trigger to check if it was the last enemy unit. However, if the last several units are killed simultaneously, it runs the check multiple times. I'm trying to figure out a way to make it so it can't fire more than once at a time. Suggestions?
You can create a boolean that goes true once the trigger fires and goes false 0.5 seconds later. This way, the trigger will have a "cooldown" of 0.5 seconds.
Do a pick every unit in playable map area. Then add them to a player group variable. In the same trigger run an IF/THEN/ELSE with IF - The player group variable you have = empty, THEN - Do whatever you want, defeat, victory, or w/e, ELSE - nothing here. Make sure to add the Any unit dies event, and a condition of Owner of dying unit = w/e player you want to be the enemy.
Edit: I'll make it more clear:
Events:
Any Unit Dies
Conditions:
OR any are true -
Dying Unit is an enemy of player X(put whatever condition you need here)
Actions:
Pick Every unit in map area belonging to Player Owner of Dying Unit
Add Picked Player to Enemy_Units
If/Then/Else
If - Enemy_Units = Empty unit group
Then - Defeat Player Owner of Dying Unit
Else -
That's it.
You can create a boolean that goes true once the trigger fires and goes false 0.5 seconds later. This way, the trigger will have a "cooldown" of 0.5 seconds.
As I see this thread has been pretty much wrapped up, the following message is more for future viewers than anything.
First, each trigger is run in a separate thread. They cannot directly communicate with each other. Realize that if more than one unit is killed at the same time, the threads will run at the same time. This could cause a variety of problems. For example, detecting when a wave of units has been depleted. In other words, refer to the following.
Unit 1 dies
Unit 2 dies
Trigger 1 runs
Trigger 2 runs
Trigger 1 checks conditions
Trigger 2 checks conditions
Trigger 1 sets boolean to false
What happens is that the first trigger will check the conditions. Before it can actually set the conditions to be false, the second thread will check the conditions. This means that both triggers are able to run.
To stop this from happening, you need to improvise. The first step is the same. In the initial conditions, make sure that the boolean is false. That is the first line of defense.
Once that returns true, use the random function to get a number (0.065-.5). Then, have the thread wait for that amount of time. Now, one of the threads will stop waiting before the other. With another if-then, check the conditions again. If the thread discovers another thread has been started, use the "wait until" command to wait until the boolean becomes true again.
Put all of that into a loop. Have a boolean "My Turn!" that is turned to "true" when the thread finally determines that no other threads are running.
If you have more than 5 threads that are being triggered at the same time (for example, you kill 10 zombies with 1 grenade on a zombie survival map) then you would probably want to add a second local boolean "My Turn, Again!" and a second loop. This way, if 2 threads return the same random number, they will be caught by the second loop.
This entire process would take about 1-3 seconds to complete, on average. It is the most secure system there is, because I don't think that Galaxy has thread locking or synchronized threads.
Also DrakenStark, do not resurrect threads in that way. Post a question and other information if you feel a topic needs to be discussed more.
I have a setup where whenever an enemy unit is killed, it runs a trigger to check if it was the last enemy unit. However, if the last several units are killed simultaneously, it runs the check multiple times. I'm trying to figure out a way to make it so it can't fire more than once at a time. Suggestions?
@schiZm22: Go
You can create a boolean that goes true once the trigger fires and goes false 0.5 seconds later. This way, the trigger will have a "cooldown" of 0.5 seconds.
Events: Any Unit Dies Conditions: OR any are true - Dying Unit is an enemy of player X(put whatever condition you need here) Actions: Pick Every unit in map area belonging to Player Owner of Dying Unit Add Picked Player to Enemy_Units If/Then/Else If - Enemy_Units = Empty unit group Then - Defeat Player Owner of Dying Unit Else -
That's it.Using this method worked perfectly. Thanks a lot.
lol thats what i do too :P Very easy peasy japanesie squeezy?
If your trying to do stuff when a unit is killed.... you would want it to fire multiple time simutaneously... or youll miss unit deaths....
what are you trying to do in the first place when units die?
@schiZm22: Go
add a wait and then set it to false?
As I see this thread has been pretty much wrapped up, the following message is more for future viewers than anything.
First, each trigger is run in a separate thread. They cannot directly communicate with each other. Realize that if more than one unit is killed at the same time, the threads will run at the same time. This could cause a variety of problems. For example, detecting when a wave of units has been depleted. In other words, refer to the following.
What happens is that the first trigger will check the conditions. Before it can actually set the conditions to be false, the second thread will check the conditions. This means that both triggers are able to run.
To stop this from happening, you need to improvise. The first step is the same. In the initial conditions, make sure that the boolean is false. That is the first line of defense.
Once that returns true, use the random function to get a number (0.065-.5). Then, have the thread wait for that amount of time. Now, one of the threads will stop waiting before the other. With another if-then, check the conditions again. If the thread discovers another thread has been started, use the "wait until" command to wait until the boolean becomes true again.
Put all of that into a loop. Have a boolean "My Turn!" that is turned to "true" when the thread finally determines that no other threads are running.
If you have more than 5 threads that are being triggered at the same time (for example, you kill 10 zombies with 1 grenade on a zombie survival map) then you would probably want to add a second local boolean "My Turn, Again!" and a second loop. This way, if 2 threads return the same random number, they will be caught by the second loop.
This entire process would take about 1-3 seconds to complete, on average. It is the most secure system there is, because I don't think that Galaxy has thread locking or synchronized threads.
Also DrakenStark, do not resurrect threads in that way. Post a question and other information if you feel a topic needs to be discussed more.
Great to be back and part of the community again!