ok from your first post this is the code that i go:
Simba Code:
Function Findiron:boolean;
var
ironTPA: TPointArray;
ironATPA: T2DPointArray;
ironBox: TBox;
i: integer;
begin
Result := false;
SetColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.23, 0.83);
if findcolorstolerance(ironTPA, 6697071, MSX1, MSY1, MSX2, MSY2, 11) then // search for color store in ironTPA
begin
ironATPA:= SplitTPAEx(ironTPA, 5, 5); // split ironTPA into 5x5's
SortATPAFromMidpoint(ironATPA, Point(MSCX, MSCY)); // sort ironATPA from the centre of MS
for i := 0 to high(ironATPA) do // iterate through ironATPA and check
begin
ironBox := GetTPABounds(ironATPA[i]);
SetColorSpeed2Modifiers(0.04, 0.28); // for ore color within the rock
if findcolorstolerance(ironTPA, 4609378, ironBox.x1, ironbox.Y1, ironbox.X2, ironbox.Y2, 15) then
begin
//do whatever you need to do here for example:
MMouse((ironBox.x1 + ironBox.x2) /2, (ironBox.y1 + ironBox.y2) /2, 5, 5); // if or found then move mouse to centre of rock
if IsUpTextEx('ron') then // if the uptext is 'ron'
begin // then left click to mine and then break
clickMouse2(true); // out of for loop
Result = true;
Break;
end;
end;
if i = high(ironATPA) then // if you get to the end of ironATPA and
begin // have found no ores then terminate
writeln('No rocks that can be mined found, terminating ...');
Terminatescript;
end;
end;
end;
SetColorToleranceSpeed(1); // reset toleranceSpeed and modifiers at the
SetColorSpeed2Modifiers(0.02, 0.02); // end of your procedure/function
end;
the looks a lot messier on here :/ the comments were on the right hand side and it looked all prettyful 
EDIT: why if you have just found the index of the rock closest that you can mine, have you then gone and used random to get an index to move the mouse to?
and i believe that by using
Code:
r := random(length(GemTPA));
r can equal length(GemTPA) which is out of bounds, you should use length(GemTPA)-1
EDIT2: or actually, just dont do that.