SRL Archive - OSR Help

TPA Help


okokokok

2012-06-24 16:44:17

Hey guys,

I have been really busy with the TPAs in my script.
I want to mine coal, so i picked a color and did the TPA.
My problem is that the TPA is really jumpy and that my function doesn't even click the coal = /

If someone could help me with the function "FindCoal" and "MineCoal" i would be very gratefull.

program GuildMiner;
{$DEFINE SMART}
{$DEFINE SRL5}

{$i SRL\SRL.simba}
{$i SPS\SPS.simba}
{$i SRL\SRL\skill\mining.simba}


procedure DeclarePlayers;
begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer:= 0;

Players[0].Name := '';
Players[0].Pass := '';
Players[0].Nick := '';
Players[0].Pin := '';
Players[0].Active:= True;
Players[0].BoxRewards := ['oins'];
end;

procedure AntiBan;
begin
if (not(LoggedIn)) then
Exit;
Case Random (1000) of
0..4:
begin
HoverSkill('Constitution', false);
wait(2453+Random(432));
end;
40..44:
begin
HoverSkill('Attack', false);
wait(2453+Random(432));
end;
80..84:
begin
HoverSkill('Strength', false);
wait(2453+Random(432));
end;
120..124:
begin
HoverSkill('Defence', false);
wait(2453+Random(432));
end;
150: BoredHuman;
200..203: PickUpMouse;
250..252: RandomRClick;
300..302: RandomMovement;
350..352: ExamineInv;
400..404:
begin
HoverSkill('random', false);
sleepandmovemouse(276 + Random(100));
PickUpMouse;
ChooseOption('Cancel');
SetAngle(SRL_ANGLE_HIGH);
end;
450..452: BoredHuman;
500..502: PickUpMouse;
550..552: RandomRClick;
600..602: RandomMovement;
650..652: SleepAndMoveMouse(3000 + Random(500));
end;
end;

procedure AntiRandom;
begin
FindNormalRandoms;
LampSkill := 'mining';
LevelUp;
end;

//Thanks For Flight for his awesome BrakeMMouse
Procedure BrakeWindMouse(xs, ys, xe, ye, gravity, wind, minWait, maxWait, targetArea: extended);
var
veloX,veloY,windX,windY,veloMag,dist,randomDist,lastDist: extended;
lastX,lastY,MSP,W,maxStep,D,TDist: integer;
sqrt2,sqrt3,sqrt5,PDist: extended;
begin
MSP := MouseSpeed;
sqrt2:= sqrt(2);
sqrt3:= sqrt(3);
sqrt5:= sqrt(5);

TDist := Distance(Round(xs), Round(ys), Round(xe), Round(ye));
if (TDist < 1) then
TDist := 1; //Let's make sure we never divide by 0
repeat

dist:= hypot(xs - xe, ys - ye);
wind:= minE(wind, dist);
if (dist < 1) then
dist := 1;
PDist := (dist/TDist);
if (PDist < 0.01) then
PDist := 0.01;

if (PDist >= 0.31) then //31% (or higher) dist to destination
begin
D := Round((Round(dist)*0.3));
if (D < 20) then
D := RandomRange(19, 21);
end else if (PDist < 0.31) then
begin
if ((PDist <= 0.30) and (PDist >= 0.20)) then //20%-30%
D := RandomRange(13, 16)
else if ((PDist < 0.20) and (PDist > 0.09)) then //10%-19%
D := RandomRange(8, 12)
else if (PDist < 0.10) then //< 10%
D := RandomRange(4, 7);
end;


if (D <= Round(dist)) then
maxStep := D
else
maxStep := Round(dist);

if dist >= targetArea then
begin
windX:= windX / sqrt3 + (random(round(wind) * 2 + 1) - wind) / sqrt5;
windY:= windY / sqrt3 + (random(round(wind) * 2 + 1) - wind) / sqrt5;
end else
begin
windX:= windX / sqrt2;
windY:= windY / sqrt2;
end;

