SRL Archive - OSR Help

code for click if Uptext is found


cradlefatal

2013-03-07 20:54:17

can someone show me to a code for Click if Uptext I tried using MMmouse left click it didn't work I got my colors in for the bank in taverley this is my script so far I'm not really sure how to make it if find uptext counter then leftclick mouse

program The_Walker;


{$DEFINE SMART8}
{$I SRL\SRL.simba}
{$I SRL\SRL\misc\Debug.simba}
{$I Srl/Srl/Skill/Mining.Simba}
{$I Srl/Srl/Skill/Crafting.Simba}
{$I SRL\SRL\Misc\smartgraphics.simba}
{$I sps/sps.simba}
{$i ObjectDTM\ObjDTMInclude.simba}

CONST
Version = '1.0';

Procedure DeclarePlayers;
Begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;
with Players[0] do
begin
Name := ''; // Player username
Pass := ''; // Player password
Active := True;
end;
End;

Procedure BasicSetup;
Var
LastPainted, StartTime: Integer;
Begin
Smart_FixSpeed:=True;
SRL_SixHourFix:=True;
SetupSRL;
ObjDTM_Setup;
MarkTime(LastPainted);
MouseSpeed:=50;
DeclarePlayers;
StartTime:=GetSystemTime;
LoginPlayer;
Wait(1500);
If (TimeFromMark(StartTime) > 120000) Then
SelectWorld(RandomWorld(Players[0].Member,True));
End;

Procedure PrepTime;
Begin
LodestoneTeleport('Taverley');
Writeln('porting now');
Wait(8000);
Writeln('wait time for portal');
SPS_Setup(RUNESCAPE_SURFACE,['11_7','11_6','10_6','10_7','12_7','12_6']);
SPS_GetMyPos;
Writeln('checking location');
MakeCompass('S');
GameTab(tab_inv);
End;





procedure SettheAngle(Angle: Integer);
begin
if ((Angle = SRL_ANGLE_NONE) or (not LoggedIn)) then
Exit;

KeyDown((Angle * 2) + 38);
Sleep(1000 + Random(300));
KeyUp((Angle * 2) + 38);
Wait(500 + Random(100));
end;







function BankCounter(var cx, cy: Integer): Boolean;
var
arP: TPointArray;
ararP: T2DPointArray;
tmpCTS, i, arL: Integer;
P: TPoint;
begin
tmpCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.00, 2.07);

if not(FindColorsTolerance(arP, 12378593, MSX1, MSY1, MSX2, MSY2, 17)) then
begin
Writeln('Failed to find the color, no object found.');
ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);
Exit;
end;

SortTPAFrom(arP, Point(MSCX, MSCY));
ararP := SplitTPAEx(arP, 10, 10);
arL := High(ararP);

for i := 0 to arL do
begin
P := MiddleTPA(ararP[i]);
MMouse(P.x, P.y, 5, 5);
Wait(100 + Random(100));
if (IsUpText('Counter')) then
begin;
Result := True;
end;
end;

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

if (i = arL + 1) then
begin
Writeln('FindObject could not find object.');
Exit;
end;

GetMousePos(cx, cy);
end;







