• 🏆 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] Lumber Income System

Status
Not open for further replies.
Level 37
Joined
Jul 22, 2015
Messages
3,485
Hello again everybody! I know I just recenty made a post for some insight on a trigger I made, but the information I learned from that post was so useful, I couldn't help but ask for more insight on a system that is currently WiP.

Here is how the system works:
The system makes lumber income work like an Entangled Gold Mine. A unit is loaded into the "lumber mill", and the player recieves lumber from the resources that unit collected in intervals. Below you can see all the triggers that are currently running the system.

  • Harvest Lumber Core
    • Events
      • Unit - A unit Is loaded into a transport
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Worker
      • (Unit-type of (Transporting unit)) Equal to Lumber Mill
    • Actions
      • Set HarvestLumber_Index = (HarvestLumber_Index + 1)
      • Set HarvestLumber_Unit[HarvestLumber_Index] = (Triggering unit)
      • Set HarvestLumber_Location[HarvestLumber_Index] = (Position of (Transporting unit))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • HarvestLumber_Index Equal to 1
        • Then - Actions
          • Trigger - Turn on Harvest Lumber Loop <gen>
        • Else - Actions
  • Harvest Lumber Loop
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • For each (Integer HarvestLumber_LoopInteger) from 1 to HarvestLumber_Index, do (Actions)
        • Loop - Actions
          • Unit Group - Add HarvestLumber_Unit[HarvestLumber_LoopInteger] to HarvestLumber_Group[HarvestLumber_LoopInteger]
          • Destructible - Create a Harvest Lumber Dummy Tree at (Random point in (Region centered at HarvestLumber_Location[HarvestLumber_LoopInteger] with size (900.00, 900.00))) facing (Random angle) with scale 1.00 and variation 0
          • Unit - Create 1 Harvest Lumber Dummy for (Owner of HarvestLumber_Unit[HarvestLumber_LoopInteger]) at (Position of (Last created destructible)) facing Default building facing degrees
          • Unit - Order (Last created unit) to Harvest (Last created destructible)
          • Unit Group - Add (Last created unit) to HarvestLumberl_DummyGroup[HarvestLumber_LoopInteger]
          • Trigger - Add to Harvest Lumber Check <gen> the event (Unit - A unit Is issued an order with no target)
          • Set HarvestLumber_DummyUnit[HarvestLumber_LoopInteger] = (Random unit from HarvestLumberl_DummyGroup[HarvestLumber_LoopInteger])
          • Set HarvestLumber_Unit[HarvestLumber_LoopInteger] = HarvestLumber_Unit[HarvestLumber_Index]
          • Set HarvestLumber_Location[HarvestLumber_LoopInteger] = HarvestLumber_Location[HarvestLumber_Index]
          • Set HarvestLumber_Index = (HarvestLumber_Index - 1)
          • Set HarvestLumber_LoopInteger = (HarvestLumber_LoopInteger - 1)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • HarvestLumber_Index Equal to 0
            • Then - Actions
              • Trigger - Turn off (This trigger)
            • Else - Actions
  • Harvest Lumber Check
    • Events
    • Conditions
      • (Issued order) Equal to (Order(stop))
    • Actions
      • Unit Group - Remove HarvestLumber_Unit[HarvestLumber_LoopInteger] from HarvestLumber_Group[HarvestLumber_LoopInteger]
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in HarvestLumber_Group[HarvestLumber_LoopInteger]) Less than (Number of units in HarvestLumberl_DummyGroup[HarvestLumber_LoopInteger])
        • Then - Actions
          • Destructible - Pick every destructible within 32.00 of (Position of HarvestLumber_DummyUnit[HarvestLumber_LoopInteger]) and do (Actions)
            • Loop - Actions
              • Destructible - Kill (Picked destructible)
              • Unit - Add a 0.01 second Generic expiration timer to HarvestLumber_DummyUnit[HarvestLumber_LoopInteger]
              • Unit Group - Remove HarvestLumber_DummyUnit[HarvestLumber_LoopInteger] from HarvestLumberl_DummyGroup[HarvestLumber_LoopInteger]
        • Else - Actions
