PDA

View Full Version : How To Make A Flawless Script!!!



Naum
04-15-2008, 02:43 PM
How To Make a Script Run Flawlessly.


This tutorial has some quotes from Chuck Norris, those who are not worthy must NOT look!, Or Fear Death!


Table Of Contents:
I - Beginning Notes.
II - Intoduction.
III - Improvisations.
IV - Failsafes.
V - TimeMarks!!
VI - End Notes.

I - Beginning Notes.

Welcome to NaumanAkhlaQ's tutorial on How To Make a Script Run Flawlessly. SO why did I make this tutorial??
Well a script without Failsafes, , TimeMarks and Improvisation[/i] techniques is like Chuck Norris without his roundhouse kicks. <-- Freaky, no?
Every script needs this criteria for it to run flawlessly. N.B, I believe that there is no such thing a flawless becuase nothing is [u]perfect flawless just means good.
Ok so lets begin!!!


II - Introduction.

SO what are Failsafes, TimeMarks and Improvisations.
Well they are what makes a script run Flawlessly.
Ok that this scenario for instance.
Your right outside the general store and you need to get inside, just one problem your in world 1, and it's really crowded.
What could you do?

http://i28.tinypic.com/2vab887.jpg

No Problem you say just use If FindSymbol(x,y,'store') Then... But how will S.C.A.R manage to find the symbol when there are loads of player dots crowding the symbol???
Chuck Norris says "RoundHouse kick all of them in their Faces!!!" Alas it isn't that easy.


III - Improvisations.


Ok so returning to the problem we encountered in chapter II, what could we use?
Ok SO Our Options:

1: Co-ord Clicking.
2: Color Finding;
3: Make it repeat until it finds the symbol.

Ok so I'll put them in order of non-detectability:
2: Color Finding;
3: Make it repeat until it finds the symbol
1: Co-ord Clicking.

So how can we use them in our script, here is an example:

http://i28.tinypic.com/2vab887.jpg