veloX:= veloX + windX;
veloY:= veloY + windY;
veloX:= veloX + gravity * (xe - xs) / dist;
veloY:= veloY + gravity * (ye - ys) / dist;

if hypot(veloX, veloY) > maxStep then
begin
randomDist:= maxStep / 2.0 + random(round(maxStep) div 2);
veloMag:= sqrt(veloX * veloX + veloY * veloY);
veloX:= (veloX / veloMag) * randomDist;
veloY:= (veloY / veloMag) * randomDist;
end;

lastX:= Round(xs);
lastY:= Round(ys);
xs:= xs + veloX;
ys:= ys + veloY;

if (lastX <> Round(xs)) or (lastY <> Round(ys)) then
MoveMouse(Round(xs), Round(ys));

W := (Random(100/MSP))*3;
if (W < 5) then
W := 5;
W := Round(W*1.5);
wait(W);
lastdist:= dist;
until(hypot(xs - xe, ys - ye) < 1)
ClearDebug;

if (Round(xe) <> Round(xs)) or (Round(ye) <> Round(ys)) then
MoveMouse(Round(xe), Round(ye));

MouseSpeed := MSP;
end;

Procedure BrakeMMouse(eX, eY, ranX, ranY: Integer);
var
randSpeed: extended;
X,Y,MS: integer;
begin
MS := MouseSpeed;
randSpeed := (random(MouseSpeed) / 2.0 + MouseSpeed) / 10.0;
GetMousePos(X, Y);
BrakeWindMouse(X, Y, eX, eY, 8, 5, 10.0 / randSpeed, 15.0 / randSpeed, 10.0 * randSpeed);
MouseSpeed := MS;
end;

function BankBoothColor: Integer;
var
arP: TPointArray;
arC: TIntegerArray;
tmpCTS, i, arL: Integer;
X, Y, Z: Extended;
begin
tmpCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.08, 0.25);

FindColorsSpiralTolerance(MMCX, MMCY, arP, 5206413, MMX1, MMY1, MMX2, MMY2, 2);
if (Length(arP) = 0) then
begin
Writeln('Failed to find the color, no result.');
ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);
Exit;
end;

arC := GetColors(arP);
ClearSameIntegers(arC);
arL := High(arC);

for i := 0 to arL do
begin
ColorToXYZ(arC[i], X, Y, Z);

if (X >= 16.94) and (X <= 19.58) and (Y >= 16.69) and (Y <= 19.37) and (Z >= 9.33) and (Z <= 10.71) then
begin
Result := arC[i];
Writeln('AutoColor = ' + IntToStr(arC[i]));
Break;
end;
end;

ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);

if (i = arL + 1) then
Writeln('AutoColor failed in finding the color.');
end;

function CoalColor: Integer;
var
arP: TPointArray;
arC: TIntegerArray;
tmpCTS, i, arL: Integer;
X, Y, Z: Extended;
begin
tmpCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.00, 0.38);

FindColorsSpiralTolerance(MSCX, MSCY, arP, 1513496, MSX1, MSY1, MSX2, MSY2, 5);
if (Length(arP) = 0) then
begin
Writeln('Failed to find the color, no result.');
ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);
Exit;
end;

arC := GetColors(arP);
ClearSameIntegers(arC);
arL := High(arC);

for i := 0 to arL do
begin
ColorToXYZ(arC[i], X, Y, Z);

if (X >= 0.36) and (X <= 1.60) and (Y >= 0.38) and (Y <= 1.69) and (Z >= 0.39) and (Z <= 1.77) then
begin
Result := arC[i];
Writeln('AutoColor = ' + IntToStr(arC[i]));
Break;
end;
end;

ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);

if (i = arL + 1) then
Writeln('AutoColor failed in finding the color.');
end;

