• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Question regarding a map mechanism

Level 5
Joined
Nov 17, 2022
Messages
84
Years ago, I played a game called Sheep Farmer where you play as a farmer raising sheep. You win rewards for how well your sheep are raised and you could sabotage other's flocks for your benefit.

One mechanic I always wondered about was how the game managed to create a breeding and pregnancy mechanic, as in the game had male and female sheep you could breed periodically to get lambs that would then age into adults. Anyone got any clue how that kind of system is made? I've been humoring a horse simulation game in the future where you play as a stallion building a herd so it's why I'm asking.
 
Unit Indexers and Timers basically.

On paper it's easy enough to create. I'm not sure about the requirements for the breeding but all you need to do is add either a buff or custom value or something to a pregnant sheep to track it. You can also add a timer indexed to that specific sheep for the time of pregnancy. Same with when a sheep is born you simply link a timer to that sheep that when it expires you replace it with the next sheep unit for that age and start another one, so on and so forth.

The implementation is the hard part but the methods are all there and simple enough on paper. You could even scrap the timers in some cases and instead use the in-built expiration timers and catch when that expires and replace the sheep with the older version and start another expiration timer etc since there are natives to control all of these already in GUI and JASS.
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
+1 to what Footman said. Here's an example:

Randomize your Lambs as they come into play:
  • Events
    • Unit - A unit Enters (playable map area)
  • Conditions
    • (Unit-type of (Triggering unit)) Equal to Lamb
  • Actions
    • Set Variable MyUnit = (Triggering unit)
    • Set Variable CV = (Custom value of MyUnit)
    • Set Variable Age[CV] = 0
    • Set Variable Gender[CV] = (Random integer number between 1 and 2)
    • -------- A Gender value of 1 = Male. A Gender value of 2 = Female. --------
    • Unit Group - Add MyUnit to Lamb_Group
Keep track of the Lambs over time, periodically increasing their Age until they reach maturity and become adults:
  • Events
    • Time - Every 1.00 seconds of game time
  • Conditions
  • Actions
    • Unit Group - Pick every unit in Lamb_Group and do (Actions)
      • Loop - Actions
        • Set Variable MyUnit = (Picked unit)
        • Set Variable CV = (Custom value of MyUnit)
        • -------- --------
        • -------- Increase the Lamb's Age by 1: --------
        • Set Variable Age[CV] = (Age[CV] + 1)
        • -------- --------
        • -------- Check if it's reached a high enough Age to be considered an adult: --------
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • Age[CV] Greater than or equal to 10
          • Then - Actions
            • Unit Group - Remove MyUnit from Lamb_Group
            • -------- --------
            • -------- Replace the Lamb with either a Ram or a Sheep --------
            • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • Gender[CV] Equal to 1
              • Then - Actions
                • -------- It's a male --------
                • Unit - Replace MyUnit with a Ram (Male) using default...
                • Set Variable MyUnit = (Last replaced unit)
                • Set Variable CV = (Custom value of MyUnit)
                • Set Variable Age[CV] = 10
                • Set Variable Gender[CV] = 1
                • Unit Group - Add MyUnit to Ram_Group
              • Else - Actions
                • -------- It's a female --------
                • Unit - Replace MyUnit with a Sheep (Female) using default...
                • Set Variable MyUnit = (Last replaced unit)
                • Set Variable CV = (Custom value of MyUnit)
                • Set Variable Age[CV] = 10
                • Set Variable Gender[CV] = 2
                • Unit Group - Add MyUnit to Sheep_Group
          • Else - Actions
In this example it takes 10 seconds for a Lamb to reach adulthood. Once that occurs it's replaced with either a Ram or Sheep based on the Gender it was born with. You can then track them in their own respective Unit Groups just like how you tracked the Lamb.

Edit: Fixed wrong Event Response in the above trigger.

Variables:
MyUnit = Unit
CV = Integer
Gender = Integer (array)
Age = Integer (array)
Lamb_Group = Unit Group
Ram_Group = Unit Group
Sheep_Group = Unit Group

