PDA

View Full Version : Making a Flawless script



The Claw
10-05-2007, 05:56 AM
Making a Flawless script

Hey guys. Before I start, I would like to note one thing - if you are looking for a magical, 1 lined function that will make your script flawless, then sadly this tutorial is not the place. This tutorial will teach you the concept of making a flawless script, but will not make it for you. Sorry. ;)

Alright, so we have all run a flawless script in our time. You know the ones I mean, the ones where you can turn off your monitor at night with confidence that when you wake up your autoers will still be autoing. The scripts that make sleeping fun (saw that posted on Ratz! I think? lol)

The scripts where you feel safe letting your precious characters run on, because you know that, due to failsafes and antirandoms, your character wont be left sitting in the one place for 4 hours, clicking on the minimap. You know that your characters wont get stuck inside a loop, be logged out and get stuck on the login screen for 8 hours until you wake up.

Because hey, when you start up the script you are hoping for it to run all night, and its a great dissapointment when you wake up and it hasnt - we have all run a script like that, in our time too.

From reading this tutorial I hope that even the most basic scripter will leave this page with the knowledge required to make one of these flawless scripts I am talking about. Once reading this tutorial, you should be able to make a script as flawless as Wizzups VEM, Wizzups EssMiner, Cows, Tara's Chicken killer and even my Lumby miner (:D).

The script will probably not be as good, or as advanced, but it will keep your accounts safe, and if you do everything right it will be able to run overnight. ;)


AntiRandoms

Firstly I will talk about anti-randoms. Random events are a direct attempt by Jagex to stop autoers, introduced in RSC I believe. They are meant to stop our scripts, and in a lot of cases they do - but we can do things to prevent this.

I'm not going to go into a big tutorial on anti-randoms (Maybe another tutorial?) but there are plenty of other tutorials around. As a general rule, try and call antirandoms after every single action, and during repeated actions, like waiting for your char to mine the rock. But yea they are needed to make a flawless script, theres plenty of tutorials on them though.

Failsafes

One of the most important things about a script is its failsafes. Without them, there is a high chance that your script wont run for more than an hour.

Seriously, I cannot stress enough, the importance of them. Ideally, your script should be prepared for anything that can possibly happen when running it. Things such as breaking out of loops if your character has logged out, or changing the colour to radial-walk with, if the road colour changes.

Most failsafes are used like this: "if not ... then ...". If it doesnt do something, then attempt something else. The if not's can stack, like this:

if not ... then
if not ... then
if not ...then

and so on.

OK enough talking. Lets get on to the examples.

Failsafes - if not LoggedIn...

if not LoggedIn then Exit;

That single line there is the most used line in all of my scripts. It is so simple, and yet, without it no scripts would be able to last overnight safely.

It does exactly what it says - If your character is not LoggedIn, then it will Exit the procedure. You might be thinking, "So what? What is the point?". Well, say for example that your character lagged, and got logged out in the middle of a mining loop.

Without this line, your script would continue to repeat the mining, until your inventory is full (or whatever you have it repeat until). But how can your inventory be full if you're logged out? It can't.

So what would happen is your script would just sit at the Login screen, forever, until you stop the script and start again.

However, if you have this line then when your character gets logged out, then your script will Exit the mining loop straight away, and continue on with the rest of the script.

"But won't the rest of the script mess up, if you are not logged in?" Yes. But not if you have this line at the start of every single procedure and inside every loop ;).

This line is so important that I have it at the beggining of nearly every procedure, function and loop - and so do all good scripters. The idea is, if your character logs out for whatever reason then it will Exit the loop, and wont even start any more procedures. If you construct your main loop correctly, the script will just go straight to the bottom of the main loop where you have this:

if not LoggedIn then NextPlayer(False)
else NextPlayer(True);

For example...

procedure WalkSomewhere;
begin
if not LoggedIn then Exit;
repeat
if not LoggedIn then Break;
WalkSomewhere;
FindFastRandoms;
until SomethingIsDone;
end;

So in short: Have "if not LoggedIn then Exit" at the start of every procedure, and have "if not LoggedIn then
Break" at the start of every loop.

Failsafes - walking...

