• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

How can I detect that a unit returned lumber?

Status
Not open for further replies.
Level 8
Joined
Jan 28, 2016
Messages
486
I may have a solution to this.

When you send a worker to gather lumber (whether it be with a right-click, manually casting Gather or even issuing an attack command), it will be ordered to "harvest." Once the worker collects the maximum amount of lumber it can carry or is manually sent to drop it off, it will be issued a "resumeharvest" order. After dropping off the lumber, it is automatically issued to "harvest" again.

I sort of half-tested this in my attempt to create a custom lumber resource system but I didn't get very far with it. Anyway you could check when a unit is issued to "resumeharvest" (or if it's issued a "smart" order on a Town Hall, Lumber Mill, etc.) and add a dummy ability to the worker, then have another check to see if a worker has the dummy ability when a unit is issued to "harvest." If so, you know that it dropped off the lumber and can remove the dummy ability. Voila!

My only possible concern is when a tree dies and the worker switches to another tree, or when it's sent to gather lumber after being ordered to resumeharvest but before making it to the drop-off building, but I can't test this at the moment. However this should be a good starting point.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,208
My only possible concern is when a tree dies and the worker switches to another tree, or when it's sent to gather lumber after being ordered to resumeharvest but before making it to the drop-off building, but I can't test this at the moment. However this should be a good starting point.
One could increase accuracy by combining it with...
player.gif
Player - Player 1 (Red)'s Current lumber becomes Greater than 0.00
Lumber will have been returned if both the order and the income occur. One could also get how much was returned to a high degree of accuracy as well as by which unit.

Such a system would start with whichever event occurs first. The event occurrence will then be cached temporarily in some form, eg a queue where elements last a fraction of a second. The event that happens last then looks up the event occurrences of the first event and filters them for any that could possibly match what has occurred, in this case that a resume order was issued almost at the same time as the income. Processed events are immediately removed to further improve accuracy. Other triggers can then be run, being passed a unit and an income quantity.

The accuracy will not be perfect. Cases such as where multiple harvesters return lumber at exactly the same time for the same player might cause the wrong unit to be credited with the wrong amount. Lumber bounty earned around the same time as lumber is returned might credit the unit with the wrong amount.

A similar two-stage system is used to create a "Units places a foundation" event. In such a case foundation orders are cached and matched in response to a unit starts construction. The accuracy can be perfect between players with only a small chance of crediting the wrong builder within the same player.
 
Last edited:
Status
Not open for further replies.
Top