SRL Archive - First Scripts

HERBLORE! First script.


NoobCode

2014-07-21 22:13:49

Hey all, the main reason i'm sharing this script is to help coding noobs (like myself).
I've commented almost every line in this code and hope it helps at least one person to become a better scripter.

I have to give a big thanks to TheMayor! without his All-In-One tutorial i wouldn't be posting this. ( I also stole his progress report) check out this guide for more help. https://villavu.com/forum/showthread.php?t=107757

I've also used antiban's and miniBreaker from Ashaman and Coh3n (I think that's all! =/ sorry i wrote this awhile back).

Anyways, I hope this helps you noobs out there understand coding a bit better while making some gold at the same time!!

SETUP
-Go to Taverly bank!
-You NEED to make sure 'withdraw-14' is an option when its banking. Do this by withdrawing 14 items of something from your bank before running the script.
-Have the mats in the proper slot in your bank (or change the code to suite your bank).
-Have enough mats to last awhile :P
-Click play and watch it go


BANK SLOTS
[ATTACH=CONFIG]23619[/ATTACH]

Feedback on how i can improve my code would be appreciated!

Thanks, and enjoy.
P.s. Use this script and try to make a headless arrow crafter if you're learning.

[ATTACH]23620[/ATTACH]

nickrules

2014-07-22 01:37:25

Hi - First off, welcome to the community, and it's great to see someone contributing so soon after joining

If your script works for you, great - but there are a lot of places to improve. First off, I like some of what you're doing with the antiban - such as your MiniBreaker function, but you have some issues with you case structures, and in general structuring issues with your antiban. This is kind of a long post, but stick with it and try to implement the suggestions I offer, and you could have an outstanding script on your hands.

While you demonstrate a solid understanding of many of the antiban functions (which is super important, and a great skill to have), your case structures kind of don't make sense (syntaxually they make sense and compile, but from a logic standpoint, I don't think you realize quite what you're doing).

So lets take a look at one of your function. I've annotated off to the side, with comments, what the script interpreter is doing, and break down the improvements further below

procedure antiBan();
begin
case (random(50)) of //right here, we generate a random number, 0-49
1, 19, 35, 60: //if that number is 1,19,35, or 60, do the following. But 60 won't happen, because a number that large won't be generated
begin
{$IFDEF DEBUG_ON}
writeln('****** antiBan [move off client and sleep]');
{$ENDIF}
mouseOffClient(OFF_CLIENT_RANDOM);
wait(randomRange(5000, 10000));
end;
5, 8, 15, 25, 28, 35, 38, 45, 48: //if that number is 5, 8, 15, 25, 28, 35, 38, 45, or 48, do this:
begin
{$IFDEF DEBUG_ON}
writeln('****** antiBan [sleep and move mouse] + [secondary]');
{$ENDIF}
sleepAndMoveMouse(randomRange(2000, 3000));
case (random(55)) of //generate a random number, 0 to 54
1: randomRclickItem(); //if it's one, do this
2: sleepAndMoveMouse(randomRange(1000, 2000));//2, do this,
3: pickUpMouse(); //3.... etc.
4, 5, 11:
begin
mouseOffClient(OFF_CLIENT_RANDOM);
wait(randomRange(5000, 10000));
end;
6, 7, 13..18: smallRandomMouse();
20..23: randomCompass(50, 150, true);
8: mouseMovingObject();
9, 10, 24..27:
begin
tabStats.open();
wait(randomRange(750, 1750));
mouseBox(tabStats.getSkillBox(Skill_HERBLORE), MOUSE_MOVE);
wait(randomRange(750, 1750));
tabBackpack.open();
end;
11..12: //this only gets called if a 12 is generated, because a case cover 11 already exists above.
begin
tabStats.open();
wait(randomRange(750, 1750));
mouseBox(tabStats.getSkillBox(Skill_HERBLORE), MOUSE_MOVE);
wait(randomRange(750, 4750));
tabBackpack.open();
end;
end;
end;
end;
end;

First of all, you select numbers for the cases more or less at random, when you could just use a simple range
//THIS:
1, 19, 35, 60: //here you jump around and pick numbers for the case at random...
begin
{$IFDEF DEBUG_ON}
writeln('****** antiBan [move off client and sleep]');
{$ENDIF}
mouseOffClient(OFF_CLIENT_RANDOM);
wait(randomRange(5000, 10000));
end;
//is the same as this:
1..4: //but each number has an equal chance of being generated. there' no point in hopping around picking meaningless numbers. There's a 4 out of 50 chance of this block of code being called here, just like there's a 4 out of 50 chance of the above block of code being called
begin
{$IFDEF DEBUG_ON}
writeln('****** antiBan [move off client and sleep]');
{$ENDIF}
mouseOffClient(OFF_CLIENT_RANDOM);
wait(randomRange(5000, 10000));
end;

second, you nest your case structures in here, which greatly affects the probability of many of your antiban functions calling
5, 8, 15, 25, 28, 35, 38, 45, 48: //9 out of 50 chance of this block of code being called
begin
{$IFDEF DEBUG_ON}
writeln('****** antiBan [sleep and move mouse] + [secondary]');
{$ENDIF}
sleepAndMoveMouse(randomRange(2000, 3000));
case (random(55)) of //but within this block you call another case structure!
1: randomRclickItem(); //That means that only if the first number generated was one of the above(5, 8, 15,...), and then the second number (generated one line above this) is one of these numbers, will this code be called. Since this has a 1/55 chance, and the first block a 9/50 chance, that means there's only a 0.3% chance of this function actually being called!
2: sleepAndMoveMouse(randomRange(1000, 2000));
3: pickUpMouse();

Third, you have two or three different antiban functions. Why not combine them?

Fourth, you recreate several functions that already exist in the SRL library (and are MUCH safer to use, and less likely to break!)

for example, you functions
function isLoggedOut(): boolean;
begin
result := (getColor(315, 401) = 157619);
end;

function isBankMenuOpen(): boolean;
begin
result := (getColor(282, 25) = 379903);
end;

function isMenuOpen(): boolean;
begin
result := (getColor(217, 45) = 379903);
end;

function isGrinding(): boolean;
begin
result := (getColor(296, 212) = 329187);
end;

function cutMenuOpen(): boolean;
begin
result := (getColor(434, 348) = 11764490);
end;

have SRL equivalents of

isLoggedIn();//is the the opposite of isLoggedOut, but by using the "not" keyword, it can be used the same way
TRSBankScreen.isOpen();//same is isBankMenuOpen
//I'm not actually sure what the isMenuOpen function reffers to, but it is most likely covered by SRL. Poke around the SRL Include files and see what you can find.
//same as above, but this time with isGrinding
TRSProductionScreen.isOpen() //is the same as cutMenuOpen


This is just a step above coordinate clicking and highly unsafe. What if the user runs out of herbs, or the herbs move somehow (perhaps an item is removed or something, i don't know…). Why not make your script smarter, and allow users to have their herbs anywhere in the bank, by using DTMs or Bitmaps? There are many tutorials on the two subjects, which will greatly improve the quality of your scripts.
procedure getHerb();
var
x, y, fail, j: Integer;
timer: TTimeMarker;
myBox, myBox2, closeBank, depositBank: TBox;
begin
timer.start();
smartImage.clear;
depositBank := intToBox(394, 569, 420, 582);
mouseBox(depositBank, MOUSE_LEFT);
wait(randomRange(100, 1200));
myBox := intToBox(85, 191, 105, 208);
mouseBox(myBox, MOUSE_MOVE);
wait(randomRange(100, 1000));
mouseBox(myBox, MOUSE_RIGHT);
wait(randomRange(100, 1050));
chooseOption.select(['-14']);
wait(randomRange(100, 1350));
myBox2 := intToBox(128, 187, 149, 200);
mouseBox(myBox2, MOUSE_MOVE);
wait(randomRange(100, 1000));
mouseBox(myBox2, MOUSE_RIGHT);
wait(randomRange(200, 1050));
chooseOption.select(['-14']);
wait(randomRange(100, 1350));
closeBank := intToBox(522, 17, 530, 25);
mouseBox(closeBank, MOUSE_LEFT);
wait(randomRange(50, 650));
if (timer.getTime() > 60000) then
terminateScript();
end;

Finally, your mix function includes yet more antiban. The antiban should be handled in the antiban function, and then called in the mix function - there's no need for all this code repetition. And honestly, I'm not too sure why you do much of what you do in this function. You should attempt to click the items needed for the combination window to open like 3-5 times, then log out if it doesn't work out (SRL has a function for logging out!). IF it does, keep going, and do whatever it is you do to combine the herbs (click a button, I'm guessing.) Make sure not to use mousebox or coordinate clicking - use DTMs or Bitmaps to find the button and then click it. Otherwise, you could be clicking on the main screen area, and send your player walking all over runescape, or something worse. Finally, make sure you are calling your antiban function appropriately.

Fix up these things, and in no time you'll be a pro. It might seem daunting at first, but it's really not so bad. Just keep trying, and great work so far! :garfield:

For bonus points, implement the SRL player system thing (so you can use the logout and login functions by SRL). :stirthepot:

PM me if you (or anyone reading this) need any help. I'm not always active, but i'll do my best.

NoobCode

2014-07-22 01:53:42

That's the type of feedback i'm looking for, thanks for putting the time in to say all that. I'll do my best to implement those ideas! I'll work on my structure and probably will pm you soon :P The SRL player system still confuses me but I'll work on it.

Any more tips/suggestions people? I'd like to improve my coding.