Unit Indexing requires that you copy and paste the single "Unit Indexer" folder from this demo map's Trigger Editor into your own:
 
Last edited:
Level 5
Joined
Nov 17, 2022
Messages
84
+1 to what Footman said. Here's an example:

Randomize your Lambs as they come into play:
  • Events
    • Unit - A unit Enters (playable map area)
  • Conditions
    • (Unit-type of (Triggering unit)) Equal to Lamb
  • Actions
    • Set Variable MyUnit = (Triggering unit)
    • Set Variable CV = (Custom value of MyUnit)
    • Set Variable Age[CV] = 0
    • Set Variable Gender[CV] = (Random integer number between 1 and 2)
    • -------- A Gender value of 1 = Male. A Gender value of 2 = Female. --------
    • Unit Group - Add MyUnit to Lamb_Group
Keep track of the Lambs over time, periodically increasing their Age until they reach maturity and become adults:
  • Events
    • Time - Every 1.00 seconds of game-time
  • Conditions
  • Actions
    • Unit Group - Pick every unit in Lamb_Group
      • Loop - Actions
        • Set Variable MyUnit = (Triggering unit)
        • Set Variable CV = (Custom value of MyUnit)
        • Set Variable Age[CV] = (Age[CV] + 1)
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • Age[CV] Greater than or equal to 10
          • Then - Actions
            • Unit Group - Remove MyUnit from Lamb_Group
            • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • Gender[CV] Equal to 1
              • Then - Actions
                • -------- It's a male --------
                • Unit - Replace MyUnit with a Ram (Male) using default...
                • Set Variable MyUnit = (Last replaced unit)
                • Set Variable CV = (Custom value of MyUnit)
                • Set Variable Age[CV] = 10
                • Set Variable Gender[CV] = 1
                • Unit Group - Add MyUnit to Ram_Group
              • Else - Actions
                • -------- It's a female --------
                • Unit - Replace MyUnit with a Sheep (Female) using default...
                • Set Variable MyUnit = (Last replaced unit)
                • Set Variable CV = (Custom value of MyUnit)
                • Set Variable Age[CV] = 10
                • Set Variable Gender[CV] = 2
                • Unit Group - Add MyUnit to Sheep_Group
          • Else - Actions
In this example it takes 10 seconds for a Lamb to reach adulthood. Once that occurs it's replaced with either a Ram or Sheep based on the Gender it was born with. You can then track them in their own respective Unit Groups just like how you tracked the Lamb.

Variables:
MyUnit = Unit
CV = Integer
Gender = Integer (array)
Age = Integer (array)
Lamb_Group = Unit Group
Ram_Group = Unit Group
Sheep_Group = Unit Group

Unit Indexing requires that you copy and paste the single "Unit Indexer" folder from this demo map's Trigger Editor into your own:
This is super helpful, thanks!
Its incredible what people can do with triggers in this program.
 
Level 5
Joined
Nov 17, 2022
Messages
84
+1 to what Footman said. Here's an example:

Randomize your Lambs as they come into play:
  • Events
    • Unit - A unit Enters (playable map area)
  • Conditions
    • (Unit-type of (Triggering unit)) Equal to Lamb
  • Actions
    • Set Variable MyUnit = (Triggering unit)
    • Set Variable CV = (Custom value of MyUnit)
    • Set Variable Age[CV] = 0
    • Set Variable Gender[CV] = (Random integer number between 1 and 2)
    • -------- A Gender value of 1 = Male. A Gender value of 2 = Female. --------
    • Unit Group - Add MyUnit to Lamb_Group
