SRL Archive - First Scripts

My First 450+ line Script :)


reddevil12312

2009-10-06 06:07:46

okay. this script is not for runescape. its for a private server. im not rele looking for a test, really just a look over to see if ive been learning right.

im not worried about making myself amazing scripts yet. i just wanna learn, and be able to judge what's best for what.

please just glance over this, and see if you can find any areas that need to be recoded to be more efficient, or to fit better into SRL's standards for scripting.

Credits go alot to YoHoJo for just helping me out with certain instances of the script.. find npcs, what to autocolor, ect…

the script is kinda typed sloppy. sorry. might fix up when i get the time.

Here's the Script.

[ATTACH]8492[/ATTACH]

[PHP]// **Dragon Stone Buyer
// **Version 1.0
// **Description: buys dragon stone gems from general store
// **Instructions
// 1-money is firstinventory spot
// 2-start near bank, will make begining the script much better
// 3-no random, will come later
// 4-type in amout of gems you want. 65k per drag stone. type 0 for unlimited
// 5-push play, and watch for a few runs. check back at times.
// 6-cutter will come later too.
//
// (Made for a private server. so the ideals of it are a lil custom from rs)
//
{ Progress/
setupscript=——–>done
declarebitmaps=—–>done
loaddtmwalks=——->done
loutMAN=————>done
walktoshop=———>done. needs testing
walktobank=———>done. needs testing
findingbanker=——>done. needs testing
findingseller=——>unfinished
buyinggems=———>done
pincheck =———->done
banking =———–>done. needs testing
checklog =———->done. risky
progress report=—->works. needs touching up
mainloop=———–>unfinished. doing it last
}










program DragBuyer;
{.include SRL/SRL.scar}