Function FindCoal(var x,y:integer): Boolean;
var
Ax,Ay: Integer;
TPA: TPointArray;
ATPA: T2DPointArray;
i: Integer;
begin
FindColorsSpiralTolerance(Ax,Ay,TPA, CoalColor,MSX1,MSY1,MSX2,MSY2,16);
begin
ATPA := SplitTPA(TPA,10);
for i:= 0 To High(ATPA) do
if MiddleTPAEX(ATPA[i],Ax,Ay) then
BrakeMMouse(Ax,Ay,0,0);
if WaitUpText('coal', 400+Random(100)) then
begin
x := Ax;
y := Ay;
Writeln('Found Coal');
Result := True;
end;
Exit;
end;
end;

Procedure MineCoal;
var x,y: Integer;
begin
ClearDebug;
Writeln('Looking for Coal');
MakeCompass('N');
SetAngle(SRL_ANGLE_HIGH);

repeat
if FindCoal(x,y) then
Writeln('Coal Found');
begin
BrakeMMouse(x,y,0,0);
Wait(50 + random(50));
Mouse(x,y,0,0,false);
repeat
Wait(100 + random(50));
ChooseOption('Coal');
Until not IsUpText('oal') or (InvFull);
end;
until (InvFull);
end;

Procedure CustomFEBBanking;
var x,y,i: Integer;
BankBooth: Array [0..1] of Integer;
Spot: TPointArray;
begin
ClearDebug;
Writeln('Looking for Booth');
MakeCompass('S');
SetAngle(SRL_ANGLE_HIGH);
BankBooth[0]:= DTMFromString('mQwAAAHicY2ZgYBBjhGBJIK4G8isYIPT0yhCGSSWBYBoZMCJhIAAA4c0F3A==');
BankBooth[1]:= DTMFromString('mQwAAAHicY2ZgYJBkhGAZIG4B8tsZIHSary5DgocWmEYGjEgYCAC1FgR5');

If FindDTM(BankBooth[i],x,y,MSX1,MSY1,MSX2,MSY2) then
begin
BrakeMMouse(x,y,0,0);
Writeln('Bank Booth Found');
Mouse(x,y,1,1,false);
ChooseOption('ank');
Writeln('Bank Opened');
Wait(3000 + random(500));
end
else

If (Not(FindDTM(BankBooth[i],x,y,MSX1,MSY1,MSX2,MSY2))) then
begin
Writeln('Repositioning');
SPS_Setup(RUNESCAPE_SURFACE,['9_8']);
Spot := [Point(3887, 3233)];
SPS_WalkToPos(Point(3887, 3233));
Writeln('Back in position')
end;

If (Not(BankScreen)) then
begin
Writeln('Bank did not open the first time');
If FindDTM(BankBooth[i],x,y,MSX1,MSY1,MSX2,MSY2) then
begin
BrakeMMouse(x,y,0,0);
Writeln('Bank Booth Found');
Mouse(x,y,1,1,false);
ChooseOption('ank');
Writeln('Bank Opened');
Wait(3000 + random(500));
end;
end;

If (Not(BankScreen)) then
begin
Writeln('Bank did not open the second time');
If FindDTM(BankBooth[i],x,y,MSX1,MSY1,MSX2,MSY2) then
begin
BrakeMMouse(x,y,0,0);
Writeln('Bank Booth Found');
Mouse(x,y,1,1,false);
ChooseOption('ank');
Writeln('Bank Opened');
Wait(3000 + random(500));
end;
end;

If (Not(BankScreen)) then
begin
Writeln('Bank did not open the third time');
If FindDTM(BankBooth[i],x,y,MSX1,MSY1,MSX2,MSY2) then
begin
BrakeMMouse(x,y,0,0);
Writeln('Bank Booth Found');
Mouse(x,y,1,1,false);
ChooseOption('ank');
Writeln('Bank Opened');
Wait(3000 + random(500));
end;
end;
FreeDTM(BankBooth[0]);
FreeDTM(BankBooth[1]);
end;

