SRL Archive - OSR Help

DTM or FindChat?


Element17

2012-04-20 20:28:46

Would it be better to use findchat or dtm? I wanna use this as a fail safe to make sure I opened the guild door.




YoHoJo

2012-04-20 20:30:09

I use GetColor to finding chat like that. (Or I think FindColor?)

Just check a specific pixel for the black color and you should be just fine.
Fast, Simple, Easy!

Grihmm

2012-04-20 20:42:46

Why not use all those methods for failsafes? You can never have too many failsafes.

Element17

2012-04-20 20:49:40

Something like this?

function GetColorsBox(x1, y1, x2, y2: Integer; ClearSameColors: Boolean): TIntegerArray;
begin
Result := GetColors(TPAFromBox(IntToBox(x1, y1, x2, y2)));
if (ClearSameColors) then
ClearSameIntegers(Result);
end;

YoHoJo

2012-04-20 21:23:12

Not even the box one, just simply the one that searches one pixel for color will work fine!
I think it's just GetColor

Element17

2012-04-20 21:58:46

Thank YoHoJo. Always helpful!


This is what I have so far

Procedure OpenDoor;
Var Tries: Integer;
Begin
Repeat
If(Not(LoggedIn))Then Exit;
Tries := Tries + 1;
If(Tries = 5) Then
Writeln('Failed Five times');
If DoorFinder(X, Y) Then
Case Random(2) of
0: Mouse(X, Y, 2, 2, True);
1: Begin
Mouse(X, Y, 2, 2, False);
WaitOption('pen', 500);
End;
End;
Wait(1000);
While IsMoving Do
AntiBan;
Wait(750+Random(200));
Until(FindColor(x, y, 0, MCX1, MCY1, MCX2, MCY2));
If FindColor(x, y, 0, MCX1, MCY1, MCX2, MCY2) Then
Writeln('Foudn and clicked door!');
End;

But is this this one better? *Flight did not make this one for me its from another script on here and I am not using it and if I choose to I will ask Flight for permission.*

Procedure OpenTheDoor;    //newer door opener, thanks Flight
var
x, y, COUNTER: integer;
begin
If FindObj(x,y,'pen', 2117737, 5) then //2581379
Begin
WriteLn('Opening Door...');
ClickMouse2(True);
COUNTER := 0;
if not DidRedClick and (COUNTER<20) then //If we missed, then exit so we can try again
begin
OpenTheDoor;
inc(COUNTER);
end;
While IsMoving do
Wait(100);
//Maybe wait a little longer?
end else if FindObj(x,y,'lose', 2117737, 5) then //The door is already open, so let's exit
Exit;
end;

Rich

2012-04-21 16:44:14

As for the first piece of code above, I'd suggest search for one specific pixel (or two to be sure) instead of the entire chat box, as there could be other reasons why black would be there. It could also be made easier by making it a function, instead of a procedure, like this
function OpenDoor : Boolean;
var Tries: Integer;
begin
Result:= ((GetColor(X1, Y2) = 0) and GetColor(X2, Y2) = 0)); //X1, X2, Y1, Y2 are co-ords where black is found in the chat box when the door is opened
repeat
if(not(LoggedIn))then
Exit;
Inc(Tries)
if DoorFinder(X, Y) then
case Random(2) of
0 : Mouse(X, Y, 2, 2, True);
1 : begin
Mouse(X, Y, 2, 2, False);
WaitOption('pen', 500);
end;
end;
Wait(1000);
while IsMoving do
AntiBan;
Wait(750+Random(200));
until(Result or (Tries = 5))
if Result then
Writeln('Found and clicked door!')
else
begin
WriteLn('Failed to find door');
//Anything else you want it to do upon failing
end;
end;
I also noticed it would keep repeated until it found the door, which it may not, so added it to break upon failing five times. If there's anything you don't understand about what I've done there, let me know :)

Element17

2012-04-21 16:54:44

That looks great! Mind if I use it? Credits of course and yeah I just noticed could be a endless loop.

Rich

2012-04-21 17:00:05

Feel free.