Heimdal's method would be quite good if the exchange from the human to p12 and back to human didn't happen every trigger cycle. Currently, the marines change ownership at least every 2 game seconds, making the marines essentially impossible to control, since every trigger cycle all marines at the location will be deselected. To fix this, you would probably use a death-counter timer that restricted the triggers from running so often.
The
"simplest" way (the method that is easiest to understand) of counting the number of marines at a location is to make a trigger for each possible number of marines. This is the method that Killer2001 was proposing.
The "simplest" way of making triggers run slower than once every trigger cycle is to use a wait action:
| Trigger |
| Conditions: |
| ¤ Current Player brings exactly X marines to 'location'. |
| Actions: |
¤ Modify resources for Current Player: Add 2X ore.
|
¤ Wait 10000 milliseconds.
|
| ¤ Preserve Trigger. |
Make one of these triggers for each value of X from 1 up to the maximum number of marines in the location.
The "simplest" way also happens to be quite an inefficient method, because you may require over two hundred triggers just to achieve what you want to achieve. It can be reduced if you're happy to settle for giving minerals for the number of marines being in a small range, rather than being 'exactly' each number. This method is also dodgy because the wait action: (i) doesn't stop the other triggers from firing, but (ii) will stop any other wait actions from running for the same player whilst it is running.
A slightly better (but still considered newbish) method is to use a countdown timer instead of a wait action.
A better still but more difficult-to-understand method would be to implement a death counter timer. Check the tutorials.
An interesting solution would be to use the "command the most at" condition.
This would involve counting off each marine by creating one for the computer at the same location until the computer controlled just as many marines as the human player did - so commands (equally) the most marines at the location - and so for each marine created, you would give the human 2 minerals. Then remove all marines for the computer player.
| Trigger |
| Conditions: |
¤ Computer Player commands the least marines at 'location'.
|
| ¤ [Whatever conditions on the timing of these triggers] |
| Actions: |
¤ Create 1 marine for Computer Player at 'location'.
|
¤ Modify resources for Human Player: Add 2 ore.
|
| ¤ Preserve trigger. |
Copy the above trigger as many times as the maximum number of marines at the location will be, and then make:
| Trigger |
| Conditions: |
| ¤ Computer Player commands the most marines at 'location'. |
| Actions: |
¤ Remove all marines for Computer Player at 'location'.
|
¤ Modify resources for Human Player: Subtract 2 ore.
|
¤ [Restart whatever timing action you're using]
|
| ¤ Preserve trigger. |
We have to subtract 2 minerals because we've actually counted one more marine than there actually is at the location.
Even this method is quite restricted, because it would be hard to find enough space to fit both the computer's and human's marines in the same location.