Procedure My_Path1;
Var
WalkTime, cx, cy: Integer;
Begin
If not LoggedIn then Exit;
MarkTime(WalkTime);
SPS_GetMyPos;
begin
If (ObjDTM_Find('90:79:5:0:7:142:47:0:7:88:31:1:7:120:29:3:7:106:96:3:7:102:121:6:81:46:110:48:112:75:72:154:53:68:66:48', cx, cy, True)) Then
Writeln('In Edgeville');
If (ObjDTM_Find('80:80:5:0:7:87:32:0:7:141:47:1:7:119:31:3:7:106:96:3:7:102:120:5:45:48:107:49:101:127:64:125:60:98', cx, cy, True)) Then
Writeln('Lodestone 2nd Attempt');
If (ObjDTM_Find('80:80:5:0:7:139:44:0:7:87:29:1:7:118:28:3:7:105:91:3:7:101:115:5:89:148:109:43:46:47:48:85:65:100', cx, cy, True)) Then
Writeln('Lodestone Found on 3rd try');
If (ObjDTM_Find('80:80:5:0:7:134:48:0:7:83:34:1:7:113:32:3:7:101:95:3:7:97:118:3:46:55:104:55:91:123', cx, cy, True)) Then
Writeln('Wow Finally found the Lodestone 4th try');
If (ObjDTM_Find('80:80:4:3:7:96:118:3:7:100:95:1:7:112:33:0:7:83:35:4:48:53:102:54:79:151:49:83', cx, cy, True)) Then
Writeln('Found Lodestone on 5th Attempt')
Else
Begin
Writeln('Unable to locate starting point, Starting over');
MakeCompass('S');
end;
end;
begin
If (ObjDTM_Walk('103:107:3:1:7:90:48:2:7:25:125:10:7:126:92:3:82:81:78:134:122:130', 2, 100, 5, True)) Then
Writeln('Walking to Bank');
If (ObjDTM_Walk('75:127:3:1:7:66:27:10:7:66:102:10:7:102:69:3:80:79:62:133:101:146', 2, 100, 5, True)) Then
Writeln('made it to point B');
If (ObjDTM_Walk('46:111:4:1:7:68:119:1:7:84:127:10:7:97:131:10:7:97:103:5:79:84:47:99:44:124:50:122:56:117', 2, 100, 5, True)) Then
Writeln('point c');
begin
Writeln('Made it to the Bank');
end;
end;
End;




Begin
BasicSetup;
PrepTime;
My_Path1;
End.

Le Jingle

2013-03-07 21:29:56

I think OpenBankQuiet finds a banker counter, no?

cradlefatal

2013-03-07 21:35:19

idk i'll look for it

cradlefatal

2013-03-07 21:37:12

it doesn't support taverly and idk how I would write the script myself to make it support taverly

cradlefatal

2013-03-07 21:38:58

found it its open bank fast

Le Jingle

2013-03-07 21:41:30

It looks like OpenBankQuiet uses bitmaps, so if you debug the bitmap for an exact replica of what's being searched for in the other banking locations, I'm sure you could add support to the location (after recreating a bitmap for taverly) with very little difficulty. The search bitmap is probably very small, so your bitmap probably will look like something on the counter of the booth, probably something that's like a center rectangle on the desk counter.

cradlefatal

2013-03-07 21:46:34

I don't have that kind of scripting xp I already got errors trying to put in the openbankfast it does have taverly support I don't know how to put it in my code though I already have errors
how am i supposed to select taverly out of that list I'm sorry I can copy and paste but I can't understand whoever made the include instructions they make no freaking since


function OpenBanktav(Location: String): Boolean;
var
cx,cy: Integer;
Info: TVariantArray;
Booths: TPointArray;
ABooths: T2DPointArray;
UpText: TStringArray;
B: TBox;
begin
result := false;
if (not LoggedIn) then
Exit;
if BankScreen or PinScreen then
begin
Result := True;
Exit;
end;
UpText := ['Count er', 'oun ter'];

