PDA

View Full Version : Failsafes



Iron Man
04-22-2008, 01:57 AM
FailSafes

What are they?

Failsafes basically, are a backup plan if your script messes up. They are very important, because none of us want our mouse moving around randomly all night logged in or logged out searching for something that isn't there.


if not/then

if not LoggedIn then exit; For normal procedures/functions.
if not LoggedIn then break; For loops.

Those are the most used, and there is a reason for it. It kind of explains itself, if you are not logged in then it will exit from the procedure/break from the loop.

Are there other uses for for "if not.. then"?

Yes, they can be used for things from map walking to finding colors on the minimap, to finding inventory items.

Example of no failsafes for inventory item finding:

FindDTM(MuhDTM, x, y, mix1, miy1, mix2, miy2);
Mouse(x, y, 5, 5, true);
etc...


Example of finding a inventory item with failsafes.

if not FindDTM(MuhDTM, x, y, mix1, miy1, mix2, miy2) then
begin
WriteLn('wat t3h h311 m4n y0u d0nt 3v3n h4v3 a p1ck4xe');
NextPlayer(False);
Exit;
end;


See, if it didn't find the DTM it would have wrote in the debug box what the problem was, and then switched to the next player and set the current one to false so he wouldn't be used anymore, then exited the procedure.

For map walking, the standard walking procedure without
failsafes.

RadialWalk(etc....);
MineRock;


What if the character was in a different spot than you wanted him to be? Without failsafes his character could be lost and looking for a rock.

For example of that same thing with failsafes:

if not RadialWalk(etc....) then
if not RadialWalk(etc....) then
begin
WriteLn('choob, you didnt walk to the right spot');
NextPlayer(False);
Exit;
end;


Same idea for that.

if/then

Basically the same idea as if not then, but instead if it didn't find it, it will look for if you did.

This is mostly used for things like FindObjCustom or other color finding things.

Example of finding a object without failsafes.

procedure FindDaPwnageRock;
begin
FindObjCustom(x, y, ['Wazzahhh!!', 'not much'], [255], 15);
Mouse(x, y, 4, 4, true);
end;


Example of finding a object with failsafes:

procedure FindDaPwnageRock;
begin
if not LoggedIn then exit;
if FindObjCustom(x, y, ['<3 Failsafes', 'me too!'], [255], 15) then
Mouse(x, y, 5, 5, true);
end;


If it wasn't logged in it wouldn't try to find the color like explained before ;)
If it found the object, it would click on it.


Counter Method

Well, this is method is most effective for loops. It pretty much counts how many times you've done something, so its like doing a progress report, but for failsafe purposes ;)


procedure MineDaChoobyRock;
var
Counter: integer;
begin
if not LoggedIn then exit;
repeat
if not LoggedIn then break;
if FindObjCustom(x, y, ['up text'], [255, 111112], 15) then
begin
Mouse(x, y, 5, 5, true);
Counter := Counter + 1;
end;
until((InvFull) or (Counter >= 50));
end;


So, the inventory has 28 spaces. The counter goes up one each time it finds the thing, and if it equals or is greater than 50 then it will stop the loop. So if it was clicking the wrong thing it won't keep clicking it.


MarkTime and TimeFromMark

The name kind of explains itself, it will mark a time like when you set a timer, and TimeFromMark is like the noise that comes when the timer goes off. (No the computer doesn't scream at you saying that its done the time):p

A example:

procedure CutNoobyTrees;
var
MarkedTime: integer;
begin
if not LoggedIn then exit;
MarkTime(MarkedTime);
repeat
if not LoggedIn then break;
if FindObjCustom(etc...) then
Mouse(x, y, 5, 5, true);
until((InvFull) or (TimeFromMark(MarkedTime) >= 9999999));
end;



Else/End Else

This will do the thing you want it to if things happened different. This is kind of hard to explain so I will show a example.

procedure WalkToSpot;
begin
if not LoggedIn then exit;
if DTMRotated(Bank, x, y, mmx1, mmy1, mmx2, mmy2) then
begin
Mouse(x, y, 5, 5, true);
FFlag(0);
WriteLn('Found bank!');
end else
begin
WriteLn('Did not find the bank');
NextPlayer(False);
Exit;
end;
end;

skilld u
04-22-2008, 01:58 AM
hot.



looks nice. very helpful.

faster789
04-22-2008, 02:27 AM
:D Sweeet TUT, I'm sure this'll help many of the noobs!
Btw, IMO you deserve a Tut cup. ;)

NiCbaZ
04-22-2008, 02:27 AM
ty i have only been doing this type of failsafe

if not radialwalk 193,19398,378387 then
radialwalk .28747.939827.903394


tyvm will use this when i get home im add a nice new feture in my script a LOC

like

if findtree symbol then loc = attree
if not find sybol tree then nextplayerfalse


thxx +repp

Iron Man
04-27-2008, 03:07 AM
So, is there anything you can think of that I can add?

XRaye
05-14-2008, 01:08 AM
Can you do

'if not <tpa stuff> then
if not <findobj stuff> then
terminatescript;'
?

I know failsafes don't matter that much when it comes to this stuff, but just wondering.

PvH
05-14-2008, 06:13 AM
nice tut:)
i didn't learn anything from it.. but it will help others:)
rep++ for the tut;)

Iron Man
05-14-2008, 11:14 PM
Can you do

'if not <tpa stuff> then
if not <findobj stuff> then
terminatescript;'
?


Yeah you could, but I'd use exit instead of terminatescript.

XRaye
05-16-2008, 10:32 PM
Ok Thanks :)

kor
05-28-2008, 07:44 PM
Really nice guide, Rep ++! helped me ;)

turbobk
10-03-2008, 01:28 PM
A example:

procedure CutNoobyTrees;
var
MarkedTime: integer;
begin
if not LoggedIn then exit;
MarkTime(MarkedTime);
repeat
if not LoggedIn then break;
if FindObjCustom(etc...) then
Mouse(x, y, 5, 5, true);
until(InvFull or (TimeFromMark(MarkedTime) >= 9999999)); // <-- Lil mistake. :)
end;





Very nice tutorial though, very nicely explained. Gratz :D

hrh
01-17-2009, 12:46 PM
this is very helpful to me and my script thank you! clearly set out and easy to read, thanks!