PLAYER SETUP (ONLY 1 PLAYER ATM

const GemAmount = 15000; // 1k gems=50m gp
const RunTime = 0; // type in number of hours. 30 minutes = .5; 15min = .25; and so on….
const GemsInBank = 0; // only use if you want the progress to show how
const DoubleCheckMW = true; // double checks map walking, if true // much total gems you have. waiste of time rele…


//**********************************************************//
// DONT TOUCH BELOW THIS! //
//**********************************************************//







var
Randomcount:integer;
NumOfTrip:integer;
TotalOfGems:integer;
//bitmaps
GemBTM:integer;
//DTMS
BankerTextDTM:integer;
ShopTextDtm:integer;
const StartGemCount = 0+GemsInBank;






procedure SetupScript;
begin
SetupSRL;
activateclient;
Writeln('Script Started');
writeln('We should be buying' + inttostr(GemAmount));
end;


procedure DeclareBitmapsAndDTM;
begin
GemBTM := BitmapFromString(10, 10, 'beNo9kGtLwnAUxl8czvN1go' +
'IhQxY0m11mu7VNRZllRRgVDTc0xTeDPncPHBjsxeD33M5fwgT1Az7' +
'v8THFKcfO0zKQlwu5PZfgTK5II3xTcKfvBX5TNEPNfakcCSnI0JiA' +
'9ht9S9Fm2lzLMykTmEbKr8Se9kDXj9qGuhlI5MmsxIGCJbopjmb3d' +
'XWp84l+cQCphVu10QRb/rPXkq3XkgvsY61HsnIlMdobSxxj/XElJe' +
'0328kLdNzMUh41kidu7u+t8FfgYJP4JmN5df4Br6JHag==');

BankerTextDTM := DTMFromString('78DA630C66606070644001AF9FB3328800694' +
'620FE0F048CB1408603AA9A7BF718E06A4080310B4838A1AA7970' +
'1F4D8D0DA69A7B77EFA0AA71071236A86AEEDF6344510300D7AB1' +
'0F0');

ShopTextDtm := DTMFromString('78DA630C6760607066400197AF32308800694' +
'620FE0F048C4E408623AA9A532719E16A4080310B53CDC9530CA8' +
'6A4076D9A3AAB9748E05AE860988015DDC0D28');
end;


function LoadAllDTMWalks(WalkName: string): Integer;
var
dtmMainPoint: TDTMPointDef;
dtmSubPoints: array[0..4] of TDTMPointDef;
TempTDTM: TDTM;
begin
case Lowercase(WalkName) of
'shop': begin //Walk To shop
dtmMainPoint.x := 635;
dtmMainPoint.y := 142;
dtmMainPoint.AreaSize := 0;
dtmMainPoint.AreaShape := 0;
dtmMainPoint.Color := 16119536;
dtmMainPoint.Tolerance := 0;

dtmSubPoints[0].x := 635;
dtmSubPoints[0].y := 142;
dtmSubPoints[0].AreaSize := 0;
dtmSubPoints[0].AreaShape := 0;
dtmSubPoints[0].Color := 16119536;
dtmSubPoints[0].Tolerance := 0;

dtmSubPoints[1].x := 627;
dtmSubPoints[1].y := 140;
dtmSubPoints[1].AreaSize := 0;
dtmSubPoints[1].AreaShape := 0;
dtmSubPoints[1].Color := 16119536;
dtmSubPoints[1].Tolerance := 0;

dtmSubPoints[2].x := 638;
dtmSubPoints[2].y := 136;
dtmSubPoints[2].AreaSize := 0;
dtmSubPoints[2].AreaShape := 0;
dtmSubPoints[2].Color := 16119536;
dtmSubPoints[2].Tolerance := 0;

dtmSubPoints[3].x := 634;
dtmSubPoints[3].y := 139;
dtmSubPoints[3].AreaSize := 0;
dtmSubPoints[3].AreaShape := 0;
dtmSubPoints[3].Color := 2180442;
dtmSubPoints[3].Tolerance := 0;

TempTDTM.MainPoint := dtmMainPoint;
TempTDTM.SubPoints := dtmSubPoints;
Result := AddDTM(TempTDTM);
end;

'bank' : begin
dtmMainPoint.x := 620;
dtmMainPoint.y := 132;
dtmMainPoint.AreaSize := 0;
dtmMainPoint.AreaShape := 0;
dtmMainPoint.Color := 15004134;
dtmMainPoint.Tolerance := 10;

dtmSubPoints[0].x := 620;
dtmSubPoints[0].y := 132;
dtmSubPoints[0].AreaSize := 0;
dtmSubPoints[0].AreaShape := 0;
dtmSubPoints[0].Color := 15004134;
dtmSubPoints[0].Tolerance := 10;

dtmSubPoints[1].x := 620;
dtmSubPoints[1].y := 120;
dtmSubPoints[1].AreaSize := 0;
dtmSubPoints[1].AreaShape := 0;
dtmSubPoints[1].Color := 15004134;
dtmSubPoints[1].Tolerance := 20;

dtmSubPoints[2].x := 611;
dtmSubPoints[2].y := 132;
dtmSubPoints[2].AreaSize := 0;
dtmSubPoints[2].AreaShape := 0;
dtmSubPoints[2].Color := 15004134;
dtmSubPoints[2].Tolerance := 20;

dtmSubPoints[3].x := 618;
dtmSubPoints[3].y := 130;
dtmSubPoints[3].AreaSize := 0;
dtmSubPoints[3].AreaShape := 0;
dtmSubPoints[3].Color := 1521983;
dtmSubPoints[3].Tolerance := 20;

dtmSubPoints[4].x := 630;
dtmSubPoints[4].y := 129;
dtmSubPoints[4].AreaSize := 0;
dtmSubPoints[4].AreaShape := 0;
dtmSubPoints[4].Color := 0;
dtmSubPoints[4].Tolerance := 28;

TempTDTM.MainPoint := dtmMainPoint;
TempTDTM.SubPoints := dtmSubPoints;
Result := AddDTM(TempTDTM);
end;
end;
end;


Procedure LogoutMAN; //uses simple pro's // not alot of advanced stuff needs to go here..
begin //progress=done. prolly needs some updates for show
mouse(1,1,1,1, true);
wait(1000);
mouse(1,1,1,1, true);
end;

Function WalkToShop: boolean;
var x,y,DtmShop: integer;
begin
MakeCompass('n');
Result:= RadialWalk(195836, 25, 119, 70, -1, -1);
If Result Then
begin
Writeln('Found Shops Yellow Dot!');
end else
begin
if (DoubleCheckMW=true) then
begin
DtmShop := LoadAllDTMWalks('shop');
If DTMRotated(dtmshop, x, y ,540, 15, 715, 158) Then
Begin
Writeln('Shop Found');
Mouse((x-7),(y-4),0,0,true);
Flag;
FreeDTm(DtmShop);
End Else
begin
WriteLn('walking to shop needs fixing. Script Terminated');
LogoutMAN;
terminatescript;
end;
end;
end;
end;


Function WalkToBank: boolean; //uses radialwalk progress-notta
var x,y,DtmBank: integer;
begin
MakeCompass('n');
Result := RadialWalk(195836, 303, 221, 71, 1, 1);
If Result Then
Begin
Writeln('Found Bankers Yellow Dot!');
end else
begin
if (DoubleCheckMW=true) Then
Begin
DTMBank := LoadAllDTMWalks('bank');
if DTMRotated(DTMBank, x, y, 540, 15, 715, 158) Then
Begin
Writeln('Bank Found! With DTM');
Mouse((x-1), (y-1),0,0, true);
flag;
freeDTM(DTMBank)
end else
begin
Writeln('Wlalking To Bank Needs Fixing. Script Terminated');
LogoutMAN;
TerminateScript;
end;
end;
end;
end;



Procedure FindingBanker;
var x, y, y2, x2,I: Integer;
Done: Boolean;
Begin
Repeat
If FindColorTolerance(x, y, 5066068, 1, 1, 1, 1, 5) Then
Begin
MMouse(x, y, 0, 0);
wait(100 + Random(100));
If FindDTM(bankertextDTM, x2, y2, 1, 1, 1, 1) Then
Begin
Writeln('gotcha banker!');
Done := True;
mouse(x, y, 0, 0, False);
mouse((x-0), (y-0), 0, 0, true);
Exit;
End Else
Begin
Inc(I); // Increase I
Wait(500 + Random(300));
End;
End;
Until (Done) Or (I > 15);
If (I > 15) Then
Begin
Writeln('Could not find Banker Text - Terminating Script');
TerminateScript;

End Else
begin
Writeln('Could not find Banker Color - Terminating Script');
TerminateScript;
End;
End;


procedure FindingShopTrader2;
var x,y:integer;
begin
FindColorTolerance(x,y,1102329, 1,1, 510,340,5);
mouse(x,(y+63), 0,0, false);
mouse(x,(y+41), 0,0, true);
IF (getcolor(191,86)=86) then
begin
writeln('used F.S.T.2 to find shop');
end else
writeln('could not find find shop');
terminatescript;
end;


Procedure FindingShopTrader;
var x, y, y2, x2, I: Integer;
Done: Boolean;
Begin
Repeat
If FindColorTolerance(x, y, 1463945, 1, 1, 510, 340, 5) Then
Begin
MMouse(x, y, 0, 0);
wait(100 + Random(100));
If FindDTM(ShoptextDTM, x2, y2, 1, 1, 198, 57) Then
Begin
Writeln('gotcha banker!');
Done := True;
mouse(x, y, 0, 0, False);
mouse(x, (y+17), 0, 0, true);
Exit;
End Else
Begin
Inc(I); // Increase I
Wait(500 + Random(300));
End;
end;
Until (Done) Or (I > 15);
If (I > 15) Then
Begin
FindingShopTrader2;
End Else
FindingShopTrader2;
End;



Procedure BuyingGems;
var x,y,B,V:integer;
begin
cleardebug;
FindBitmap(GemBTM,x,y);
repeat
inc(B);
mouse(x,y,2,4, false);
wait(1000);
mouse(232, 159,2,3, true);
until (B=3);
V :=Length(ItemCoordinates('inv', 'Bitmap',GemBTM,[3]));
if (V < 26) then
begin
Writeln('trying to buy again')
BuyingGems;
end else
begin
mouse(445,39,0,0, True);
writeln('script has bought you' + inttostr(StartGemCount+27));
end;
end;


procedure PinCheck;
begin
if (getcolor(184,92) = 255) then
begin
mouse(67, 193, 5, 5, true); //1
wait(500);
mouse(158, 193, 5, 5, true); //2
wait(500);
mouse(257, 193, 5, 5, true); //3
wait(500);
mouse(346, 193, 5, 5, true); //4
wait(500);
end else
begin
writeln('pin is no where');
end;
end;



Procedure Banking; //my own mainly //progress=needs alot of work
var x,y,GemCountA,GemCountB:integer; // a is before deposit. b is after
begin
findingbanker;
GemCountA :=Length(ItemCoordinates('inv', 'Bitmap',GemBTM,[3]));
FindBitmap(GemBTM,x,y);
PinCheck;
mouse(x,y,2,4, false); //right clicks gem in inventory
wait(1000);
mouse(x,(y+72),0,0,true); //left clicks deposit alloption in menu. rs text, is different…
GemCountB :=Length(ItemCoordinates('inv', 'Bitmap',GemBTM,[3]));
if (GemcountB>0) then
begin
banking;
end else
begin
Writeln('Made Deposit');
Writeln(''); //creates space
end;
NumOfTrip := (NumOfTrip+1)
TotalOfGems := (TotalofGems+GemcountA);
Writeln('Came to Bank with' + inttostr(GemcountA) + 'gems');
Writeln('Deposited' + IntToStr(GemCountB) + 'Gems');
Writeln('Trips made =' + IntToStr(NumOfTrip));
closebank;
end;



function CheckLog: boolean; //my own sees if you're logged in. stops script atm. later on, log in will be made.
begin
If not LoggedIn then
begin
Writeln('person is Loged Out');
terminateScript;
end;
end;

Procedure ProgressReport; //my own progress=done atm
begin
cleardebug;
writeln('**************************************');
writeln('** Amount of Trips Made ='+ inttostr(NumOfTrip));
writeln('** Amount of Gems Bought ='+ inttostr(StartGemCount)+'/' + inttostr(NumOfTrip*27));
writeln('** Time Ran For Total ='+ (timerunning));
writeln('**************************************');
writeln('Sorry, progess does not look pretty yet :(');
end;









begin
SetupScript;
DeclareBitmapsAndDTM;
REPEAT //MAIN REPEAT
WalkToShop;
FindingShopTrader;
checklog;//random check
BuyingGems;
WalkToBank;
checklog; //random check
FindingBanker;
Banking;
checklog; //random check
until (TotalOfGems=GemAmount);
cleardebug;
progressreport;
end.[/PHP]

Sandstorm

2009-10-06 06:40:29

Not bad, just did a quick skim of it. One thing I did notice was your lack of/bad standards. Good standards make a script a LOT more readable, especially if your standards are… well, standard, as it helps people get used to one look, and then they don't have to struggle to figure out what goes where. I had that trouble in my IRC Client a few days ago, actually. Something wasn't working properly, and it wasn't standardized right, so I couldn't see what was wrong (until I restandardized the procedure).

I believe there's a tutorial on standards somewhere, but I don't have time to get it right now. If you still need a link tomorrow, or some help, I'll be happy to help.

~Sandstorm

TRiLeZ

2009-10-06 06:54:44

This is the Scar Script Official Standards
http://www.villavu.com/forum/showthread.php?t=3293

Baked0420

2009-10-06 07:25:51

everyone adopts their own standards over time, not everyone scripts the same here, and most people's are readable, even with the tiny differences, so don't go crazy over reading and memorizing that tut, just use it to help you see what looks nicer, and pick the things you like. I don't really feel like reading your script right now though, it's a little late, and tomorrow I'm busy, so if I remember in two days I'll go over it and see if I can help any :)