One of the most important features of a script is it's walking, because this is what gets you places. This is also where most scripts fail. I'm not going into a full tutorial on walking here (maybe another day..) but I have some tips for you.

Take a look at this piece of code:

repeat
if not LoggedIn then Break;
FindRandoms;
if not RadialWalk(WaterColor, 0, 180, 60, 0, 0) then
if not RadialWalk(WaterColor, 0, 270, 60, 0, 0) then
Logout;
until SomethingIsDone

Since RadialWalk returns a boolean if it successfully walks to the spot, we can use it like this.
If it doesnt successfully RadialWalk with the angle of 0, 180 then it attempts to RadialWalk with the angle of 0, 270. If it doesnt do that, then it Logs out, and the "if not LoggedIn" saves our script from hanging at the login screen.

*Note* That piece of code is very specific for water walking from the draynor bank to the lumby swamp. But you can tailor that to your needs easily.

Instead of Logout, you could also do things like Changing the WaterColor variable to a different colour, increasing the Radial, or try another angle with RadialWalking. The possibilities are endless.

FailSafes - TimeFromMark's...

A TimeFromMark is a way of recording the time the script got to something, and then we can check how long it has been since the script got to that point. They are used like this:

MarkTime(MyMark);
Wait(5000);
Writeln(IntToStr(TimeFromMark(MyMark)));

That will write the time since MyMark was Marked.

*Note* you have to declare your mark (MyMark in this case) as an integer.

They can be used like this:

MarkTime(MineWalk);
repeat
if not LoggedIn then Break;
FindRandoms;
if not RadialWalk(WaterColor, 0, 180, 60, 0, 0) then
if not RadialWalk(WaterColor, 0, 270, 60, 0, 0) then
if not RadialWalk(WaterColor, 0, 270, 80, 0, 0) then
GetWaterColor(WaterColor);
FindRandoms;
Wait(1000);
if TimeFromMark(MineWalk) > 240000 then begin LogoutPlayer('Lost - MineWalk2'); Exit; end;
until FindSymbol(x, y, 'Mining spot');

As you can see from this piece of code, it implements all the failsafes I have talked about today. If its not Logged in, then it will Exit, making sure that your script wont get stuck on the Login screen. It uses Failsafes in the walking to make sure that it will always get to where it wants to. Then, it checks if the time since the loop started is over 240, 000 ms (4 minutes..) and if it is, it Logs out your player.

It repeats the whole loop until it finds the mining spot.

*Note* GetWaterColor and LogoutPlayer are just custom procedures which I use in my scripts.

So if everything goes well, that piece of code will check if we are logged in, find randoms, walk (with failsafes), check if we have taken too long it will log out. Repeat until it gets to the mining symbol.

The advantages of TimeFromMark's are, it makes sure that you dont stand around in the one spot for ages, doing nothing.

I mean, in the piece of code above, if I didnt have the TimeFromMark, what happens if it never found the mining symbol, what happens if it was covered when we walked past the mine? It would just keep walking along the water, for hours and hours and hours, until it got an unsolvable random, which would look extremely suspicious to Jagex and would get you banned.

You can use these effectively in pretty much everything. Mining, searching for colours, woodcutting, walking,
anything at all. I use them in my mining procedures like this:

MarkTime(MiningLoad);
repeat
if not LoggedIn then Break; //You should know about this by now ;)
if InvFull then Break; //Checks if invent is full
MineRocks; //My mining function to actually mine
until TimeFromMark(MiningLoad) > (LoadTime * 1000 * 60) + Random(10000); //Loadtime is a constant, I set it at 20. * 1000 * 50 converts it to minutes.

So that piece of code will mine, do all the checks, for a maxtime of 20 minutes, where it will continue with the rest of the script which is walking to bank, banking, and going back to mine. The reason we have this failsafe here is because what happens if we are getting outmined really badly or something goes wrong and we can't see any rocks? (Never happened on my scripts but hey it can on others :D)

It would look suspicious to stand around doing nothing for hours on end.


And lastly...