Procedure DepositCoal;
var x,y: Integer;
begin
ClearDebug;
If (PinScreen) then
InPin(Players[0].Pin);

If (BankScreen) then
Begin
Writeln('In the Bank');
DepositAll;
Writeln('Everything Banked');
CloseBank;
end;
end;

procedure WalkToGuild;
var x,y: Integer;
myPath: TPointArray;
begin
ClearDebug;
MakeCompass('N');
SetAngle(SRL_ANGLE_HIGH);
writeln('To Guild')
SPS_Setup(RUNESCAPE_SURFACE,['9_8','9_7','10_7','10_8']);
myPath := [Point(3886, 3235), Point(3886, 3229), Point(3888, 3222), Point(3893, 3215), Point(3900, 3215), Point(3908, 3215), Point(3915, 3217), Point(3919, 3223), Point(3924, 3228), Point(3927, 3233), Point(3927, 3239), Point(3931, 3244), Point(3932, 3248), Point(3939, 3253), Point(3947, 3257), Point(3954, 3262), Point(3955, 3267), Point(3955, 3273), Point(3958, 3282), Point(3958, 3289), Point(3957, 3296), Point(3957, 3302), Point(3955, 3309), Point(3948, 3309), Point(3941, 3309), Point(3931, 3309), Point(3924, 3307), Point(3918, 3303)];
SPS_WalkPath(myPath);
Writeln('Arrived at Guild');
Wait(1000 + Random(200));
end;

procedure WalkToCoal;
var x,y: Integer;
myPath: TPointArray;
begin
ClearDebug;
Writeln('To Coal');
MakeCompass('N');
SetAngle(SRL_ANGLE_HIGH);
SPS_Setup(RUNESCAPE_OTHER,['dwarven_mine']);
myPath := [Point(292, 537), Point(298, 539), Point(303, 539), Point(311, 539), Point(319, 538), Point(325, 538), Point(331, 538), Point(341, 538), Point(347, 538), Point(355, 538), Point(361, 538), Point(368, 538), Point(378, 535)];
SPS_WalkPath(myPath);
Writeln('Arrived at Coal');
Wait(1000 + Random(200));
end;

procedure WalkToLadder;
var x,y: Integer;
myPath: TPointArray;
begin
ClearDebug;
MakeCompass('N');
SetAngle(SRL_ANGLE_HIGH);
writeln('To Ladder')
SPS_Setup(RUNESCAPE_OTHER,['dwarven_mine']);
myPath := [Point(379, 537), Point(373, 537), Point(362, 536), Point(353, 533), Point(343, 533), Point(335, 535), Point(330, 537), Point(319, 538), Point(315, 536), Point(306, 534), Point(302, 537), Point(295, 539)];
SPS_WalkPath(myPath);
Writeln('Arrived at Ladder');
Wait(2000 + random(200));
end;

procedure WalkToBank;
var x,y: Integer;
myPath: TPointArray;
begin
ClearDebug;
MakeCompass('N');
SetAngle(SRL_ANGLE_HIGH);
writeln('To Bank')
SPS_Setup(RUNESCAPE_SURFACE,['9_8','9_7','10_7','10_8']);
myPath := [Point(3917, 3308), Point(3924, 3310), Point(3933, 3310), Point(3942, 3310), Point(3955, 3309), Point(3954, 3302), Point(3954, 3293), Point(3955, 3284), Point(3955, 3277), Point(3953, 3267), Point(3946, 3260), Point(3936, 3254), Point(3933, 3248), Point(3932, 3239), Point(3929, 3230), Point(3924, 3224), Point(3914, 3220), Point(3910, 3217), Point(3901, 3214), Point(3893, 3214), Point(3890, 3217), Point(3889, 3223), Point(3893, 3226), Point(3894, 3229), Point(3897, 3234), Point(3898, 3240)];
SPS_WalkPath(myPath);
Writeln('Arrived at Bank');
Wait(1000 + Random(200));
end;

