# [Trigger]Harvesters to drop gold

#### Tristex

Level 1
I've been working on a system to make peasants and peons drop their gold-sack upon death. It is a little bit flimsy in my opinion as there is no way to detect the moment that the harvest/resumeharvesting order is completed, still I am happy enough with what I have to consider implementing it with the exception of one thing that I am asking for help with.

Here's what I have

• Exit Mine
• Events
• Unit - A unit Is issued an order targeting an object
• Conditions
• (Issued order) Equal to (Order(resumeharvesting))
• Or - Any (Conditions) are true
• Conditions
• (Unit-type of (Ordered unit)) Equal to Peon
• (Unit-type of (Ordered unit)) Equal to Peasant
• Actions
• Unit Group - Pick every unit in (Units of type Gold Mine) and do (Actions)
• Loop - Actions
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• (Distance between (Position of (Ordered unit)) and (Position of (Picked unit))) Less than or equal to 256.00
• Then - Actions
• Unit - Set the custom value of (Ordered unit) to -1
• Else - Actions
• Unit Group - Pick every unit in (Units of type Dropped) and do (Actions)
• Loop - Actions
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• (Resource quantity contained in (Picked unit)) Equal to 1
• (Distance between (Position of (Ordered unit)) and (Position of (Picked unit))) Less than or equal to 128.00
• (Custom value of (Ordered unit)) Not equal to -1
• Then - Actions
• Unit - Set the custom value of (Ordered unit) to -1
• Unit Group - Pick every unit in (Units within 128.00 of (Position of (Picked unit)) matching (((Unit-type of (Matching unit)) Equal to Dropped) and ((Custom value of (Matching unit)) Equal to ((Custom value of (Picked unit)) + 1)))) and do (Actions)
• Loop - Actions
• Unit - Remove (Picked unit) from the game
• Unit - Remove (Picked unit) from the game
• Else - Actions
• Drop Gold
• Events
• Unit - A unit Dies
• Conditions
• (Custom value of (Dying unit)) Equal to -1
• Or - Any (Conditions) are true
• Conditions
• (Unit-type of (Dying unit)) Equal to Peon
• (Unit-type of (Dying unit)) Equal to Peasant
• Actions
• Unit - Create 1 Dropped for Neutral Passive at (Position of (Dying unit)) facing Default building facing degrees
• Neutral Building - Set (Last created unit) to 11 gold
• Unit - Set the custom value of (Last created unit) to (GoldPair x 2)
• Animation - Change (Last created unit)'s size to (0.01%, 0.01%, 0.01%) of its original size
• Unit - Create 1 Dropped for Neutral Passive at (Position of (Dying unit)) facing Default building facing degrees
• Neutral Building - Set (Last created unit) to 10 gold
• Unit - Set the custom value of (Last created unit) to ((GoldPair x 2) + 1)
• Set GoldPair = (GoldPair + 1)
• Switch Gold
• Events
• Unit - A unit Is issued an order targeting an object
• Conditions
• (Unit-type of (Target unit of issued order)) Equal to Dropped
• (Resource quantity contained in (Target unit of issued order)) Equal to 10
• Or - Any (Conditions) are true
• Conditions
• (Unit-type of (Ordered unit)) Equal to Peon
• (Unit-type of (Ordered unit)) Equal to Peasant
• Actions
• Unit Group - Pick every unit in (Units within 128.00 of (Position of (Target unit of issued order)) matching (((Unit-type of (Matching unit)) Equal to Dropped) and ((Custom value of (Matching unit)) Equal to ((Custom value of (Target unit of issued order)) - 1)))) and do (Actions)
• Loop - Actions
• Unit - Order (Ordered unit) to Harvest (Picked unit)
• Reset Harvest
• Events
• Unit - A unit Is issued an order targeting an object
• Conditions
• Or - Any (Conditions) are true
• Conditions
• (Unit-type of (Target unit of issued order)) Equal to Gold Mine
• (Unit-type of (Target unit of issued order)) Equal to Dropped
• Or - Any (Conditions) are true
• Conditions
• (Issued order) Equal to (Order(harvest))
• (Issued order) Equal to (Order(smart))
• Or - Any (Conditions) are true
• Conditions
• (Unit-type of (Ordered unit)) Equal to Peon
• (Unit-type of (Ordered unit)) Equal to Peasant
• Actions
• Unit - Set the custom value of (Ordered unit) to 0
My question is in the Reset Harvest function, does anyone know of or have any suggestions for detecting when a peasant/peon returns the dropped gold?
As it is the problem is that the worker doesn't receive the harvest order when they can't find their previous mine. My hope was that they would look for the nearest mine if it was close enough no they do not. Can I detect the animation change? I have looked around for something like that (GUI) but have had no luck.

Edit: [trigger][/trigger] tag learning curve. Please excuse my inexperience.

Last edited:

#### streetpunk

Level 11
maybe if you don't use the deafult harvast from w3 and trigger something equal you could detect when the unit returns the gold. you could make an building to drop the resource however it would't be done automaticaly, instead it would be triggered. something like unit enter region near drop building, remove resource from unit, add it to the player then order the unit to go back to work.

#### Tristex

Level 1
I keep thinking more and more now that I should do something like that. It's late now and my brober just came in to town so I've been very distracted but I think I am going to do basically what you have said but I think I'll overhaul the custom value aspect of the system in order to identify if the worker has just harvested a real gold mine or a dropped gold pouch and then I can just tell all the pouch harvesters to find the nearest gold mine and harvest, or just remove their custom value so they dont die and drop gold after the player already has recieved the gold

To explain the issue I am dealing with in more detail, the system appears to work wonderfully for my purposes (I really just want the system to be very simple and transferable because I was doing it more as an exercise and want it to be potentially useful to someone).
The issue that I have is that if a unit harvests from a dropped gold pouch and completes the order, their mine has been removed so no resumeharvesting order is issued to trigger the reset of the worker's custom value, so it will drop a "free" gold pouch if it dies with convenient timing. This also occurs to the last worker's to leave a gold mine as it collapses

But thank you for your suggestion, I'm going to mess around with it tomorrow and see what works out, for now I need sleep.

#### BloodSoul

Level 13
A few days ago another person asked for help to make a new way of gold mining. I've started making one myself, and I just need to adjust and fix a few things. However, it's a little bit different than the original way of collecting gold (get in a gold mine, then the worker appears and delivers the gold). It actually makes the worker collect gold like harvesting lumber. If you're interested in it, let me know, so I post the code (JASS) as soon as I finish it.

Replies
4
Views
284
Replies
0
Views
401
Replies
3
Views
545
Replies
6
Views
785
Replies
4
Views
631