If (not(FindSymbol(x,y,'store'))) Then
Begin
WriteLn('General Store Not found, Trying another tack');
If FindColorSpiral(x,y,47587,Co-ords here) Then
Mouse(x,y,1,1,true)
FFlag(0)
If (Not(FindColorSpiral( x,y,47587,Co-ords here) Then
WriteLn('Couldnt Find Color, now going to co-ord click')
Begin
Mouse(657,655,5,5,true);
FFlag(0)
If (not(FlagPresent)) Then
WriteLn('We have died')
TerminateScript;
end;
end;


^ Thats Just an example, but hounostly it looks very messy so hows about we put it in a seperate Procedure ^

SO here
Procedure TryAgain;
Begin
WriteLn('General Store Not found, Trying another tack');
If FindColorSpiral(x,y,47587,Co-ords here) Then
Mouse(x,y,1,1,true)
FFlag(0)
If (Not(FindColorSpiral( x,y,47587,Co-ords here) Then
WriteLn('Couldnt Find Color, now going to co-ord click')
Begin
Mouse(657,655,5,5,true);
FFlag(0)
If (not(FlagPresent)) Then
WriteLn('We have died')
TerminateScript;
end;
end;

Procedure FindStore;
Begin
If (not(FindSymbol(x,y,'store'))) Then
Begin
TryAgain;
Begin
BuyBuckets; //e.t.c if our script hasn't terminated //
end;
end;
end;

That Looks much better and less messier.
Thats that covered, now what about makeing it repeat until it finds the symbol
Well we could do something like this.

If (Not (FindSymbol(x,y,'store'))) then
Begin
Repeat
If FindSymbol(x,y,'store') then
Result := True;
Mouse(x,y,1,1,true);
Until(Result);
FFlag(0);
end;
^ But what if it doesn't find it wouldn't that be a waste of time, that leads us on to the next chapter on FailSafes.


IV - Failsafes.

Ok so scenario 2 - we can't let it keep trying to find it, we need to make it stop after doing ten tries or something...
And Failsafes do exactly that.
So First we make a variable called Tries as an Integer; .

http://i28.tinypic.com/2vab887.jpg


Procedure FindStore;
var
Tries: Integer; <---- Here!!!
Begin
If (Not (FindSymbol(x,y,'store'))) then
Begin
Repeat
If FindSymbol(x,y,'store') then
Result := True;
Mouse(x,y,1,1,true);
Until(Result);
FFlag(0);
end;
end;

OK SO we made an Integer called tries, now what do we do?
One good thing about an Integer as it will always start at 0 unless specified not to. So we can keep adding on one in a loop until it will get to 10 as they say so our code could look something like this:

Procedure FindStore;
var
Tries: Integer; <---- Here!!!
Begin
If (Not (FindSymbol(x,y,'store'))) then
Begin
Repeat
If FindSymbol(x,y,'store') then
Tries:=Tries+1;
Result := True;
Mouse(x,y,1,1,true);
Until(Result) or (Tries = 10);
FFlag(0);
end;
end;

SO what we are doing there is basically telling it to add one onto zero each time until it gets to ten meaning it will try to find then symbol 10 times. so Tries:=Tries+1; is basically 0:=0+1 and it a second time is 1:=1+1; e.t.c

SO what does
Tries = 10
do? What it does is that it will stop after Tries is equal to 10 meaning it will try and find the symbol store until it finds it or it tires 10 times.
Simple huh....
But Chuck Norris isn't impressed, "So wouldn't it time out just as it reaches ten meaning it might not click???".
Well guess what folks Chucks right again!!!

Procedure FindStore;
var
Tries: Integer; <---- Here!!!
Begin
If (Not (FindSymbol(x,y,'store'))) then
Begin
Repeat
If FindSymbol(x,y,'store') then
Tries:=Tries+1 <--// Will stop here! if it finds it the tenth time//
Result := True;
Mouse(x,y,1,1,true);
Until(Result) or (Tries = 10);
FFlag(0);
end;
end;

So it should look like:

Until(Result) or (Tries > 10);

Becuase when its over ten meaning it will stop after it's clicked the symbol. Thats about all and you can use it if you want to repeat a procedure so you could do (Just for Chuck Norris' pleasure

Repeat
DoRoundHouseKicksOnBadGuys;
i:=i+1;
Until(i> 6{Number Of Bad Guys!})

SO there we go we have made a working Failsafe whilst satisying Chuck Norris :)


V - TimeMarks!!


Ok SO what are TimeMarks?
Well stupid Question lets ask the all knowing Chuck.
Chuck Norris says: "Some code used in a script to make a loop stop after a certain amount of time";
Ok How you use time marks is just declare them a variable first ok lets do Chuck Norris as an Integer.

N.B You must declare the
MarkTime
Before the loop begins.

Example (this would be wrong):
Procedure Chuck;
var Chuck_Norris : Integer;
Begin
Repeat
MarkTime(Chuck_Norris)
Until(TimeFromMark(Chuck_Norris) > (8000))

^That would be wrong as it will start it again from zero so it will never get to 8 seconds, this is what you call an endless loop^

So this would be right:
Procedure Chuck;
var Chuck_Norris : Integer;
Begin
MarkTime(Chuck_Norris)
Repeat
RoundHouseKicks;
Until(TimeFromMark(Chuck_Norris) > (8000))

A good way of reminding you that you should never declare it in a loop is that: Chuck Norris always comes first.

So now you wonder what this does??
Until(TimeFromMark(Chuck_Norris) > (8000))
Well it tells S.C.A.R that it will repeat RoundHouseKicks; for 8 seconds( Not enough time??? Too much time for Chuck Norris.!)
Remember the code that goes Inbetween the brackets must be declared as an Integer!!!.


SO you could use it for something else:
Scenario 3:
Your Mining some coal rocks, with your own script, but sometimes the ore goes when your still waiting and the pickaxe might break
So how would you solve this:
Well what the WaitWhileMining procedure looks like is:


procedure WaitWhileMining;
begin
repeat
NAutoRespond;
FindFastRandoms;
PickChecker;
Check;
if GasFound(fx, fy) then
begin
RunTo('E', False)
wait(7000 + Random(3000))
writeln('We avoided Gas!!! :P')
RunBack;
end;
NAutoRespond;
AntiBan;
until (FindBlackChatMessage('You manage to mine some'))
end;

So we can add a timemark.

procedure WaitWhileMining;
var
Mark : Integer;
begin
MarkTime(Mark);
repeat
NAutoRespond;
FindFastRandoms;
PickChecker;
Check;
if GasFound(fx, fy) then
begin
RunTo('E', False)
wait(7000 + Random(3000))
writeln('We avoided Gas!!! :P')
RunBack;
end;
NAutoRespond;
AntiBan;
until (FindBlackChatMessage('You manage to mine some')) or (TimeFromMark(mark) > 20000))
end;
What this will do is it will time out after 20 seconds from when the pick touches the rock to when 20 secs is up.
See TimeMarks are used everywhere!!!!

VI - End Notes:

The reason why I wrote Chuck Norris in bold was becuase if you don't show him respect then you will die, simple!
If you liked this tutorial then you can Rep++ me :) :) :)

Hope you learned something :).

Harry
04-15-2008, 02:50 PM
I don't really need this tut, my scripts are already flawless (A).

Well, good job, IDK what to say with this E-Gun against my head :(

Nauman says:
http://www.villavu.com/forum/showthread.php?t=29049?p=384646#post384646
Nauman says:
"thanks man"

Naum
04-15-2008, 02:51 PM
Lol you missed out what you wrote and the disturbing emotes :rolleyes:, Thanks for the comments Hy :).

JuKKa
04-15-2008, 02:55 PM
theres alot of Begins missing in the tutorial examples.

