SRL Archive - OSR Help

Help with clicking a moving shop owner


Cage

2013-09-30 08:27:23

Hello! I am trying to get my script to click on the shop owner and trade her, then to proceed to selling her my items. I need help finding a way to know whether I have successfully traded her (i.e. on shop screen) or I have missed her and in that case trying again. This is what I have so far…. It still loops even when I think I have found the shop screen. (used a colour on the shop screen - any better ways would be appreciated) Anyway, here is my code.



procedure FindShopOwnerFinal;

Var TPA : TPointArray;
tmpCTS, I, X, Y, Found:Integer;
ATPA : T2DPointArray;

begin

repeat
tmpCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.04, 0.37);
FindColorsTolerance(TPA, 1520706, MSX1, MSY1, MSX2, MSY2, 7);
SetColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);
ATPA := TPAToATPAEx(TPA, 20, 20);
DebugATPA(ATPA, ' ');
SortATPASize(ATPA, True);
FindNormalRandoms();

For I := 0 To High(ATPA) Do //Loops through until it finds it
If GetArraylength(ATPA[i]) > 10 Then
begin //Similar to 'length'
MiddleTPAEx(ATPA[i], X, Y); //Finds the middle via averaging
MMouse(X, Y, 3, 3);
sleep(50 + random(200));
WriteLn(GetUpText);
if waituptext('Talk', 300) then
begin
sleep(300 + random(200));
clickmouse2(mouse_right);
sleep(300 + random(200));
chooseoption('Trade');
sleep(8000 + random(3000));
if FindColorTolerance(x,y,1692278,MSX1,MSY1,MSX2,MSY2,10) then
WriteLn('Color Found ');
break;
end else
FindShopOwnerFinal;



end;




until (False);
FindTheESSDTM;
end;

Olly

2013-09-30 09:15:15

You could try something like this. :)

function FindShopOwnerFunc(): boolean;
var
TPA : TPointArray;
tmpCTS, I, X, Y, Found:Integer;
ATPA : T2DPointArray;
begin
result := false;
tmpCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);

SetColorSpeed2Modifiers(0.04, 0.37);
FindColorsTolerance(TPA, 1520706, MSX1, MSY1, MSX2, MSY2, 7);

SetColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);

if (length(tpa) < 10) then //found barely any colour? no point going further
begin
writeln('Found no shop owner colors');
result := false;
exit;
end;

ATPA := TPAToATPAEx(TPA, 20, 20);
DebugATPA(ATPA, ' ');
SortATPASize(ATPA, True);
FindNormalRandoms();

for i := 0 to high(atpa) do //Loops through every atpa
if (GetArraylength(ATPA[i]) > 10) Then
begin
MiddleTPAEx(ATPA[i], X, Y); //Finds the middle via averaging
MMouse(X, Y, 3, 3);
sleep(50 + random(50));
WriteLn(GetUpText);

if waituptext('Talk', 300) then
begin
sleep(300 + random(200));
clickmouse2(mouse_right);
sleep(300 + random(200));
chooseoption('Trade');
sleep(8000 + random(3000));

if FindColorTolerance(x,y,1692278,MSX1,MSY1,MSX2,MSY2,10) then
begin
WriteLn('Color Found ');
result := true;
exit;
end;
end;
end;
end;

procedure findShopOwner();
var
tries: integer;
begin
tries := 0;

repeat
if (findShopOwnerFunc()) then
break;

inc(tries); // plus one to tries count
until (tries > 10); // try for a max of 10 tries
end;

Hoodz

2013-09-30 09:20:48

You can make a dtm of the cross (exit shop) and if it finds the dtm then the shop is open and else shop isnt open.

Flight

2013-09-30 10:13:50

Ah making a nature-crafter are we? Give me a second and I'll show you mine with explanations.

Both of these functions are a bit old and might need the colors updated, I'm not sure.

Function openTheShop: Boolean;
var
mPnt: TPoint;
TPA: TPointArray;
ATPA: T2DPointArray;
i,CTS,F,X,Y,T: Integer;
label
Start;
begin
if ((not loggedIn()) or (not findSymbol(X, Y, 'Shop'))) then // If no shop symbol is found on the MM or if not logged in, exit
Exit;
if shopOpen() then // Is the shop already open?
Exit(True);

Start:
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.03, 0.67);

for i:=0 to 5 do // Search for the shop owner colors 6 times
begin
findColorsSpiralTolerance(MSX1, MSY1, TPA, 5537195, MSX1, MSY1, MSX2, MSY2, 11);
if (length(TPA) > 0) then
break;
end;

setColorSpeed2Modifiers(0.02, 0.02);
colorToleranceSpeed(1);
if (F > 5) then
Exit(False);

if (length(TPA) < 1) then // No shop owner colors found
begin
inc(F);
if (F > 2) then
Exit;
GoTo Start;
end;

splitTPAExWrap(TPA, 10, 20, ATPA); // Split the colors into, hopefully, 10x20 boxes
sortATPASize(ATPA, True); // Sort by size (# of colors found per box)

for i:=0 to High(ATPA) do // For each box do...
begin
mPnt := medianTPA(ATPA[i]); // Check for uptext
MMouse(mPnt.X, mPnt.Y, 0, 0);
if waitUpTextMulti(['to Ji','Jimin','minua'], 300) then
break;
end;
// Was the uptext ever found? If not try again from the beginning (max of 6 attempts
if not isUpTextMultiCustom(['to Ji','Jimin','minua']) then
begin
Inc(F);
GoTo Start;
end;

clickMouse2(mouse_right); // Trade and wait until we're close to the flag on the MM
if chooseOptionMulti(['rade Ji','de Jim']) then
fFlag(5);

markTime(T); // Wait for the shop screen to appear (max of 5 seconds)
repeat
if not loggedIn() then
Exit;
if isMoving() then
Wait(10);

if shopOpen() then
break;
until(timeFromMark(T) > 5000)

if not shopOpen() then // Possibly a random event?
findNormalRandoms();

Result := shopOpen(); // If the shop screen is present then this function results True, False if not present
end;

Also you'll need this:

Function shopOpen(): Boolean;
var
X,Y: Integer;
begin
Result := findColorTolerance(X, Y, 2070783, 185, 30, 250, 45, 30);
end;

Cage

2013-09-30 13:45:07

Thanks very much for all the helpful replies. Ill try and implement when I get home!