case LowerCase(Location) of { Sort X Sort Y Color Tol Hue Sat Count SplitTPA? W H }
'cg', 'cooking guild': Info := [MSCX, MSCY, 5666708, 17, 0.06, 0.77, 100, False, 10, 10];
'akb', 'al kharid': Info := [MSCX - 50, MSCY, 5002594, 20, 0.02, 0.61, 100, False, 10, 10]; // Fixed 1/5, #40
'lb', 'lumbridge': Info := [MSCX, MSCY - 50, 6780805, 10, 0.19, 0.27, 100, False, 10, 10]; // Fixed 12/7, #40
'veb', 'varrock east': Info := [MSCX, MSCY + 50, 3037545, 5, 0.41, 1.32, 100, False, 10, 10]; // Fixed 12/7, #40
'vwb', 'varrock west': Info := [MSCX, MSCY, 3037545, 5, 0.41, 1.32, 100, False, 10, 10]; // Fixed 12/7, #40
'feb', 'falador east': Info := [MSCX, MSCY + 50, 5008519, 10, 0.22, 0.67, 100, False, 10, 10]; // Fixed 12/7, #40
'fwb', 'falador west': Info := [MSCX, MSCY + 50, 5074569, 15, 0.22, 0.67, 50, False, 10, 10]; // Fixed 12/7, #40
'db', 'draynor': begin UpText := ['ount', 'unte', 'oun', 'unter'];
Info := [MSCX - 50, MSCY, 5136741, 5, 0.73, 0.49, 15, False, 10, 10]; // Fixed 12/7, #40
end;
'eb', 'edgeville bank': Info := [MSCX + 20, MSCY, 3561835, 20, 0.32, 0.61, 50, False, 10, 10]; // Fixed 12/7, #40
'ctb', 'catherby bank': Info := [MSCX, MSCY, 3239049, 8, 0.20, 0.20, 100, False, 10, 10];
'clt', 'camelot bank': Info := [MSCX, MSCY, 7636882, 5, 0.20, 0.20, 100, False, 10, 10];
'nab', 'north ardougne bank': Info := [MSCX, MSCY, 4084572, 5, 0.20, 0.20, 100, False, 10, 10];
'sab', 'south ardougne bank': Info := [MSCX, MSCY, 4084572, 5, 0.20, 0.20, 100, False, 10, 10];
'ynb', 'yanille bank': Info := [MSCX, MSCY, 3239049, 7, 0.20, 0.20, 100, False, 10, 10];
'ngb', 'north gnome bank': Info := [MSCX, MSCY, 3239049, 7, 0.20, 0.20, 100, False, 10, 10];
'sgb', 'south gnome bank': Info := [MSCX, MSCY, 3239049, 7, 0.20, 0.20, 100, False, 10, 10];
'wgb', 'warrior guild bank': Info := [MSCX, MSCY, 2578286, 7, 0.20, 0.20, 100, False, 10, 10];
'fgb', 'fishing guild bank': Info := [MSCX, MSCY, 2908796, 10, 0.20, 0.20, 100, False, 10, 10];
'tavb', 'taverly bank': begin UpText := ['ount','unte','oun','unter'];
Info := [MSCX, MSCY, 3556433, 7, 0.20, 0.20, 100, False, 10, 10];
end;
else
begin
srl_Warn('OpenBankFast', 'Unknown bank: '+Location, warn_AllVersions);
Exit;
end;
end;

MakeCompass('n');
cy := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(Info[4], Info[5]);

FindColorsSpiralTolerance(Info[0], Info[1], Booths, Info[2], MSX1, MSY1, MSX2, MSY2, Info[3]);
ColorToleranceSpeed(z);
SetColorSpeed2Modifiers(0.2, 0.2);

{ Split to ATPA. }
if Info[7] then
ABooths := SplitTPA(Booths, 1)
else
ABooths := TPAtoATPA(Booths, 10);

Booths := [];

{ Go through ATPA. }
l := GetArrayLength(ABooths) -1;
for i := 0 to l do
begin
{ Too few pixels. }
if (Length(ABooths[i]) < Info[6]) then
Continue;

{ Too small TPA bounds. }
B := GetTPABounds(ABooths[i]);
If ((B.X2 - B.X1) < Info[8]) Or ((B.Y2 - B.Y1) < Info[9]) Then
Continue;

Inc(bo);
SetArrayLength(Booths, bo);
Booths[bo-1] := MiddleTPA(ABooths[i]);

end;

SortTPAFrom(Booths, Point(Info[0], Info[1]));

l := GetArrayLength(Booths) -1;
for i := 0 to l do
begin

MMouse(Booths[i].X, Booths[i].Y, 3, 3);
if WaitUpTextMulti(UpText, 1000) Then
begin
GetMousePos(Booths[i].X, Booths[i].Y);
Mouse(Booths[i].X, Booths[i].Y, 0, 0, mouse_left);
FFLag(0);
MarkTime(c);
repeat
Wait(100);
until (BankScreen) or (PinScreen) or (TimeFromMark(c) > 10000);
Wait(Random(300));
if (HowManyPlayers > 0) then
if (Players[CurrentPlayer].Pin <> '') then
InPin(Players[CurrentPlayer].Pin);
Result := (BankScreen) or (PinScreen);
if (Result) then Exit;
end;
end;
end;

Le Jingle