Procedure ClimbDownLadder;
var x,y,i: Integer;
Ladder: Array [0..3] of Integer;
Spot: TPointArray;
begin
ClearDebug;
Writeln('Ladder Time');
MakeCompass('N');
SetAngle(SRL_ANGLE_HIGH);
Ladder[0]:= DTMFromString('mQwAAAHicY2ZgYFgJxWuA+AAQ74HSLja6DAoSXGAaGTAiYSAAABa6Bd0=');
Ladder[1]:= DTMFromString('mQwAAAHicY2ZgYFgMxcuAeDUQr4DS9dnuDO2F3mAaGTAiYSAAAEzMB5Y=');
Ladder[2]:= DTMFromString('mQwAAAHicY2ZgYNgIxBuAeAsQrwXiVVC6LM6YoSrRFEwjA0YkDAQARYoHPg==');
Ladder[3]:= DTMFromString('mQwAAAHicY2ZgYFgJxWuAeA8Q74TSChJcDJF+1mAaGTAiYSAAAA2PBZw=');

If FindDTM(Ladder[i],x,y,MSX1,MSY1,MSX2,MSY2) then
begin
BrakeMMouse(x,y,1,1);
Writeln('Ladder Found');
Mouse(x,y,0,0,false);
ChooseOption('limb');
Writeln('Climbing Down Ladder');
Wait(2000 + random(200));
end
else

If FindDTM(Ladder[i],x,y,MSX1,MSY1,MSX2,MSY2) then
begin
BrakeMMouse(x,y,1,1);
Writeln('Ladder Found');
Mouse(x,y,0,0,false);
ChooseOption('limb');
Writeln('Climbing Down Ladder');
Wait(2000 + random(200));
end
else

If FindDTM(Ladder[i],x,y,MSX1,MSY1,MSX2,MSY2) then
begin
BrakeMMouse(x,y,1,1);
Writeln('Ladder Found');
Mouse(x,y,0,0,false);
ChooseOption('limb');
Writeln('Climbing Down Ladder');
Wait(2000 + random(200));
end;
FreeDTM(Ladder[0]);
FreeDTM(Ladder[1]);
FreeDTM(Ladder[2]);
FreeDTM(Ladder[3]);
end;

Procedure ClimbUpLadder;
var x,y,i: Integer;
Ladder: Array [0..7] of Integer;
Spot: TPointArray;
begin
ClearDebug;
Writeln('Ladder Time');
MakeCompass('N');
SetAngle(SRL_ANGLE_HIGH);
Ladder[0]:= DTMFromString('mQwAAAHicY2ZgYDgLxKeg9HooXgPEof6ODAHetgwuTtYMyIARCQMBAEOmBvM=');
Ladder[1]:= DTMFromString('mQwAAAHicY2ZgYDBlhGALIL4G5F9mgNCmWuIM7k5mYBoZMCJhIAAA1XkE1g==');
Ladder[2]:= DTMFromString('mQwAAAHicY2ZgYDgLxKegdBoUJwOxn6cNGFvoSDAgA0YkDAQAEBkFvA==');
Ladder[3]:= DTMFromString('mQwAAAHicY2ZgYDBlhGALID4C5B9kgNBB/u4MplriYBoZMCJhIAAA4AwFOw==');
Ladder[4]:= DTMFromString('mQwAAAHicY2ZgYDgGxIeh9EcofgfE3m5WDE62Rgz2tuYMyIARCQMBAFh0B1U=');
Ladder[5]:= DTMFromString('mQwAAAHicY2ZgYNgBxFuhtA0jBFsCcXiwN0NooCeYRgaMSBgIAAHOBbk=');
Ladder[6]:= DTMFromString('mQwAAAHicY2ZgYLBnhGAnIJYAYlEoHeTvzuDn7QymkQEjEgYCAJY9A74=');
Ladder[7]:= DTMFromString('mQwAAAHicY2ZgYIhhhOB4IP4N5P9ggNBOtkYMni4WYBoZMCJhIAAAFTwGNg==');

