• 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.

How to make only 1 peasant be able to cut a single tree

Status
Not open for further replies.
Level 6
Joined
Jan 16, 2017
Messages
110
Hello i was trying to make a trigger to limit peasants per tree just to 1 (For balance purposes).
But i am stuck at one point and unable to figure out what should i do next.
The idea is that when peasant is ordered to gather lumber and checks if the tree has enough health, then the tree will have reduced health and if it doesn't have enough health then the peasant is stopped.
When the peasant finishes cutting the tree or is moved to a different one or just moved somewhere else then the tree restores it's health.
But it doesn't work properly (First time it works but if you click the tree multiple times then it resets and the Peasant joins gathering the lumber with the other peasant).
I would really appreciate if someone could solve this,
here's my trigger
  • Init
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units of type Peasant) and do (Actions)
        • Loop - Actions
          • Unit - Set the custom value of (Picked unit) to PeasantCount
          • Set PeasantCount = (PeasantCount + 1)
  • Limit
    • Events
      • Unit - A unit Is issued an order targeting an object
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • (Issued order) Equal to (Order(smart))
          • (Issued order) Equal to (Order(harvest))
          • (Issued order) Equal to (Order(resumeharvesting))
      • (Unit-type of (Triggering unit)) Equal to Peasant
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Or - Any (Conditions) are true
            • Conditions
              • (Issued order) Equal to (Order(smart))
              • (Issued order) Equal to (Order(harvest))
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Current life of (Target destructible of issued order)) Greater than or equal to 100.00
            • Then - Actions
              • Set Tree[(Custom value of (Triggering unit))] = (Target destructible of issued order)
              • Destructible - Set life of (Target destructible of issued order) to 50.00
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Current life of (Target destructible of issued order)) Greater than or equal to 0.01
                • Then - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Current life of Tree[(Custom value of (Triggering unit))]) Greater than or equal to 0.01
                    • Then - Actions
                      • Destructible - Set life of Tree[(Custom value of (Triggering unit))] to 140.00
                    • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Current life of (Target destructible of issued order)) Greater than or equal to 0.01
                    • Then - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • ((Triggering unit) is selected by (Owner of (Triggering unit))) Equal to True
                        • Then - Actions
                          • Unit - Replace (Triggering unit) with a (Unit-type of (Triggering unit)) using The old unit's relative life and mana
                          • Selection - Add (Last replaced unit) to selection for (Owner of (Last replaced unit))
                        • Else - Actions
                          • Unit - Replace (Triggering unit) with a (Unit-type of (Triggering unit)) using The old unit's relative life and mana
                    • Else - Actions
                • Else - Actions
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Current life of Tree[(Custom value of (Triggering unit))]) Greater than or equal to 0.01
            • Then - Actions
              • Destructible - Set life of Tree[(Custom value of (Triggering unit))] to 140.00
            • Else - Actions
          • Custom script: set udg_Tree[GetUnitUserData(GetTriggerUnit())] = null
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Issued order) Equal to (Order(resumeharvesting))
          • (Current life of (Target destructible of issued order)) Less than or equal to 75.00
        • Then - Actions
          • Custom script: set udg_Tree[GetUnitUserData(GetTriggerUnit())] = null
          • Destructible - Set life of (Target destructible of issued order) to 140.00
        • Else - Actions
 
Level 6
Joined
Jan 16, 2017
Messages
110
Why not simply use the Wisp's harvest lumber ability?

Edit : This isn't exactly what you are looking for but you may find this useful : [Trigger] - Limit Number of units that can attack another unit. You can use it as a base and make modifications so that it works on destructibles instead.
I was already using Wisp's ability but it's not what i wanted for couple reasons.