Neehosoft

2009-10-06 08:19:45

Use SCAR Tags instead of PHP :
(SCAR) () = []

Sandstorm

2009-10-06 08:32:12

From: Baked0420
everyone adopts their own standards over time, not everyone scripts the same here, and most people's are readable, even with the tiny differences, so don't go crazy over reading and memorizing that tut, just use it to help you see what looks nicer, and pick the things you like. I don't really feel like reading your script right now though, it's a little late, and tomorrow I'm busy, so if I remember in two days I'll go over it and see if I can help any :)


So apparently I didn't have to go out. :duh:

But anyways, little things like bolded words being capitalized, spaces between procedures, etc. are personal choice. But the indent size of two spaces, indent after begin/ends, don't indent begin/ends if they're following an if/then statement, etc. was more what I was talking about (although I should have mentioned that small differences do occur). Thanks for clarifying Baked.

~Sandstorm

Rich

2009-10-06 10:30:54

Just had a quick look over it, and one thing I noticed was this:

 IF (getcolor(191,86)=86) then
begin
writeln('used F.S.T.2 to find shop');
end else
writeln('could not find find shop');
terminatescript;
end;

This will terminate the script no matter what happens, so it should be:

if (GetColor(191, 86) = 86) then
WriteLn('Used F.S.T.2 to find shop');
else
begin
WriteLn('Could not find find shop');
TerminateScript;
end;
end;

