• 🏆 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!

Detect Worker Carrying Resource

Status
Not open for further replies.
Level 2
Joined
Jun 3, 2018
Messages
17
Is there a way to detect when a worker has resources via trigger or other means? I've tried "when unit casts/channels ability" on Harvest but it doesn't work.

Ultimately I just want the peasant to drop gold/lumber if it's killed while carrying it.
 
Level 12
Joined
Nov 3, 2013
Messages
989
You can detect the order ids, if the unit is issued the return resources order then you'd know that it has resources since otherwise it wouldn't be possible for the unit to be ordered to return any resources.

(or actually, the real order name used is "resumeharvesting", and it doesn't show up in the list of orders, so you need to check with order id instead)

public constant integer resumeharvesting=852017 is the one you're looking for.

Edit: Actually scrap that, you only need to use the above to issue the order, but it should work just fine to write "resumeharvesting" when checking for it with conditions.

  • Untitled Trigger 001
    • Events
      • Unit - A unit Is issued an order targeting an object
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Issued order) Equal to (Order(harvest))
        • Then - Actions
          • -------- blablabla --------
        • 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
              • -------- blablabla --------
            • Else - Actions

The only issue(s) is if you manually order the worker to stop harvesting before it's done (thus it won't automatically receive the "resumeharvesting" order), and maybe you don't even order it to return resources, so how would you know whether or not the unit has any?

Similarly, if you can order the unit to return resources without it being automatically being ordered to harvest again (I don't remember if this is possible or not.), then you'll have a similar problem. Since the worker could've dropped of their resources but then the system would still think it has the goods.
 
Level 2
Joined
Jun 3, 2018
Messages
17
Yes, I thought of that method too but because of the issues you listed it won't work. Players would be moving the worker so it won't die.
The harvest ability turns into "return resources" when they have some, there's some variable somewhere that stores how much lumber/gold they have collected, there must be some way to detect this....
 
Level 3
Joined
Apr 1, 2019
Messages
48
As many hardcoded things, I suppose you cannot get that variable, it will be private.

What you want to do is very difficult and complicated. It needs a loads of variables and Jass as I suppose.
The problem would be easier, if there was a way to detect which animation a unit is currently playing - but there is no way to detect that.

I think there is no real method to make that work as you like it, so I suggest a workaround:
Replace the harvest abilities.

I know this is not what you wanted, but it is easier to detect.
I.e. give the unit the "eat tree" ability, to make the unit right click trees easy. When the unit does start casting, order it to stop. Then "Animation"-> play the "Stand Work Lumber"-Animation (I think it is called "stand,work,lumber") and add it to a unit group which you watch on "issued an order" (any order), where you can stop that animation.
Now you think of any way to set the amount of lumber it has achieved till now, there are several.
You use a JASS function for that, if you want to do it that way, I can help you with that.
Anyway, that way you can successful detect the amount of lumber the unit has and that is has lumber carried. The only possibility to lose it, is either a suitable building or dying.
If it dies now, you have what you wanted.
Anyway if that unit stops lumbering or your timer ran out, so the unit has full lumber and that way stops lumbering, you add them to another unit group. Those are the units, that have lumber, but are not gathering.
Of course, if it has full lumber, you issue an order to make it return.
Anyway, you can now detect if a unit of this unit group comes in range of a suitable building to return that ressource (when such building finishes built, add new event, unit comes in range of building, condition: triggering unit is in that unit group).
Then you can return the lumber and even show a text for it if you want, do not forget to remove it out of the unit group.


Well I know that this will be a complicated way, but I really think, that it will be easier.
If you want it that way, I can help you make it work.


For Gold it should be easier, as you need to watch units approach to gold mines.
 
Level 39
Joined
Feb 27, 2007
Messages
5,016
A downside to that is all workers will behave like wisps in that the trees they harvest from will never get chopped down. To retain that functionality you will have to also manually kill the trees yourself. You will also have to do the pathfinding to 'closest lumber depot' yourself too, since the AI automatically returns to the closest such depot unless specifically ordered to do otherwise.
 
Level 3
Joined
Apr 1, 2019
Messages
48
Damaging the tree should be easy, since you already need a loop for each unit.
Returning to the nearest depot is needed too, but I also thought of that.
It is possible to achieve it that way, but it will not 100% look the same and it will cost some resources.
So before I explain it all, I wanted to know if OP is interested in this idea or not.
 
Level 2
Joined
Jun 3, 2018
Messages
17
This all seems too complicated to even bother with it. For lumber it doesn't have to know how much they have, I'd just make it drop 10 when an enemy kills them. Same for gold. Would that be simpler to implement?
 
Level 3
Joined
Apr 1, 2019
Messages
48
Would that be simpler to implement?
Well, I don't think so.

The real problem is to successfully detect when a unit starts chopping a tree and finished returning ressources.


The fact, that in my idea the exact amount is known just comes along naturally.
 
Status
Not open for further replies.
Top