Also i checked the link and it inspired me to make some improvements to make it much better
But everytime a peasant is trained and the rally point is directly placed on the tree then it doesn't work and the Tree[x] variable doesn't get updated so if you know what kind of order it is then it would be really helpful. (otherwise it nearly works)
here's how it looks right now:
  • Init
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units of type Peasant) and do (Actions)
        • Loop - Actions
          • Unit - Set the custom value of (Picked unit) to LumberjackCount
          • Set LumberjackCount = (LumberjackCount + 1)
  • Train
    • Events
      • Unit - A unit Finishes training a unit
    • Conditions
      • (Unit-type of (Trained unit)) Equal to Peasant
    • Actions
      • Unit - Set the custom value of (Picked unit) to LumberjackCount
      • Set LumberjackCount = (LumberjackCount + 1)
  • Limit1
    • Events
      • Unit - A unit Is issued an order targeting an object
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • (Issued order) Equal to (Order(smart))
          • (Issued order) Equal to (Order(harvest))
          • (Issued order) Equal to (Order(resumeharvesting))
      • (Unit-type of (Triggering unit)) Equal to Peasant
    • Actions
      • Custom script: local destructable d
      • Set TempDestructible[1] = (Target destructible of issued order)
      • Custom script: set d = udg_TempDestructible[1]
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Current life of (Target destructible of issued order)) Greater than or equal to 0.01
          • Or - Any (Conditions) are true
            • Conditions
              • (Issued order) Equal to (Order(smart))
              • (Issued order) Equal to (Order(harvest))
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • CD Less than or equal to 0.00
              • (Current life of TempDestructible[1]) Greater than or equal to 60.00
            • Then - Actions
              • Set Tree[(Custom value of (Triggering unit))] = (Target destructible of issued order)
              • Destructible - Set life of TempDestructible[1] to 59.00
              • Set CD = 1.00
              • Wait 0.01 seconds
              • Set CD = 0.00
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Current life of Tree[(Custom value of (Triggering unit))]) Greater than or equal to 0.01
                  • TempDestructible[1] Not equal to Tree[(Custom value of (Triggering unit))]
                • Then - Actions
                  • Destructible - Set life of Tree[(Custom value of (Triggering unit))] to 60.00
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Current life of TempDestructible[1]) Greater than or equal to 0.01
                • Then - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • ((Triggering unit) is selected by (Owner of (Triggering unit))) Equal to True
                    • Then - Actions
                      • Unit - Replace (Triggering unit) with a (Unit-type of (Triggering unit)) using The old unit's relative life and mana
                      • Selection - Add (Last replaced unit) to selection for (Owner of (Triggering unit))
                    • Else - Actions
                      • Unit - Replace (Triggering unit) with a (Unit-type of (Triggering unit)) using The old unit's relative life and mana
                • Else - Actions
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Issued order) Equal to (Order(resumeharvesting))
        • Then - Actions
          • Destructible - Set life of Tree[(Custom value of (Triggering unit))] to 60.00
          • Custom script: set udg_Tree[GetUnitUserData(GetTriggerUnit())] = null
        • Else - Actions
      • Custom script: set d = null
  • Limit2
    • Events
      • Unit - A unit Is issued an order targeting an object
      • Unit - A unit Is issued an order targeting a point
      • Unit - A unit Is issued an order with no target
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Peasant
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Current life of (Target destructible of issued order)) Greater than or equal to 0.01
        • Then - Actions
          • Game - Display to (All players) the text: Passed
        • Else - Actions
          • Destructible - Set life of Tree[(Custom value of (Triggering unit))] to 60.00
          • Custom script: set udg_Tree[GetUnitUserData(GetTriggerUnit())] = null
  • Limit3
    • Events
      • Unit - A unit owned by Player 1 (Red) Dies
      • Unit - A unit owned by Player 2 (Blue) Dies
      • Unit - A unit owned by Player 3 (Teal) Dies
      • Unit - A unit owned by Player 4 (Purple) Dies
      • Unit - A unit owned by Player 5 (Yellow) Dies
      • Unit - A unit owned by Player 6 (Orange) Dies
      • Unit - A unit owned by Player 7 (Green) Dies
      • Unit - A unit owned by Player 8 (Pink) Dies
      • Unit - A unit owned by Player 9 (Gray) Dies
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Peasant
    • Actions
      • Destructible - Set life of Tree[(Custom value of (Triggering unit))] to 60.00
      • Custom script: set udg_Tree[GetUnitUserData(GetTriggerUnit())] = null
 
