This will give players gold for the units every 120 seconds. Will give 1 gold for a unit that has been alive for the entire 120 seconds aswell as for the unit that has only been alive for 1 second.
Variables
TempGroup = Unit Group that is used temporarily to not create leaks. Can be used by any other trigger as long as it is set, used and destroyed immediatly without any waits.
Gold = Integer with an array equal to the number of players playing.
Every 120 seconds of game-time
Set TempGroup = Units in Playable match area matching matching unit is alive equal to true and matching unit-type of matching unit equal to Peasant or matching unit-type of matching unit equal to Footman or matching unit-type of matching unit equal to Rifleman
Pick every unit in TempGroup
Set Gold(Player number of (Owner of (Picked unit) = Gold(Player number of (Owner of (Picked unit) + 1
call DestroyGroup(udg_TempGroup)
Pick every player in (All Players)
Set property (Picked Player) current gold to (Picked Player) current gold + Gold(Player number of (Picked Player)
Set Gold(Player number of (Picked Player) = 0
The next one will add 1 gold when the count of all affected units reaches 120.
Variables
CashMoneeeeyGroup = Unit Group. Does not create a leak because we will always use it.
Int = Integer to keep track of player number easily and to make the trigger more effective. Integers do not leak.
GoldCount = Integer array with size of amount of players to keep track of when 1 gold should be added to the player.
Add to Group
-A unit enters Playable map area
-A unit is revived <- (May not be needed)
--Or any conditions are true
---Unit-type of triggering unit equal to Peasant
---Unit-type of triggering unit equal to Footman
---Unit-type of triggering unit equal to Rifleman
----Add triggering unit to CashMoneeeeyGroup
----If
----Trigger Periodic Gold is off
----Then
----Trigger turn on Periodic Gold
----Else
Remove from Group
-A unit dies
--Triggering unit is in CashMoneeeeyGroup
---Remove (Triggering unit) from CashMoneeeeyGroup
---If
---Number of units in CashMoneeeeyGroup = 0
---Then
---Trigger turn off Periodic Gold
---Else
(Does not work if the unit is Removed with Remove unit action)
Periodic Gold
-Every 1 seconds of game-time
--Pick every unit in CashMoneeeeyGroup
---Set Int = (Player number of (Owner of (Picked unit)
---Set GoldCount(Int) = GoldCount(Int) + 1
----If
----GoldCount(Int) greater than 119
----Then
----Set Set Player(Int) current gold to Player(Int) current gold + 1
----Set GoldCount(Int) = GoldCount(Int) - 120
----Else
(Can only give a maximum of 1 gold per second)
Probably a more effective way of doing it.
Variables
GoldUnits = Integer array with size equal to amount of players to keep track of the amount of units adding to the GoldCount
GoldCount
GoldForce = Player Group. Players who have a unit that gives gold
Increase GoldUnits
-A unit enters Playable map area
-A unit is revived
--Or any conditions are true
---Unit-type of triggering unit equal to Peasant
---Unit-type of triggering unit equal to Footman
---Unit-type of triggering unit equal to Rifleman
----Set GoldUnits(Player number of (Triggering player) = GoldUnits(Player number of (Triggering player) + 1
----If
----(Triggering Player) is in GoldForce equal to False
----Then
-------Add (Triggering Player) to GoldForce
-------If
-------Number of Players in (GoldForce) equal to 1
-------Then
-------Turn on Periodic Gold
-------Else
----Else
Decrease GoldUnits
-A unit dies
--Or any conditions are true
---Unit-type of triggering unit equal to Peasant
---Unit-type of triggering unit equal to Footman
---Unit-type of triggering unit equal to Rifleman
----Set GoldUnits(Player number of (Triggering player) = GoldUnits(Player number of (Triggering player) - 1
----If
----GoldUnits(Player number of (Triggering player) = 0
----Then
-------Remove (Triggering Player) from GoldForce
-------If
-------Number of Players in (GoldForce) equal to 0
-------Then
-------Turn off Periodic Gold
-------Else
----Else
Periodic Gold
-Every 1 seconds of game-time
--Pick every player in (GoldForce)
---Set Int = (Player number of (Picked Player)
---Set GoldCount(Int) = GoldCount(Int) + GoldUnits(Int)
----If
----GoldCount(Int) greater than 119
----Then
----Set Set Player(Int) current gold to Player(Int) current gold + 1
----Set GoldCount(Int) = GoldCount(Int) - 120
----Else
Yet another option would be to count all units GoldCount seperately and requires (I believe) a unit indexer. Or hashtable. This would be the most exact method of all I have listed.