2013-03-07 22:46:55

I suggested looking into the OpenBankQuiet function, debugging and toying around with a bitmap, adding or replacing an existing case option (still in OpenBankQuiet) for taverly, and using that for finding a banker + opening. I also gave a hint that since the bitmap name is TheCounter, it might be helpful to make a small + accurate bitmap of the beige-looking counter on a bank booth.

Are there parts in this post, in the description above, that aren't clear and would you like me to elaborate on those specified points?

cradlefatal

2013-03-08 00:08:50

idk anything about bitmap i barley know scripting i messed around with java scripting back before rarebot got hijacked but that was about it I could probably retrain myself in HTML in the matter of minutes its been years since i've done it I've only done this scripting for about 5 days or so lols I get to mad and have to quit after a while so I really don't know anything about editing the bitmap and etc because usually when i do the script goes to hell lols easiest way to put it, however as far as the bank booth colors I have it to select the white little circles of paper that are on the bank counter and it keeps the rest of the white out of the picture like the carpet and etc only thing i need is a procedure to make my mouse move to the bank all I need is the code LOL i don't know how to wright my own or really even use the includes because you have to edit them

Le Jingle

2013-03-08 01:58:30

That helps me diagnose on how to help you out ;)

1. I think the first step towards helping out your original question (banking at taverly counter), would be to say, the function that we could look at, that is an included function in the srl includes, is within bank.simba. The function in specific within the file is OpenBankQuiet, as I previously mentioned.

2. So, breaking down the function OpenBankQuiet, we'll discover what's being done in each step of the function, thus understanding what we need to do in order to get that function to work the way we want it to.