Keep track of the Lambs over time, periodically increasing their Age until they reach maturity and become adults:
  • Events
    • Time - Every 1.00 seconds of game time
  • Conditions
  • Actions
    • Unit Group - Pick every unit in Lamb_Group and do (Actions)
      • Loop - Actions
        • Set Variable MyUnit = (Picked unit)
        • Set Variable CV = (Custom value of MyUnit)
        • -------- --------
        • -------- Increase the Lamb's Age by 1: --------
        • Set Variable Age[CV] = (Age[CV] + 1)
        • -------- --------
        • -------- Check if it's reached a high enough Age to be considered an adult: --------
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • Age[CV] Greater than or equal to 10
          • Then - Actions
            • Unit Group - Remove MyUnit from Lamb_Group
            • -------- --------
            • -------- Replace the Lamb with either a Ram or a Sheep --------
            • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • Gender[CV] Equal to 1
              • Then - Actions
                • -------- It's a male --------
                • Unit - Replace MyUnit with a Ram (Male) using default...
                • Set Variable MyUnit = (Last replaced unit)
                • Set Variable CV = (Custom value of MyUnit)
                • Set Variable Age[CV] = 10
                • Set Variable Gender[CV] = 1
                • Unit Group - Add MyUnit to Ram_Group
              • Else - Actions
                • -------- It's a female --------
                • Unit - Replace MyUnit with a Sheep (Female) using default...
                • Set Variable MyUnit = (Last replaced unit)
                • Set Variable CV = (Custom value of MyUnit)
                • Set Variable Age[CV] = 10
                • Set Variable Gender[CV] = 2
                • Unit Group - Add MyUnit to Sheep_Group
          • Else - Actions
In this example it takes 10 seconds for a Lamb to reach adulthood. Once that occurs it's replaced with either a Ram or Sheep based on the Gender it was born with. You can then track them in their own respective Unit Groups just like how you tracked the Lamb.

Edit: Fixed wrong Event Response in the above trigger.

Variables:
MyUnit = Unit
CV = Integer
Gender = Integer (array)
Age = Integer (array)
Lamb_Group = Unit Group
Ram_Group = Unit Group
Sheep_Group = Unit Group

Unit Indexing requires that you copy and paste the single "Unit Indexer" folder from this demo map's Trigger Editor into your own:
also
do you have any idea how a trigger for the breeding period might work? like would it be related to a spell or something else entirely?
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
also
do you have any idea how a trigger for the breeding period might work? like would it be related to a spell or something else entirely?
You'd have to explain how you want it to work.

Because this is too vague to come up with a trigger since the trigger will change depending on the mechanics involved:
in the game had male and female sheep you could breed periodically to get lambs that would then age into adults.
What does "breed" mean exactly? How does that translate over to Warcraft 3 mechanics? This choice is entirely up to you.

But I'll throw some ideas out there:

1) Breeding could happen automatically as time goes by using a very similar design to the aging triggers above. You could incorporate some kind of breeding zone or distance checks between Sheep + Rams and increase a "Pregnancy" variable as long as the Sheep is near a Ram. Upon reaching 100 "Pregnancy" a Sheep will give birth to a Lamb.

2) It could happen when you cast an ability, IE: Sheep targets Ram with the Channel ability (a special ability meant to be combined with triggers).

3) Like #2 but the ability is disabled by default and becomes enabled once a Sheep is say "fertile". This could be the case after a certain period of time. You could even incorporate this into #1 so that the ability becomes active after the unit has been near a potential mate for a while, thus requiring the user to check in on them and manually initiate the Breeding process via the ability.

4) You could incorporate Mana into the mix for #2. This resource is already visible to the Player, easy to modify, and can be attached to the "Breed" ability for instance.


Using #4 as our method, here we cancel a player's attempt to Breed if you target the wrong unit or the target doesn't have enough mana:
  • Events
    • Unit - A unit Begins casting an ability
  • Conditions
    • (Ability being cast) Equal to Breed
  • Actions
    • -------- Cancel the breeding process if you target the wrong unit or the target isn't on full mana --------
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • (Unit-type of (Triggering unit)) Equal to Sheep
        • Or - Multiple conditions are true
          • Or - Conditions
            • (Percentage mana of (Target unit of ability being cast)) Less than 100.00
            • (Unit-type of (Target unit of ability being cast)) Not equal to Ram
      • Then - Actions
        • Unit - Order (Triggering unit) to Stop
      • Else - Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • (Unit-type of (Triggering unit)) Equal to Ram
        • Or - Multiple conditions are true
          • Or - Conditions
            • (Percentage mana of (Target unit of ability being cast)) Less than 100.00
            • (Unit-type of (Target unit of ability being cast)) Not equal to Sheep
      • Then - Actions
        • Unit - Order (Triggering unit) to Stop
      • Else - Actions