To make this sytem work, I had to make it so that whenever a unit enters the lumber mill, it creates a dummy tree within a set region of the lumber mill (this makes it so that the lumber it retrieved from the tree appears as text over the lumber mill), then it creates a dummy harvester (uses the Wisp Harvest ability) on the location of the recently created tree, and then orders the dummy harvest to harvest that tree. However, I am stuck on trying to figure out how to make it so that if a unit were to leave the lumber mill, the tree and unit are removed. So far with what I have, it only works for 1 peasant, and every peasant after that leaves, the dummies are not removed. I have spent already 2 days trying out different functions, but now I'm just pooped. Any help is appreciated, and if you need any more questions/concerns about this system, feel free to ask!
 
Last edited:

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,183
Every 0.03 seconds check the current order of all workers. If the unit had the order "harvest" last time checked and is now having "resumeharvest" then he has turned it in within the 0.03 interval.

I will upload triggers in a sec.

edit:
  • Untitled Trigger 003
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Hashtable - Create a hashtable
      • Set my_hash = (Last created hashtable)
  • Untitled Trigger 002
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units of type Peasant) and do (Actions)
        • Loop - Actions
          • Set current_order = (Current order of (Picked unit))
          • Custom script: set udg_old_order = LoadInteger(udg_my_hash, GetHandleId(GetEnumUnit()), 1)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • current_order Equal to (Order(harvest))
              • old_order Equal to (Order(resumeharvesting))
            • Then - Actions
              • Player - Add 9 to (Owner of (Picked unit)) Current gold
            • Else - Actions
          • Custom script: call SaveInteger(udg_my_hash, GetHandleId(GetEnumUnit()), 1, udg_current_order)
I use hashtable to make it MUI, since you use indexing yours will have to look a bit different.
 
Level 37
Joined
Jul 22, 2015
Messages
3,485
Every 0.03 seconds check the current order of all workers. If the unit had the order "harvest" last time checked and is now having "resumeharvest" then he has turned it in within the 0.03 interval.

I will upload triggers in a sec.

edit:
  • Untitled Trigger 003
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Hashtable - Create a hashtable
      • Set my_hash = (Last created hashtable)
  • Untitled Trigger 002
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units of type Peasant) and do (Actions)
        • Loop - Actions
          • Set current_order = (Current order of (Picked unit))
          • Custom script: set udg_old_order = LoadInteger(udg_my_hash, GetHandleId(GetEnumUnit()), 1)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • current_order Equal to (Order(harvest))
              • old_order Equal to (Order(resumeharvesting))
            • Then - Actions
              • Player - Add 9 to (Owner of (Picked unit)) Current gold
            • Else - Actions
          • Custom script: call SaveInteger(udg_my_hash, GetHandleId(GetEnumUnit()), 1, udg_current_order)
I use hashtable to make it MUI, since you use indexing yours will have to look a bit different.

Thanks for the response! Is there no work around with the way I currently have it? I tried this method, but it doesn't destroy the dummy unit or tree after the first peasant leaves.

  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • (Number of units in HarvestLumber_Group[HarvestLumber_LoopInteger]) Less than (Number of units in HarvestLumberl_DummyGroup[HarvestLumber_LoopInteger])
    • Then - Actions
      • Unit Group - Pick every unit in (Random 1 units from HarvestLumberl_DummyGroup[HarvestLumber_LoopInteger]) and do (Actions)
        • Loop - Actions
          • Destructible - Pick every destructible within 32.00 of (Position of (Picked unit)) and do (Actions)
            • Loop - Actions
              • Unit - Add a 0.01 second Generic expiration timer to HarvestLumber_DummyUnit[HarvestLumber_LoopInteger]
              • Destructible - Kill (Picked destructible)
          • Unit Group - Remove (Picked unit) from HarvestLumberl_DummyGroup[HarvestLumber_LoopInteger]
    • Else - Actions
 

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,183
Wow. I actually failed to notice that you wanted it like the entangle gold mine.. let's see..

When a worker enter the building do the index thing.
Loop every 0.03 seconds and loop through all indexes, keep track on the interval with a variable.. and after 1 second add gold/lumber.
You have basically done all this in your other thread.

As I see you're overthinking it again.
 
Status
Not open for further replies.
Top