If FindDTM(Ladder[i],x,y,MSX1,MSY1,MSX2,MSY2) then
begin
BrakeMMouse(x,y,1,1);
Writeln('Ladder Found');
Mouse(x,y,0,0,false);
ChooseOption('limb');
Writeln('Climbing Down Ladder');
Wait(2000 + random(200));
end
else

If FindDTM(Ladder[i],x,y,MSX1,MSY1,MSX2,MSY2) then
begin
BrakeMMouse(x,y,1,1);
Writeln('Ladder Found');
Mouse(x,y,0,0,false);
ChooseOption('limb');
Writeln('Climbing Up Ladder');
Wait(2000 + random(200));
end;
FreeDTM(Ladder[0]);
FreeDTM(Ladder[1]);
FreeDTM(Ladder[2]);
FreeDTM(Ladder[3]);
FreeDTM(Ladder[4]);
FreeDTM(Ladder[5]);
FreeDTM(Ladder[6]);
FreeDTM(Ladder[7]);

end;





procedure OneRun;
begin
//ClearDebug;
//WalkToGuild;
//ClimbDownLadder;
//WalkToCoal;
//MineCoal;
findthething;
//WalkToLadder;
//ClimbUpLadder;
//WalkToBank;
//CustomFEBBanking;
//DepositCoal;
end;



begin
Smart_Server := 17;
Smart_Members := false;
Smart_Signed := true;
Smart_SuperDetail := false;
clearDebug();
setupSRL;
DeclarePlayers;
if (Not(LoggedIn)) then
begin
LogInPlayer;
Wait(2500 + Random(1500));
end;
OneRun;
end.

Thanks in advance.

P1ng

2012-06-24 18:55:09

Function FindCoal(var x,y:integer): Boolean;
var
Ax,Ay: Integer;
TPA: TPointArray;
ATPA: T2DPointArray;
i: Integer;
begin
FindColorsSpiralTolerance(Ax,Ay,TPA, CoalColor,MSX1,MSY1,MSX2,MSY2,16);
begin
ATPA := SplitTPA(TPA,10);
for i:= 0 To High(ATPA) do
if MiddleTPAEX(ATPA[i],Ax,Ay) then //no need for if then here imo
BrakeMMouse(Ax,Ay,0,0);
if WaitUpText('coal', 400+Random(100)) then //i'd make the uptext 'oal'
begin
x := Ax; //use GetMousePos(x,y);
y := Ay;
Writeln('Found Coal');
Result := True;
end;
Exit; //Add a writeln here so you know when it hasn't found the uptext
end;
end;

Procedure MineCoal;
var x,y: Integer;
begin
ClearDebug;
Writeln('Looking for Coal');
MakeCompass('N');
SetAngle(SRL_ANGLE_HIGH);

repeat
if FindCoal(x,y) then
Writeln('Coal Found');
begin
BrakeMMouse(x,y,0,0); // This and the two lines below with ClickMouse2(mouse_Right);
Wait(50 + random(50)); // Because your FindCoal has already moved the mouse to those x,y co-ordinates.
Mouse(x,y,0,0,false);
repeat
Wait(100 + random(50)); // Instead of a wait with chooseoption try using WaitOption('oal',RandomRange(1000,1500));
ChooseOption('Coal'); // I also wouldn't use coal as the option because I'm assuming all options will have that word.
Until not IsUpText('oal') or (InvFull);
end;
until (InvFull);
end;

okokokok

2012-06-25 02:32:15

Thanks for your feedback. It helps the process a little bit, but the mouse is still flying over the rocks and clicking accidentally. I have adjusted the waitoption etc. But it's still not working good.

Edit:
This is how the function and procedure look like now. It's alot better, but still pretty bad banwise.