reddevil12312

2009-10-07 03:33:17

From: Neehosoft
Use SCAR Tags instead of PHP :
(SCAR) () = []


Lol, I'm Sorry for that. I Just Sort of like php. looks fancy. ill keep to basic tags for now on.

From: R1ch
Just had a quick look over it, and one thing I noticed was this:

 IF (getcolor(191,86)=86) then
begin
writeln('used F.S.T.2 to find shop');
end else
writeln('could not find find shop');
terminatescript;
end;

This will terminate the script no matter what happens, so it should be:

if (GetColor(191, 86) = 86) then
WriteLn('Used F.S.T.2 to find shop');
else
begin
WriteLn('Could not find find shop');
TerminateScript;
end;
end;


Okay. I'm not seeing the difference. but I'll change it, and maybe one day ill figure it out lol

Thanks for all the Time you spent reading and making suggestions. the private server doesn't have good detail, so the script doesn't work very good, but that's okay. i was just practicing anyways. I'll prolly be switching back to regular RS. Ugh… i gotta go back to making my scripts have randomness. And just to point out. SCAR code is much easier to learn then other auto's code ive used. im not avertising or nothing, just wanted to say, SCAR is a pretty great tool lol.

Sandstorm

2009-10-07 09:36:17

  end else
writeln('could not find find shop');
terminatescript;
end;[scar]

That has no begin/end block, and as a result will only execute writeln in the end else, causing it to terminate whether the if/then is true or not.

[scar]else
begin
WriteLn('Could not find find shop');
TerminateScript;
end;
end;

This one has a begin/end block surrounding the writeln and terminatescript, and so will only execute the terminate if the if/then is false.

~Sandstorm