SRL Archive - First Scripts

My Very Basic First Script - GE Buy Option


ForMyFutures

2013-02-01 03:12:01


program GEBuyOption;

{$DEFINE SMART}
{$i srl/srl.Simba}



var
BuyOption, X, Y: Integer;
fonts, txt: TStringArray;
ItemChoice, BasicSearch: String;




begin
SetupSRL;
fonts :=['BigChars', 'SmallChars', 'FriendChars', 'CharsTrade', 'SmallCharsNS' ];
BuyOption := DTMFromString('mlwAAAHicY2dgYGAFYh4g5gRiNiBmZIAAdigfJM4CFWOGinEDcW0HM0OUvjDDpqNMDBuPMzEUx+gwJBoJMDgr8TLgA4x4MBQAAD28BwU=');
InputQuery('This is what your script will type', 'You do not have to type the full item name', BasicSearch);
InputQuery('This is what your script will look for', 'A string of characters that are not within the search item', ItemChoice);
txt :=[ItemChoice];



If FindDTM(BuyOption, X, Y , MSX1, MSY1, MSX2, MSY2) Then
begin
MMouse(X, Y, 10, 30);
ClickMouse2(Mouse_Left);
Wait(RandomRange(300, 700));
SendKeys(BasicSearch, RandomRange(250, 350), RandomRange(100, 150));
Wait(RandomRange(2000, 2100))
if FindTextEx(X, Y, txt, fonts, 66, 330, 492, 448) Then
begin
Wait(RandomRange(650, 1000));
WriteLn('We found the Item');
MMouse(X, Y, 5, 5);
Wait(RandomRange(300, 800));
WriteLn('Clicking item');
ClickMouse2(True);
end;
end;

FreeDTM(BuyOption);

end.
[Updated]


Its just a simple script that will click buy, type in the item, and click the name in the chat. Any suggestions would be lovely. :)

Le Jingle

2013-02-01 03:21:19

From: ForMyFutures

Its just a simple script that will click buy, type in the item, and click the name in the chat. Still working on it, so any critiques are more than welcomed. Currently, I'm trying to figure out how to click without having to move the mouse a second time but still allowing for some randomness in MMouse.


To click without moving the mouse, use: ClickMouse2(Mouse_left);
Note that MMouse and Mouse use the same mouse movements (wind mouse iirc), and that mouse has an additive parameter to click (click can be set to move too).

Not bad for a first snippet, keep up the work :]

-Lj

Press Play

2013-02-01 03:29:51

If you put your code in Simba tags, that would make it look a bit nicer :)
[SIMBA][/SIMBA]

First off, you would like to know that the Mouse(); procedure moves the mouse with randomness. ie.
MMouse(X, Y, Random(80), Random(60));
Mouse(X, Y, 0, 0, True);

// Is the same as just:

Mouse(X, Y, Random(80), Random(60), True);

Also, with these mouse functions, you don't need to put in a random number for the 3rd and 4th parameters because it is already randomised. For example:
Mouse(X, Y, Random(80), Random(60), True);

// Can be replaced with

Mouse(X, Y, 80, 60, True);

Second, it is better to use RandomRange(); instead of just Random();. But really, it depends on what you're after. You should be using this randomness in all of your Wait();s.
RandomRange(40, 80);   // Returns a value between 40 and 80 inclusive
Random(80); // Whereas this will return values from 0 to 80 inclusive.

Also, you don't need {$i sps/sps.simba} at the top there, since you're not using any SPS map walking functions.

Lastly, I'd say to have another look at coding standards. Your indenting is mostly good with the exception of the begins and ends. They should be looking like this: (Lowercase is preferred for bold words, but it's really up to you)
if FindBitmapToleranceIn(RunesPlate, X, Y, 70, 75, 600, 400, 255) then
begin
Wait(RandomRange(500, 1000));
WriteLn('Found plate!');
MMouse(X, Y, 60, 7);
Wait(RandomRange(250, 700));
Mouse(X, Y, 25, 3, True);
end;

Post again if you're unsure/need anything else :)

ForMyFutures

2013-02-01 03:59:59

Post again if you're unsure/need anything else


I need help with determining coordinates on the screen, actually. That would be a huge help lol.

Press Play

2013-02-01 04:11:46

From: ForMyFutures
I need help with determining coordinates on the screen, actually. That would be a huge help lol.


I'm assuming you're looking for fixed points on the RS Client? In Simba, you can drag the cross-hair over your SMART window (to "select a client"), and use the colour picker to find a point. It will return the colour along with the co-ordinates that it was picked at (IMPORTANT: The co-ordinate includes the "Home/Support/Forums/Clans" bar at the top, so you have to minus 50 off the y-value).

Hopes this makes sense!