Function FindCoal(var x,y:integer): Boolean;
var
Ax,Ay: Integer;
TPA: TPointArray;
ATPA: T2DPointArray;
i: Integer;
begin
FindColorsSpiralTolerance(Ax,Ay,TPA, CoalColor,MSX1,MSY1,MSX2,MSY2,16);
begin
ATPA := SplitTPA(TPA,10);
for i:= 0 To High(ATPA) do
MiddleTPAEX(ATPA[i],Ax,Ay); //no need for if then here imo
BrakeMMouse(Ax,Ay,0,0);
if WaitUpText('ocks', 400+Random(100)) then //i'd make the uptext 'oal'
begin
GetMousePos(x,y);
Writeln('Found Coal');
Result := True;
end;
Writeln('Coal not found');
Exit; //Add a writeln here so you know when it hasn't found the uptext
end;
end;

Procedure MineCoal;
var x,y: Integer;
begin
ClearDebug;
Writeln('Looking for Coal');
MakeCompass('N');
SetAngle(SRL_ANGLE_HIGH);

repeat
if FindCoal(x,y) then
Writeln('Coal Found');
begin
ClickMouse2(mouse_Right);
repeat
WaitOption('Min',RandomRange(1000,1500)); // I also wouldn't use coal as the option because I'm assuming all options will have that word.
Break;
Until not IsUpText('oal') or (InvFull);
end;
until (InvFull);
end;

Brandon

2012-06-25 03:03:59


{$DEFINE SMART}
{$I SRL/SRL.Simba}

Function FindObjectMS(Color, Tolerance: Integer; Speed: TExtendedArray): TPointArray;
var
CTS: Integer;
TPA: TPointArray;
begin
if (Length(Speed) < 2) then
Exit;
CTS:= GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(Speed[0], Speed[1]);
FindColorsTolerance(TPA, Color, MSX1, MSY1, MSX2, MSY2, Tolerance);
ColorToleranceSpeed(CTS);
SetColorSpeed2Modifiers(0.02, 0.02);
Result:= TPA;
end;

Function FindObjectInObject(TPA: TPointArray; Color, Width, Height, Tolerance: Integer; Speed: TExtendedArray): TPointArray;
var
CTS, L, I: Integer;
TPACopy: TPointArray;
ATPA, ATPA2: T2DPointArray;
B: TBox;
begin
if (Length(Speed) < 2) then
Exit;
CTS:= GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(Speed[0], Speed[1]);

if (Length(TPA) < 1) then
Exit;

TPACopy:= TPA;//CopyTPA(TPA);
if (Length(TPACopy) < 1) then
Exit;

ATPA:= TPAToATPAEx(TPACopy, Width, Height);
SortATPASize(ATPA, True);
L := High(ATPA);
SetArrayLength(ATPA2, L+1);

For I:= 0 To L do
begin
B := GetTPABounds(ATPA[I]);
with B do
begin
FindColorsTolerance(ATPA2[I], Color, B.X1, B.Y1, B.X2, B.Y2, Tolerance);
if (Length(ATPA2[I]) < 1) then
Continue;
end;
end;
if (Length(ATPA2) > 0) then
Result:= MergeATPA(ATPA2)
else
Result:= [];

ColorToleranceSpeed(CTS);
SetColorSpeed2Modifiers(0.02, 0.02);
end;

Function FindCoal(var Rock: TPoint): Boolean;
var
BrownRock, CoalRocks: TPointArray;
AllRocks: T2DPointArray;
begin
BrownRock:= FindObjectMS(3825003, 15, [0.04, 0.65]);
if (Length(BrownRock) < 1) then Exit;

CoalRocks:= FindObjectInObject(BrownRock, 1579289, 46, 44, 5, [0.00, 0.34]);
if (Length(CoalRocks) < 1) then Exit;

