The problem with the map you mentioned is that it doesn't check if a building is completely constructed. It gives gold to players as soon as such structures enter the map. However, there's an easy way to avoid this problem.
All right, here's a simple example where I give gold to players who own one or more farms:
-
Income Register Structure
-
Events
-
Unit - A unit Finishes construction
-
Conditions
-
(Unit-type of (Triggering unit)) Equal to Farm
-
Actions
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
-
(Number of units in Income_Group) Equal to 0
-
Then - Actions
-
Trigger - Turn on Income Loop <gen>
-
Else - Actions
-
Unit Group - Add (Triggering unit) to Income_Group
I am adding the farm to the group, but prior to that, I check if there's no unit in the group. That means the Loop trigger is turned off. So, turn it on.
-
Income Unregister Structure
-
Events
-
Conditions
-
((Triggering unit) is in Income_Group) Equal to True
-
Actions
-
Unit Group - Remove (Triggering unit) from Income_Group
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
-
(Number of units in Income_Group) Equal to 0
-
Then - Actions
-
Trigger - Turn off Income Loop <gen>
-
Else - Actions
If a farm gets destroyed, you simply remove it from the group. After that, check if there's no units left in the group. If yes, then turn the loop trigger off.
-
Income Loop
-
Events
-
Time - Every 2.00 seconds of game time
-
Conditions
-
Actions
-
Custom script: set udg_localPlayer = GetLocalPlayer()
-
Unit Group - Pick every unit in Income_Group and do (Actions)
-
Loop - Actions
-
Set buildPlayer = (Owner of (Picked unit))
-
-------- Create Floating Text --------
-
Floating Text - Create floating text that reads |cffffcc00+2|r above (Picked unit) with Z offset 0.00, using font size 10.00, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
-
Set lastTextTag = (Last created floating text)
-
Floating Text - Set the velocity of lastTextTag to 64.00 towards 90.00 degrees
-
Floating Text - Change lastTextTag: Disable permanence
-
Floating Text - Change the fading age of lastTextTag to 0.75 seconds
-
Floating Text - Change the lifespan of lastTextTag to 1.50 seconds
-
-------- Show it for only one player --------
-
Custom script: if udg_localPlayer != udg_buildPlayer then
-
Custom script: call SetTextTagVisibility(udg_lastTextTag, false)
-
Custom script: endif
-
-------- Do whatever actions you want to do --------
-
Player - Add 2 to buildPlayer Current gold
You probably noticed that I used the
GetLocalPlayer() function in order to hide the floating text for other players. I also used another player variable to NOT call the ( Owner of (unit) ) multiple times.
However, I believe that for this example only, this is quite an exaggeration. I recommend that you do this for triggers where you call the same function more than 4~5 times in a row. The same applies for other functions such as
Picked Unit,
Triggering Unit, Last Created Floating Text, etc...
NOTE: Floating texts are also known as
text tag. I just named that variable as lastTextTag, because I'm lazy.