Ok... Do this:
Place a gold mine, and one worker, and a townhall to deliver the gold.
Every 0.5 second of game time
Game - Display Text -> Current order of YourWorker <gen>
That way you can know what's the worker doing, and what changes when he goes inside and outside the gold mine.
EDIT: If you "right click" the mine, the order is "smart". When the worker gets out of the mine carrying the gold, the action is "resume harvesting", same than "return resources" actions. When you order "harvest" the unit, the action is "harvest". Same happens with trees.
You would have to add peasants to a unit group, and pick every 0.03 segs every unit in that unit group, and if the action is "resume harvest" and the unit is in (Units within xxxx distance from Unit of Type Gold Mine) then-> Give the item. Of course, removing the leaks.
EDIT2: This may work. It has leaks and it's poorly done (it's 2:20am) but may give you a clue. Just like it's, it creates the item only if the worker is really near to the gold mine right after he leaves the gold mine.
EDIT3: Tried to fix triggers a bit.
EDit 4: Map added
-
Melee Initialization
-
Events
-
Conditions
-
Actions
-
Melee Game - Create starting units (for all players)
-
Unit - Create 1 Peasant for Player 1 (Red) at (Center of (Playable map area)) facing Default building facing degrees
-
Set GoldMines = (Units of type Gold Mine)
-
Hashtable - Create a hashtable
-
Set MineHash = (Last created hashtable)
-
Untitled Trigger 002
-
Events
-
Unit - A unit enters (Playable map area)
-
Conditions
-
(Unit-type of (Triggering unit)) Equal to Peasant
-
Actions
-
Unit Group - Add (Triggering unit) to Peasants
-
Untitled Trigger 001
-
Events
-
Time - Every 0.05 seconds of game time
-
Conditions
-
Actions
-
Game - Display to (All players) the text: (String((Current order of (Last created unit))))
-
Unit Group - Pick every unit in Peasants and do (Actions)
-
Loop - Actions
-
Set Unit = (Picked unit)
-
Custom script: set udg_i = GetHandleId(udg_Unit)
-
Set TPoint = (Position of Unit)
-
Set TGroup = (Units within 325.00 of TPoint matching ((Unit-type of (Matching unit)) Equal to Gold Mine))
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
-
(Number of units in TGroup) Greater than 0
-
(Current order of Unit) Equal to (Order(resumeharvesting))
-
(Load 0 of i from MineHash) Equal to False
-
Then - Actions
-
Hero - Create Claws of Attack +15 and give it to Unit
-
Hashtable - Save True as 0 of i in MineHash
-
Else - Actions
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
-
(Number of units in TGroup) Greater than 0
-
(Current order of Unit) Equal to (Order(harvest))
-
(Load 0 of i from MineHash) Equal to True
-
Then - Actions
-
Hashtable - Save False as 0 of i in MineHash
-
Else - Actions
-
Custom script: call RemoveLocation(udg_TPoint)
-
Custom script: call DestroyGroup(udg_TGroup)
I'm not sure, but I guess this is needed to avoid storing unneeded unit data.
-
Untitled Trigger 003
-
Events
-
Conditions
-
(Unit-type of (Triggering unit)) Equal to Peasant
-
Actions
-
Hashtable - Clear all child hashtables of child (Key (Triggering unit)) in MineHash
Doesn't work always. May stop working for one or two trips (Of returning gold) if you give a different order during the process. Don't have the time right now to check why it doesn't work when you interrupt the action (It's 2:36am now)