Naum
04-15-2008, 02:57 PM
Well the examples aren't meant to compile there only mean't to show the person roughly how it's done.
But nevertheless maybe you can point out the areas :).

Torrent of Flame
04-15-2008, 03:00 PM
Wahey. I can add a wait whilst chopping now :D

Torrent of Flame
04-15-2008, 03:13 PM
procedure WaitWhilstChopping; //Kudos to Naum and his "Flawless Script" tutorial
var
CuttingMark : Integer;
begin
MarkTime(CuttingMark);
repeat
AntiBan;
FindRandoms;
CheckAxe;
EntFinder;
AntiBan;
until (FindBlackChatMessage('cut some logs')) or (TimeFromMark(CuttingMark) > 200000));
end;

Identifier Expected? 0_o

Naum
04-15-2008, 03:58 PM
Here you go:
procedure WaitWhilstChopping; //Kudos to Naum and his "Flawless Script" tutorial
var
CuttingMark : Integer;
begin
MarkTime(CuttingMark);
repeat
AntiBan;
FindRandoms;
CheckAxe;
EntFinder;
AntiBan;
until (FindBlackChatMessage('cut some logs')) or (TimeFromMark(CuttingMark) > (200000));
end;
Need to correct my brackets thanks :).

Updated Tutorial :).

ShowerThoughts
04-15-2008, 04:02 PM
Nauman good tutorial, change the examples to work else your a fagg ;)

Torrent of Flame
04-15-2008, 04:03 PM
^.^ Thanks to you too =D

Naum
04-15-2008, 04:08 PM
Yeah I changed them :)

Waddo
04-15-2008, 04:19 PM
Failed when compiling
[Error] (1337:1337): shop not found chucknorisroundhousekickbadguys smashed the baddies thru the walls the shop is no longer standing in script D:\Program Files\SCAR 3.15\Scripts\my scripts\scripts\entershop.scar

help with this error pl0x

Torrent of Flame
04-15-2008, 04:31 PM
Hahaha =P

Naum
04-15-2008, 04:44 PM
Lol waddoo you funny but always put chuck norris in bold or he will round house kick you in the face >.<

Torrent of Flame
04-15-2008, 04:48 PM
he spelt Chuck Norris wrong anyway. Chuck Noris is an imposter!

Naum
04-15-2008, 05:22 PM
Omg call chuck !!!

Torrent of Flame
04-15-2008, 05:24 PM
AMGZ! CHUCK Where are you?!?

Naum
04-15-2008, 05:30 PM
Dunoo probely wrestling with a tiger.

GoF
04-15-2008, 06:16 PM
Nice tut ;) Knew most of this already but still well done :D I think you'd deserve a tut writers cup, but I'm not the one to decide about these things.

E: Except the chuck norris parts. Adds too much gayness to the tut.


Nauman good tutorial, change the examples to work else your a fagg ;)

Your mom.

Naum
04-16-2008, 10:50 AM
Ahh as usual GoF pwns, Thanks alot GoF but chuck is the hero :)

PvH
04-16-2008, 01:45 PM
whoah... very nice tut!
another one from you:D
i learned a bit of it:)
thanks a lot
and rep++ for you;)

Naum
04-16-2008, 02:44 PM
Thanks No Problem :).

King of the Nites
04-17-2008, 01:09 AM
WOWZURS!! I am now rewriting most of my procedures lol. Thanks a ton, rep for you!!

Naum
04-17-2008, 09:02 AM
Thanks No Problem :).

BKNYKavkaz
04-23-2008, 04:10 PM
Wow man great TUT. It has honestly helped me a lot...gonna start my first script based off this.

However...We all know Chuck Norris has the best of the best scipts/TUTS.

Naum
04-23-2008, 04:13 PM
Ok glad i could help you in scripting :)

kor
05-08-2008, 01:54 PM
THAAAAAAAAAANKSS!!!!!!! awesome tut! helped me alot! woot wot owootoot

Claymore
07-05-2008, 06:15 AM
Sweet! So Chuck Norris does SCAR scripting too?

What can't Chuck Norris do?

Naum
07-07-2008, 07:02 AM
Chuck Norris cant do nothing :p

pure pk l t
07-09-2008, 08:05 AM
Thx NaumanAkhlaQ for a great tut :)

Wanted
07-09-2008, 04:16 PM
You really need to learn how use waits to time your script better Nauman, I see loops in there like FindSymbol with no waits at all, not even like 100 MS, you're basically just causing lag and unnecessary repeats. You need waits in a lot of places such as after mouse movements and checking up texts to selecting options ect.. your scripts would run sooo much smoother and less laggy-er and believe it or not faster.

I think you should read through the part of the tutorial where you create functions for RS and use waits and uptext ect.. effectively http://www.villavu.com/forum/showthread.php?t=32490

Edit: Yea here we go, at least look at part # 7 in there http://forum.scar-scripts.com/showpost.php?p=150&postcount=7