For detecting a change in resources, simply use a player state event.
native TriggerRegisterPlayerStateEvent trigger whichTrigger, player whichPlayer, playerstate whichState, limitop opcode, real limitval
So to use this to detect someone's gold increasing, your code might look like this
JASS:
local trigger t = CreateTrigger()
local integer playerGold = playerGolds[0]
call TriggerRegisterPlayerStateEvent(t, Player(0), PLAYER_STATE_RESOURCE_GOLD, NOT_EQUAL, playerGold)
call TriggerAddCondition(t, Condition(function main))
Use the limit op NOT_EQUAL so whenever the player's gold isn't equal to what you have stored in your separate variable, the event will fire off. In your main you will need detect by how much the gold changed, change the variable/array member accordingly, and then apply the changes (locally) to the player's leader board.
But then I have to have one of those for all 12 players....Right?
Anyway, okay, so here's what I got so far for the system:
When a unit is ordered to Harvest from a Gold Mine via my fake harvesting ability that is based off of Shadow Strike, and he uses the ability, that's how I pick up on the Worker "Entering" the Gold Mine. Via trigger, I morph the unit into an invisible unit with no movement and no attack, and remove them from the players selection, then after a timer I morph them back into the original unit, remove the dummy Harvest (Shadow Strike) ability, and order them to return to the closest Town Hall, once the dummy Return Resources ability goes off I can pick up on that as a "Unit Starts the Effect of an Ability" event, and set the amount of gold accordingly, without the actual Gold count in the UI being modified at all.
This is what I got so far:
Okay, I finished the base of the system and now I need to make it MUI. I still have some stuff I need to fix but now that I figured everything else out it won't be hard to fix. Once I get it 100% done, cleaned up, and working flawlessly, I'll post it.
There is ONE problem that I'm not quite sure how to fix, though, and that's this:
-
Timer Order Harvest
-
Events
-
Time - Every 0.03 seconds of game time
-
Conditions
-
Actions
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
-
GoldReturningUpdate Equal to 1
-
GoldReturnedTimer Less than 67
-
Then - Actions
-
Set GoldReturnedTimer = (GoldReturnedTimer + 1)
-
Selection - Remove GoldReturningUnit from selection
-
Else - Actions
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
-
GoldReturningUpdate Equal to 1
-
GoldReturnedTimer Equal to 66
-
Then - Actions
-
Unit - Remove Peasant Morph from GoldReturningUnit
-
Unit - Add Peasant Remorph to GoldReturningUnit
-
Else - Actions
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
-
GoldReturningUpdate Equal to 1
-
GoldReturnedTimer Equal to 67
-
Then - Actions
-
Set GoldReturningUpdate = 0
-
Unit - Remove Peasant Remorph from GoldReturningUnit
-
Unit - Add Shadow Strike to GoldReturningUnit
-
Unit - Remove Return Resources from GoldReturningUnit
-
Animation - Remove the gold animation tag to GoldReturningUnit
-
Set GoldReturnedFinished = 1
-
Set PlayerGold[1] = (PlayerGold[1] + 100)
-
Multiboard - Set the text for PlayerResources item in column 1, row 1 to (|c00BBAA00Gold:|r + (String(PlayerGold[1])))
-
Else - Actions
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
-
GoldPointOrder Equal to False
-
Then - Actions
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
-
GoldMineInRange Equal to True
-
Then - Actions
-
Unit - Order GoldReturningUnit to Night Elf Warden - Shadow Strike TargetGoldMine
-
Set GoldMineInRange = False
-
Else - Actions
-
Else - Actions
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
-
GoldPointOrder Equal to False
-
GoldMineInRange Equal to False
-
GoldReturnedFinished Equal to 1
-
Then - Actions
-
Game - Display to (All players) the text: FIRED!
-
Unit - Remove Shadow Strike from GoldReturningUnit
-
Unit - Add Harvest (Point Order) to GoldReturningUnit
-
Unit - Order GoldReturningUnit to Orc Far Seer - Earthquake (Position of TargetGoldMine)
-
Set GoldPointOrder = True
-
Set GoldReturnedFinished = 0
-
Else - Actions
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
-
GoldPointOrder Equal to True
-
GoldMineInRange Equal to False
-
Then - Actions
-
Custom script: set bj_wantDestroyGroup = true
-
Unit Group - Pick every unit in (Units within 500.00 of (Position of GoldReturningUnit)) and do (Actions)
-
Loop - Actions
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
-
(Picked unit) Equal to TargetGoldMine
-
Then - Actions
-
Set GoldMineInRange = True
-
Set GoldPointOrder = False
-
Unit - Remove Harvest (Point Order) from GoldReturningUnit
-
Unit - Add Shadow Strike to GoldReturningUnit
-
Else - Actions
-
Else - Actions
The part I'm having a problem with is near the bottom, "Unit - Order GoldReturningUnit to Orc Far Seer - Earthquake (Position of TargetGoldMine)"
The Position of the Target Gold Mine seems to go a bit off course, heading in an almost different direction. It's not much of a deviation of the course it should take, but it's enough to where lets say if it's going half-way across the map, the worker may never find the Gold Mine....
EDIT2: Okay, I'm going to leave this thread to making the Leaderboard LocalPlayer-able, and make a new thread for working with my Resource Harvesting System.