3. (Look for the blue comments within this code, helping unravel the logic.

(*
OpenBankQuiet
~~~~~~~~~~~~~

.. code-block:: pascal

function OpenBankQuiet(WhichBank: string): Boolean;

Opens any given bank in the free world using
FindDeformedBitmapToleranceIn. Avoids strange mouse movements. Will cause
significant lag (approx. 1 second), but finds the bank with one click.

Valid arguments are:
'feb' (Falador East Bank)
'fwb' (Falador West Bank)
'veb' (Varrock East Bank)
'vwb' (Varrock West Bank)
'db' (Draynor Bank)
'eb' (Edgeville Bank)
'akb' (Al-Kharid Bank)

.. note::

Author: WT-Fakawi and modified by Ron
Last Modified: Unknown

Example:

.. code-block:: pascal

if OpenBankQuiet('feb') then
Withdraw(...);
*)

// as we see in the line below, when you call this function, you have to have a string argument, which are specifically listed later in the function.
function OpenBankQuiet(WhichBank: string): Boolean;

// here we declare all the needed variables in the function.
var
TheCounter, dx, dy, tol, Mark2, Mark3: Integer; // integer types are numbers, such as 0, 1, 2, 3, -1, -2, -3, etc.
acc, accthres: Extended; // extended types are decimal numbers, such as 0.0, 5.5, -2.2, etc.
begin
result := false; // this is already initialized via the function, but it's good practice to declare the result false before doing anything.

// the line below, tells us that, given the string argument from the function call earlier,
// we have the string cases below, such that if the string argument from the function call,
// matches one of these strings in the list below, then we'll initialize the bitmap for the bank counter to look for.
case WhichBank of
// note that, this is only one option, but we'll let the argument for this specific bitmap, accept two different strings, 'feb' or 'fwb' that will both mean the same case statement value
'feb', 'fwb': TheCounter := BitmapFromString(1, 10, '6C583296897A948779948779736C63A59E968C7F6F9686749B8A7685663E');

// varrock west - same idea as 'feb' or 'fwb'
'vwb': TheCounter:= BitmapFromString(10, 1, 'A0997F504A49504A49504A495E4F215E4F215E4F215E4F212C250EA0997F');

// varrock east - etc. just another case choice
'veb': TheCounter := BitmapFromString(1, 10, '5E4D1589826D88806D88806D867F6C9996907C7664847D648C836891876B');

// draynor and this works too for alkharid
'akb', 'db', 'eb': TheCounter:= BitmapFromString(12, 1, '584209735C29735C29735C2960585558504D60504D58504D58504D58504D58504D605855');
else
begin
// this executes if we use a string in the function call argument, that isn't on our list above. This will stop the script, throwing a warning/exception.
// thus, make sure to call either 1. 'akb', 'db', 'eb' 2. 'feb', 'fwb' 3. 'vwb' or 4. 'veb'
srl_Warn('OpenBankQuiet', 'Unknown bank: ' + WhichBank, warn_AllVersions);
Exit;
end;
end;

// Here we start a sort of timer, like one you'd start up on your wrist watch. Starts from 0.
MarkTime(Mark3);

//Declare the tolerance of the bitmap to start at 1.
// Generally the lower the tolerance, the more precise the bitmap will need to be found on the screen in this case.
// lower tolerance can provide more accurate results, but also less or no results.
// this will most likely increase as we start looping for checks later on in the code.
tol := 1;

// same idea here, we'll start with a somewhat precise accuracy threshold, 0.6, or 60% accuracy for a match.
accthres := 0.6;

// now we start looping. A loop in general is about bigO(n), among other things as well as operations, however meaning it has some representation in something that is nowhere near helpful for beginning to learn. This is now a line where I've just totally gone off topic ;P But this is an important idea later down the road in computer classes you may take.
repeat

// these if statements, check if there's actually a player to access,
// given the first check was true, then we'll check to see if the current player actually has a pin associated with it to try to enter into the pinscreen if it pop's up.
// and finally, will input the pin if there's a pin. Hmm this could be some bad practice, but I did pull it off the includes; I'll revise this later to see if I should change this as the first check in our loop.
// for now, I'd take from this if statement block, that it's the first thing being evaluated in the loop.
if (Length(Players) > 0) then
if (Players[CurrentPlayer].Pin <> '') then
InPin(Players[CurrentPlayer].Pin);

// here, we see if there's a pinscreen or bank screen open.
// given true to either of these being presently open, then we'll start doing what's inside the begin .. end, to this if statement.
if BankScreen or PinScreen then
begin

// we'll if we're already in the bank, then we'll say that's good, and set the result to true.
Result := True;
// free the bitmap from memory so we don't cause memory leaks to slow our computer down.
FreeBitmap(TheCounter);
// exit the function now, with a true result!
Exit;
end;

// if we wait for 1 second, and look for the up text (in the upper left hand of the main screen), we'll see if we can match any of the text in the below string array, ['ank', 'Bo', 'ot']
if WaitUpTextMulti(['ank', 'Bo', 'ot'], 1000) then
begin
// if the above if statement is true, then we'll get the x and y coordinates of our mouse, and store them in dx, dy, respectively.
GetMousePos(dx, dy);
// then, we'll say, let's click left in this spot! (the mouse is never moved, only clicked with the left mouse button)
Mouse(dx, dy, 0, 0, mouse_left);
// here we mark another counter, starting from 0.
MarkTime(Mark2);

// we then make it into an inner loop
repeat

Wait(10);// simply waits 10 ms, allow the loop to ``breathe''

// first we'll preform a check. If the time we recently marked from 0, is now currently above 20,000 ms, then we'll free the bitmap and exit this function with a false result. However on the first loop, we're generally only about 10 ms, given the 10 ms wait, from the second time marker.
if TimeFromMark(Mark2) > 20000 then
begin
WriteLn('Couldn''t find the bank. Exiting');
FreeBitmap(TheCounter);
Exit;
end;

// we'll now enter the conditions that also guard the loop, meaning, if during this loop, we evaluate to have true result of the bankscreen or pin screen being open, then we'll stop looping in this inner loop because we've got what we wanted. Notice how there wasn't any interaction with RS being done in the inner loop aside from waiting and checking. this is probably a good measure loop wait for a screen to open up (or not - in which we'll exit).
until BankScreen or PinScreen;

// again looking for pin's (as I stated earlier, this is probably a spot for this if block, not sure why it is also at the top of the outer loop).
if (Length(Players) > 0) then
if (Players[CurrentPlayer].Pin <> '') then
InPin(Players[CurrentPlayer].Pin);

// if we made it past the timeout failsafe that would have sent us exiting out of this function, then we should know that we're in the bank screen!, so we'll set the result to true, free the bitmap from memory and then exit the function.
Result := True;
FreeBitmap(TheCounter);
Exit;
end;

// here we are looking for the bitmap for TheCounter, that we assigned earlier in the case statement.
// this is a good line of code, exampling how the previous variables all combine into one call.
// 1. TheCounter - this came from our case statement, telling us which bank's bitmap to use
// 2. dx, dy - we'll get two new x and y values for the result of finding the bitmap
// 3. MSX1, MSY1, MSX2, MSY2 - the area to search in, these are all constant values already in the includes in globals.simba
// 4. tol, the start tolerance we declared outside the loop.
// 5. the accuracy we declared outside the loop.
FindDeformedBitmapToleranceIn(TheCounter, dx, dy, MSX1 + 50, MSY1 + 50, MSX2
- 50, MSY2 - 50, tol, 4, True, acc);

// compare accuracy with the result from the above call for finding the bitmap with the current accuracy declared from the outside of the outer loop.
if (acc >= accthres) then
begin
// straight forward by now
if (Length(Players) > 0) then
if (Players[CurrentPlayer].Pin <> '') then
InPin(Players[CurrentPlayer].Pin);
// straight forward by now
if BankScreen or PinScreen then
begin
Result := True;
FreeBitmap(TheCounter);
Exit;
end;

// another loop like we encountered earlier, if the uptext is already the text for a banker, we'll click!
MMouse(dx, dy, 0, 0);
if WaitUptextMulti(['ank', 'Bo', 'ot'], 1000) then
begin
GetMousePos(dx, dy);
Mouse(dx, dy, 0, 0, mouse_left);
MarkTime(Mark2);
repeat
Wait(10);
if TimeFromMark(Mark2) > 20000 then
begin
WriteLn('Couldn''t find the bank. Exiting');
FreeBitmap(TheCounter);
Exit;
end;
until BankScreen or PinScreen;


if (Length(Players) > 0) then
if (Players[CurrentPlayer].Pin <> '') then
InPin(Players[CurrentPlayer].Pin);
Result := True;
FreeBitmap(TheCounter);
Exit;
end;
end;
Wait(100);

// here is where we sit and say, we'll humpty dumpty, no darn bank screen yet!
// so now we'll up our tolerance by 4, allow for more ``loose'' bitmap searches, but potentially more since we're searching a wider range of tolerance
tol := tol + 4;

// a tolerance failsafe: bascially, if we loop to the point where our tolerance is 20 or greater,
// 1. then we'll reset our tolerance to be used (but can still be incremented later) to 1,
// 2. decrease our accuracy threshold by 0.1,
// 3. check if our accuracy is less than 0.2 (if it is, we'll exit because the bitmap likely won't ever match)
if tol >= 20 then
begin
tol := 1;
accthres := accthres - 0.1;
if accthres < 0.2 then
begin
WriteLn('Couldn''t find the bank. Exiting');
FreeBitmap(TheCounter);
Exit;
end;
end;

// then, completing the outer loop, (yep, we've looped through a lot of code, even some loops inside this outer loop!
// with all the above checking and the single bitmap search (can you believe that, only 1 call for searching for a bitmap, and the rest was to modify the searching for that single call, with the help of loops)
until TimeFromMark(Mark3) > 60000;
FreeBitmap(TheCounter);
end;

I'll post some idea's on what you could change tomorrow, hopefully giving you time to read + digest the comments that help break down the above code :]

cradlefatal

2013-03-09 15:35:29

just now seen this thank you

cradlefatal

2013-03-09 19:48:12

i just got done going over the code I'm still quite lost here so if we are making our own would we have to add our own into the list above or would we use one from the list above and change the code on the bank quite confusing and if we are then where would I put AKB, db,
// this executes if we use a string in the function call argument, that isn't on our list above.  This will stop the script, throwing a warning/exception.
// thus, make sure to call either 1. 'akb', 'db', 'eb' 2. 'feb', 'fwb' 3. 'vwb' or 4. 'veb'
srl_Warn('OpenBankQuiet', 'Unknown bank: ' + WhichBank, warn_AllVersions);
Exit;
end;