On a successful cast, adjust the mana of the target and create a Lamb:
  • Events
    • Unit - A unit Starts the effect of an ability
  • Conditions
    • (Ability being cast) Equal to Breed
  • Actions
    • -------- Both the Sheep and Ram will be reset back to 0 mana and a Lamb will be born --------
    • Unit - Set mana of (Target unit of ability being cast) to 0.00
    • Unit - Create 1 Lamb for (Triggering player) at (Position of (Triggering unit))...
This is assuming that the Breed ability costs all of the unit's mana. So the outcome will be that two full mana units, a Sheep and a Ram, will be needed to breed and both will lose all of their Mana upon doing so. You can use Mana's natural regeneration as your time component. You could even incorporate something like items that regenerate mana faster or restore a chunk of mana. IE: Fresh Water restores 2 mana thus speeding up the breeding process.
 
Last edited:
Level 5
Joined
Nov 17, 2022
Messages
84
You'd have to explain how you want it to work.

Because this is too vague to come up with a trigger since the trigger will change depending on the mechanics involved:

What does "breed" mean exactly? How does that translate over to Warcraft 3 mechanics? This choice is entirely up to you.

But I'll throw some ideas out there:
1) Breeding could happen automatically as time goes by using a very similar design to the aging triggers above. So you could incorporate some kind of breeding zone or distance checks between Sheep + Rams and increase a "Pregnancy" variable as long as the Sheep is near a Ram, for example. At 100 "Pregnancy" it gives birth.
2) It could happen when you cast an ability, IE: Sheep targets Ram.
3) It could be #2 but the ability is disabled by default and becomes enabled once a Sheep is say "fertile". This could be the case after a certain period of time.
4) You could incorporate Mana into the mix for #2/#3. This resource is already visible to the Player, easy to modify, and can be attached to the "breed" ability for instance.

Using #4 as our method, here we cancel a player's attempt to Breed if you target the wrong unit or the target doesn't have enough mana:
  • Events
    • Unit - A unit Begins casting an ability
  • Conditions
    • (Ability being cast) Equal to Breed
  • Actions
    • -------- Cancel the breeding process if you target the wrong unit or the target isn't on full mana --------
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • (Unit-type of (Triggering unit)) Equal to Sheep
        • Or - Multiple conditions are true
          • Or - Conditions
            • (Percentage mana of (Target unit of ability being cast)) Less than 100.00
            • (Unit-type of (Target unit of ability being cast)) Not equal to Ram
      • Then - Actions
        • Unit - Order (Triggering unit) to Stop
      • Else - Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • (Unit-type of (Triggering unit)) Equal to Ram
        • Or - Multiple conditions are true
          • Or - Conditions
            • (Percentage mana of (Target unit of ability being cast)) Less than 100.00
            • (Unit-type of (Target unit of ability being cast)) Not equal to Sheep
      • Then - Actions
        • Unit - Order (Triggering unit) to Stop
      • Else - Actions
On a successful cast, adjust the mana of the target and create a Lamb:
  • Events
    • Unit - A unit Starts the effect of an ability
  • Conditions
    • (Ability being cast) Equal to Breed
  • Actions
    • -------- Both the Sheep and Ram will be reset back to 0 mana and a Lamb will be born --------
    • Unit - Set mana of (Target unit of ability being cast) to 0.00
    • Unit - Create 1 Lamb for (Triggering player) at (Position of (Triggering unit))...
This is assuming that the Breed ability costs all of the unit's mana.
This is exactly what I need I think! Feels like a good fit 👍
Thank you again for all this detailed information, it helps me learn a lot about working triggers further.
 
Top