There are also some constants in globals.simba that include this like:
{ const MSX1, MSY1, MSX2, MSY2;
Description: Main Screen EdgePoints. }
const
MSX1 = 4;
MSY1 = 4;
MSX2 = 515;
MSY2 = 337;
You can use these to search for things. eg.
if FindColor(x, y, colour, MSX1, MSY1, MSX2, MSY2) then
...

ForMyFutures

2013-02-01 04:24:03

Well for instance

if FindBitmapToleranceIn(Partyhat, X, Y, 6, 400, 500, 500, 255) Then

The parameters I pass to it are points, but I dont understand what to pass it because A single point has an X and Y so the way I think of it currently is just two points, aka Pixels. basically, how can you distinguish between it being just a single point, or a defined area?

Edit: Nevermind, found a tutorial.

However,

program GEBuyOption;

{$DEFINE SMART}
{$i srl/srl.Simba}



var

Arrowss, BuyOption, X, Y: Integer;



begin

SetupSRL;
BuyOption := DTMFromString('mlwAAAHicY2dgYGAFYh4g5gRiNiBmZIAAdigfJM4CFWOGinEDcW0HM0OUvjDDpqNMDBuPMzEUx+gwJBoJMDgr8TLgA4x4MBQAAD28BwU=');

If FindDTM(BuyOption, X, Y , MSX1, MSY1, MSX2, MSY2) Then
begin
MMouse(X, Y, 10, 30);
ClickMouse2(Mouse_Left);
Wait(RandomRange(300, 700));
SendKeys('arrow', RandomRange(250, 350), RandomRange(100, 150));
Arrowss:= BitmapFromText('Rune Arrow', 'FriendChars');
Wait(RandomRange(300, 900));
if FindBitmapToleranceIn(Arrowss, X, Y, 65, 350, 450, 450, 255) Then
begin
Wait(RandomRange(650, 1000));
WriteLn('We found the Arrow');
MMouse(X, Y, RandomRange(15, 45), 5);
Wait(RandomRange(400, 800));
ClickMouse2(True);
end;
end;

FreeDTM(BuyOption);
FreeBitmap(Arrowss);

end.

Right now, whenever I try to get it to click something below the top line for an item option after it types it in, it never does and only selects the first one. :\

Press Play

2013-02-01 07:01:09

IIRC, 225 is the highest possible tolerance - so I think you're giving the bitmap-finder too much leeway. Try this:
if FindBitmapToleranceIn(Arrowss, X, Y, MCX1, MCY1, MCX2, MCY2, 30) then

Where MCX1, MCY1, MCX2, MCY2 are the chat screen boundary co-ordinates.

Olly

2013-02-01 07:33:47

Why don't you look into the SRL text finding function?

ForMyFutures

2013-02-01 18:11:54

 
program GEBuyOption;

{$DEFINE SMART}
{$i srl/srl.Simba}



var
BuyOption, X, Y: Integer;
fonts, txt: TStringArray;
ItemChoice, BasicSearch: String;




begin
SetupSRL;
fonts :=['BigChars', 'SmallChars', 'FriendChars', 'CharsTrade', 'SmallCharsNS' ];
BuyOption := DTMFromString('mlwAAAHicY2dgYGAFYh4g5gRiNiBmZIAAdigfJM4CFWOGinEDcW0HM0OUvjDDpqNMDBuPMzEUx+gwJBoJMDgr8TLgA4x4MBQAAD28BwU=');
InputQuery('This is what your script will type', 'You do not have to type the full item name', BasicSearch);
InputQuery('This is what your script will look for', 'A string of characters that are not within the search item', ItemChoice);
txt :=[ItemChoice];



If FindDTM(BuyOption, X, Y , MSX1, MSY1, MSX2, MSY2) Then
begin
MMouse(X, Y, 10, 30);
ClickMouse2(Mouse_Left);
Wait(RandomRange(300, 700));
SendKeys(BasicSearch, RandomRange(250, 350), RandomRange(100, 150));
Wait(RandomRange(2000, 2100))
if FindTextEx(X, Y, txt, fonts, 66, 330, 492, 448) Then
begin
Wait(RandomRange(650, 1000));
WriteLn('We found the Item');
MMouse(X, Y, 5, 5);
Wait(RandomRange(300, 800));
WriteLn('Clicking item');
ClickMouse2(True);
end;
end;

FreeDTM(BuyOption);

end.

I just noticed that it will not attempt to look for the text if I put what it types the same as what FindTextEx is looking for. It thinks its out of range.

At least I think that's what it is:
 Error: Exception: The Points you passed to DrawATPA exceed the bitmap's bounds at line 137 

For example if I specified BasicSearch to be 'partyhat' and ItemChoice to be 'Green'. It would have no trouble clicking the Green Partyhat.

However, if I specified BasicSearch to be 'Blue Partyhat' and ItemChoice to be 'Blue Partyhat' the error above shows up and the script doesn't find it.