Last edited:
Level 6
Joined
Jan 16, 2017
Messages
110
Update
I major improvements but still it doesn't work that well, it has a limit on how many units can gather lumber and sometimes the tree doesn't get healed and i don't know why. The problem was in the older triggers above too.
  • Init
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units of type Lumberjack) and do (Actions)
        • Loop - Actions
          • Unit - Set the custom value of (Picked unit) to TALumberjackCount
          • Set TALumberjackCount = (TALumberjackCount + 1)
      • Unit Group - Pick every unit in (Units in (Playable map area) matching (((Matching unit) is A town-hall-type unit) Equal to True)) and do (Actions)
        • Loop - Actions
          • Unit - Set the custom value of (Picked unit) to TATownHallCount
          • Set TATownHallCount = (TATownHallCount + 1)
  • Train
    • Events
      • Unit - A unit Finishes training a unit
    • Conditions
      • (Unit-type of (Trained unit)) Equal to Lumberjack
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • TARallyPoint[(Custom value of (Triggering unit))] Not equal to No destructible
        • Then - Actions
          • Unit - Replace (Trained unit) with a (Unit-type of (Trained unit)) using The old unit's relative life and mana
          • Unit - Set the custom value of (Last replaced unit) to TALumberjackCount
          • Set TALumberjackCount = (TALumberjackCount + 1)
          • Unit - Order (Last replaced unit) to Harvest TARallyPoint[(Custom value of (Triggering unit))]
        • Else - Actions
          • Unit - Set the custom value of (Trained unit) to TALumberjackCount
          • Set TALumberjackCount = (TALumberjackCount + 1)
  • Build
    • Events
      • Unit - A unit owned by Player 1 (Red) Begins construction
      • Unit - A unit owned by Player 2 (Blue) Begins construction
      • Unit - A unit owned by Player 3 (Teal) Begins construction
      • Unit - A unit owned by Player 4 (Purple) Begins construction
      • Unit - A unit owned by Player 5 (Yellow) Begins construction
      • Unit - A unit owned by Player 6 (Orange) Begins construction
      • Unit - A unit owned by Player 7 (Green) Begins construction
      • Unit - A unit owned by Player 8 (Pink) Begins construction
      • Unit - A unit owned by Player 9 (Gray) Begins construction
    • Conditions
      • ((Constructing structure) is A town-hall-type unit) Equal to True
    • Actions
      • Unit - Set the custom value of (Constructing structure) to TATownHallCount
      • Set TATownHallCount = (TATownHallCount + 1)
  • Limit1
    • Events
      • Unit - A unit Is issued an order targeting an object
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • (Issued order) Equal to (Order(smart))
          • (Issued order) Equal to (Order(harvest))
          • (Issued order) Equal to (Order(resumeharvesting))
      • (Unit-type of (Triggering unit)) Equal to Lumberjack
    • Actions
      • Custom script: local destructable d
      • Set TempDestructible[1] = (Target destructible of issued order)
      • Custom script: set d = udg_TempDestructible[1]
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Current life of (Target destructible of issued order)) Greater than or equal to 0.01
          • Or - Any (Conditions) are true
            • Conditions
              • (Issued order) Equal to (Order(smart))
              • (Issued order) Equal to (Order(harvest))
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • CD Less than or equal to 0.00
              • (Current life of TempDestructible[1]) Greater than or equal to 60.00
            • Then - Actions
              • Set Tree[(Custom value of (Triggering unit))] = (Target destructible of issued order)
              • Destructible - Set life of TempDestructible[1] to 59.00
              • Set CD = 1.00
              • Wait 0.01 seconds
              • Set CD = 0.00
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Current life of Tree[(Custom value of (Triggering unit))]) Greater than or equal to 0.01
                  • TempDestructible[1] Not equal to Tree[(Custom value of (Triggering unit))]
                • Then - Actions
                  • Destructible - Set life of Tree[(Custom value of (Triggering unit))] to 60.00
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Current life of TempDestructible[1]) Greater than or equal to 0.01
                • Then - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • ((Triggering unit) is selected by (Owner of (Triggering unit))) Equal to True
                    • Then - Actions
                      • Unit - Replace (Triggering unit) with a (Unit-type of (Triggering unit)) using The old unit's relative life and mana
                      • Selection - Add (Last replaced unit) to selection for (Owner of (Triggering unit))
                    • Else - Actions
                      • Unit - Replace (Triggering unit) with a (Unit-type of (Triggering unit)) using The old unit's relative life and mana
                • Else - Actions
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Issued order) Equal to (Order(resumeharvesting))
        • Then - Actions
          • Destructible - Set life of Tree[(Custom value of (Triggering unit))] to 60.00
          • Custom script: set udg_Tree[GetUnitUserData(GetTriggerUnit())] = null
        • Else - Actions
      • Custom script: set d = null
  • Limit2
    • Events
      • Unit - A unit Is issued an order targeting an object
      • Unit - A unit Is issued an order targeting a point
      • Unit - A unit Is issued an order with no target
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Lumberjack
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Current life of (Target destructible of issued order)) Greater than or equal to 0.01
        • Then - Actions
        • Else - Actions
          • Destructible - Set life of Tree[(Custom value of (Triggering unit))] to 60.00
          • Custom script: set udg_Tree[GetUnitUserData(GetTriggerUnit())] = null
  • Limit3
    • Events
      • Unit - A unit owned by Player 1 (Red) Dies
      • Unit - A unit owned by Player 2 (Blue) Dies
      • Unit - A unit owned by Player 3 (Teal) Dies
      • Unit - A unit owned by Player 4 (Purple) Dies
      • Unit - A unit owned by Player 5 (Yellow) Dies
      • Unit - A unit owned by Player 6 (Orange) Dies
      • Unit - A unit owned by Player 7 (Green) Dies
      • Unit - A unit owned by Player 8 (Pink) Dies
      • Unit - A unit owned by Player 9 (Gray) Dies
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Lumberjack
    • Actions
      • Destructible - Set life of Tree[(Custom value of (Triggering unit))] to 60.00
      • Custom script: set udg_Tree[GetUnitUserData(GetTriggerUnit())] = null
  • Order
    • Events
      • Unit - A unit Is issued an order targeting an object
      • Unit - A unit Is issued an order targeting a point
    • Conditions
      • (Issued order) Equal to (Order(smart))
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Triggering unit) is A town-hall-type unit) Equal to True
        • Then - Actions
          • Set TARallyPoint[(Custom value of (Triggering unit))] = No destructible
          • Set TempDestructible[1] = (Target destructible of issued order)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Or - Any (Conditions) are true
                • Conditions
                  • (Destructible-type of TempDestructible[1]) Equal to Summer Tree Wall
                  • (Destructible-type of TempDestructible[1]) Equal to Snowy Tree Wall
                  • (Destructible-type of TempDestructible[1]) Equal to Winter Tree Wall
                  • (Destructible-type of TempDestructible[1]) Equal to Fall Tree Wall
                  • (Destructible-type of TempDestructible[1]) Equal to Ruins Tree Wall
            • Then - Actions
              • Set TARallyPoint[(Custom value of (Triggering unit))] = TempDestructible[1]
            • Else - Actions
        • Else - Actions
 
Status
Not open for further replies.
Top