AllRocks:= TPAToATPAEx(CoalRocks, 46, 44);
Result:= Length(AllRocks) > 0;
if (Not Result) then Exit;

SortATPAFromFirstPoint(AllRocks, Point(MSCX, MSCY));
Rock:= MiddleTPA(AllRocks[0]);
Result:= True;
end;

var
Rock: TPoint;

begin
SETUPSRL;
if FindCoal(Rock) then
MMouse(Rock.X, Rock.Y, 0, 0);
end.


From my own include. It always works for any rock or object. Doesn't matter how close or far apart the colours are. Wasn't planning on giving out the code just yet but hey why not. Try it and let me know how it works for you. I only tested the above in the mining guild.

okokokok

2012-06-25 03:22:27

From: Brandon

{$DEFINE SMART}
{$I SRL/SRL.Simba}

Function FindObjectMS(Color, Tolerance: Integer; Speed: TExtendedArray): TPointArray;
var
CTS: Integer;
TPA: TPointArray;
begin
if (Length(Speed) < 2) then
Exit;
CTS:= GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(Speed[0], Speed[1]);
FindColorsTolerance(TPA, Color, MSX1, MSY1, MSX2, MSY2, Tolerance);
ColorToleranceSpeed(CTS);
SetColorSpeed2Modifiers(0.02, 0.02);
Result:= TPA;
end;

Function FindObjectInObject(TPA: TPointArray; Color, Width, Height, Tolerance: Integer; Speed: TExtendedArray): TPointArray;
var
CTS, L, I: Integer;
TPACopy: TPointArray;
ATPA, ATPA2: T2DPointArray;
B: TBox;
begin
if (Length(Speed) < 2) then
Exit;
CTS:= GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(Speed[0], Speed[1]);

if (Length(TPA) < 1) then
Exit;

TPACopy:= TPA;//CopyTPA(TPA);
if (Length(TPACopy) < 1) then
Exit;

ATPA:= TPAToATPAEx(TPACopy, Width, Height);
SortATPASize(ATPA, True);
L := High(ATPA);
SetArrayLength(ATPA2, L+1);

For I:= 0 To L do
begin
B := GetTPABounds(ATPA[I]);
with B do
begin
FindColorsTolerance(ATPA2[I], Color, B.X1, B.Y1, B.X2, B.Y2, Tolerance);
if (Length(ATPA2[I]) < 1) then
Continue;
end;
end;
if (Length(ATPA2) > 0) then
Result:= MergeATPA(ATPA2)
else
Result:= [];

ColorToleranceSpeed(CTS);
SetColorSpeed2Modifiers(0.02, 0.02);
end;

Function FindCoal(var Rock: TPoint): Boolean;
var
BrownRock, CoalRocks: TPointArray;
AllRocks: T2DPointArray;
begin
BrownRock:= FindObjectMS(3825003, 15, [0.04, 0.65]);
if (Length(BrownRock) < 1) then Exit;

CoalRocks:= FindObjectInObject(BrownRock, 1579289, 46, 44, 5, [0.00, 0.34]);
if (Length(CoalRocks) < 1) then Exit;

AllRocks:= TPAToATPAEx(CoalRocks, 46, 44);
Result:= Length(AllRocks) > 0;
if (Not Result) then Exit;

SortATPAFromFirstPoint(AllRocks, Point(MSCX, MSCY));
Rock:= MiddleTPA(AllRocks[0]);
Result:= True;
end;

var
Rock: TPoint;

begin
SETUPSRL;
if FindCoal(Rock) then
MMouse(Rock.X, Rock.Y, 0, 0);
end.


From my own include. It always works for any rock or object. Doesn't matter how close or far apart the colours are. Wasn't planning on giving out the code just yet but hey why not. Try it and let me know how it works for you. I only tested the above in the mining guild.


Thanks! It works like a charm! I do see that i have alot to learn about TPAs :P I'll get into TPAs after this week (got exams and stuff). Anyway thanks man! :)