OK, after reading that you should have sufficient knowledge to go and become the next Fawki or nielsie! :) But like I said - this is not a magical way to create a flawless script, it is just the techniques and concepts to. You will need to implement these techniques into your own scripts, if you want them to be successful - what I mean is, a direct copy + paste will not work in this case.

Just remember - you are not limited to using these failsafes only in the examples I showed, the best scripters will apply these techniques while doing other things too. Try to "build your scripts completely around timed loops, failsafes and breakouts." - Fawki said that once, its the technique that he uses, so do I and many others. So you should use it too :)

Thanks for reading :) Don't PM me. If I didn't explain something clear enough, or you need some help, please post here and I will do my best to explain it better. Hope this helps someone.

Cheers,

~~ The Claw.

ZephyrsFury
10-05-2007, 06:19 AM
Nice tut. Thanks for telling us your secrets. Lol jk, every scripter should incorporate these :p. Might I suggest that you add a small section on counters. For example:


procedure ClickColour;
var
Counter : Integer; //Counter is an integer
begin
Counter := 0;
repeat
if (FindColor(x, y, 23423445, MMX1, MMY1, MMX2, MMY2)) then
begin
Mouse(x, y, 5, 5, True);
FFlag(10);
Break; //If it finds the colour then it breaks the loop.
end;
Counter := Counter + 1; //Increments the Counter variable.
until(Counter > 5); //Repeat until counter is greater than 5.
if (Counter > 5) then
begin
Writeln('Could not find colour after 5 tries');
LogOut; //If it can't find the colour then it logs out the player and exits the procedure.
Exit;
end;
end;

ShowerThoughts
10-05-2007, 06:21 AM
update! we want more! :D

nice tut ;)

The Claw
10-05-2007, 06:40 AM
thanks for that idea zephys, ill update it later :)
hermpie, what things would you like to see?

BobboHobbo
10-05-2007, 07:32 AM
Omg how gay is this Tutorial!

Jokes man, Nice tut, there is over 5000 words in this tut, nicely written and presented

I think there isnt enough Fail safe's in this tutroial.

The Claw
10-05-2007, 07:50 AM
I think there isnt enough Fail safe's in this tutroial.

OK Fair enough, if you were being serious, what else would you like to see? More examples of how to use them, or whole new failsafes?

ZephyrsFury
10-05-2007, 07:56 AM
Another common fail safe that I use for walking is blind clicks. For example if the RadialWalk doesn't work my next failsafe would be a mouse click in the general direction of where the colour should be and then if that doesn't work then LogOut;.

BobboHobbo
10-05-2007, 11:18 AM
OK Fair enough, if you were being serious, what else would you like to see? More examples of how to use them, or whole new failsafes?

Nah im joking its a good tut, no doubt about that.

Rikje
10-05-2007, 06:57 PM
wow nice tut the claw!. Very well explained :)

ShowerThoughts
10-05-2007, 07:29 PM
thanks for that idea zephys, ill update it later :)
hermpie, what things would you like to see?


ehm, your only talking about failsafes look at your topic title ;)
just make some extra cool stuff like stuff i dont know and you dont know what i dont know know ya?

just add somthing cool that we really need ;)

thanks,
hermpie

The Claw
10-06-2007, 01:47 AM
ehm, your only talking about failsafes look at your topic title ;)
just make some extra cool stuff like stuff i dont know and you dont know what i dont know know ya?

just add somthing cool that we really need ;)

thanks,
hermpie

I spoke about failsafes and randoms, and this is all you need to make a flawless script really.

Wanted
10-07-2007, 07:18 AM
Great tutorial.

One thing though, you can just use

NextPlayer(LoggedIn);

rkroxpunk
10-09-2007, 09:53 AM
very nice tut mister, I was about to say something that you missed and then I looked again and it was there :p very nice

ZephyrsFury
10-09-2007, 01:06 PM
very nice tut mister, I was about to say something that you missed and then I looked again and it was there :p very nice

The only thing wrong about this is that it should be in the Beginners Tut section IMO. :p

the scar noob
10-13-2007, 01:18 PM
Great tut, except of otheres I actually enjoyned reading this one :)
Everything is very clear explained, I like it!

Keep on writing more tuts, I will read them all!:p

-Tsn.