copypaseted in mod to test:
Click "Locate" button, left-click ground - unit moves there.
When the unit comes near the mineral coordinates it says "The Locator is within range of a mineral deposit!"
But then it does not close in on the excact part of the mineral deposit because this part is outside any function and never called:
Code: Select all
if depositLocated == true then
Spring.SetUnitMoveGoal(unitID, metalx, metaly, metalz)
else
end
If delete that there and move it to here:
Code: Select all
if math.abs(metalx - locatorPosX)<=200 and math.abs(metalz - locatorPosZ)<=200 then
Spring.Echo("The Locator is within range of a mineral deposit!")
depositLocated = true
Spring.SetUnitMoveGoal(unitID, metalx, metaly, metalz)
then the locator, if on his locate-travel he gets near a mineral depot will change course towards it.
In fact now the locator feels so attracted towards the minera depot that is impossible to move him away.
That is because reason:
The lolcator must be freed from the
for unitID in pairs(activeLocators) do loop which is calling SetUnitMoveGoal all the time!
There actually is a
activeLocators[unitID] = nil which should free him but does not
work because two reasons:
1)
http://pastebin.com/6NbjeEhW Line 79 the else belongs to the wrong if.
After fixing it, any non-locate command (example: move) should "free" the lolcator from his obession with the mineral deposit.
But only in theory because
2) CommandFallback() is appearently only called for custom commands.
Not for engine ones like move.
Sorry, my mistake. But could have noticed it if you put there an Echo (cmdID) that it always prints your cmdID 34581
So for stopping the lolcator, CommandFallback can not be used like this. But AllowCommand can:
Code: Select all
function gadget:AllowCommand(unitID, unitDefID, teamID, cmdID, cmdParams, cmdOptions)
Spring.Echo (CMD[cmdID])
if cmdID == CMD.STOP then --lolcator giving STOP command and is not active anymore
Spring.Echo ("a stop command in AllowCommand")
activeLocators[unitID] = nil
end
return true
end
Note:
if cmdID ~= CMD_STRT_LOC
or
if cmdID ~= CMD.MOVE
would not work because the gadget gives order itself, too.
(Note the output of the Spring.Echo (CMD[cmdID]) )
gadget with above fixes:
http://pastebin.com/EWi5wyAH
Actually it is all somewhat fumbeldumbel but good luck.