• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Trigger : 3 kind of units giving me gold per minut.

Status
Not open for further replies.
Level 7
Joined
Sep 3, 2020
Messages
191
Hey there.

First of all, I'm sorry if a thread was already open about this. I do also apologize for my english :peasant-confused:
Then, I'm kinda reaaaaaally new with triggers, just learnt them a week ago :peasant-work-work: and I was wondering if someone could help me to fix something I cannot reach.

I would like that 3 of my custom units give me 1 gold every 120 seconds while they're alive (let's say, a Peasant, a Footman and a Rifleman). Can someone explain me how I could reach this with triggers ? :)

Thank youuuuuuuuuuu :peasant-grin:
 
Level 19
Joined
Feb 27, 2019
Messages
580
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.
 
Last edited:
Level 7
Joined
Sep 3, 2020
Messages
191
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.
Thanks a lot for all the time you took writing me this man, I do appreciate a lot. I'll read all of this to understand all you've done and remade it by myself :)

Thank you, I'll read this carefully :)
 
Last edited:
Status
Not open for further replies.
Top