PDA

View Full Version : Guide to checking if your in a area



rj
03-15-2013, 12:15 AM
Guide on how to check if your in a area!





Here is a cool guide on how to check if you are in a specific area, such as inside of a bank, or outside of a bank. Beleive it or not, you don't need nooby injection to get the current tile your in, you can use Symbol Finding This method is pretty reliable, I have recently find out about it myself!

-What you need to know before reading this tutorial-

-How to make a DTM
-Basic pascal knowledge
-Basic Function knowledge
-Taking a American 8th-9th grade math class or more advanced would help you understand the math being used(Just know the distance formula)


-Basics-

For my example, I am going to want to check if I am inside of the Seers bank or not which is in these red lines:

http://i47.tinypic.com/af9g5l.png

Now, you might be wondering, how are we going to do that? the answer is: We are going to be using the minimap symbols to get our location!

-How to get distance-

Now, first off, the symbols in the Minimap are not always in the same place, BUT they are always close to the same area, so they calculations can always be close. BUT your character square on the minimap is ALWAYS in the same exact coordinate spot which is (643,83) on Runescape 2007. what we will be doing is, finding the distance between your square on the minimap and the DTM's of the symbols that you choose on the minimap, here are the ones I have:

http://i48.tinypic.com/2nu0is5.png

Once you have picked the Symbols you want to use, make a DTM of each of them, and declare them in the script, BUT store the co-coords to each of them to different Variables. For example:

FindDTM(DTM_Bank, x, y, 524, 3, 762, 168)
FindDTM(DTM_House, c, b, 524, 3, 762, 168)
FindDTM(DTM_Smith, t, u, 524, 3, 762, 168)

As you can see, I stored them in different variables. Next We make a function that searches for the DTM's and stores them in the variables:

function IsInBank(): boolean;
var
Dist_To_Symbol,c,b,t,u,Dist_To_House,Dist_To_Smith :Integer;
Begin
Result := false;
FindDTM(DTM_Bank, x, y, 524, 3, 762, 168)
FindDTM(DTM_House, c, b, 524, 3, 762, 168)
FindDTM(DTM_Smith, t, u, 524, 3, 762, 168)
End;

Next, we use the simba function "Distance" to find the distance between (643,83) Which is your player's square, and the DTM's:

Dist_To_Symbol := Distance(X,Y,643,83);
Dist_To_House := Distance(c,b,643,83);
Dist_To_Smith := Distance(t,u,643,83);

you can Debug this by doing a Writeln:

Writeln('Current Distance from Bank symbol:' + ToStr(Dist_To_Symbol))
Writeln('Current Distance from House symbol:' + ToStr(Dist_To_House))
Writeln('Current Distance from Smithing symbol:' + ToStr(Dist_To_Smith))

Now, you go to each corner of the bank, and find the least distance from the symbols while your still in the bank, and the most distance. Now make some constraints that define whether you are in the bank BUT do not make them exactly like the results you got, for example, if you have to be no more then 10 pixels from the bank symbol, and 40 pixels from the smithing symbol, and 50 pixels from the house symbol, do not make them like:

If (Dist_To_Symbol <= 10) And
(Dist_To_House <= 40) And
(Dist_To_Smith <= 50) Then

Otherwise when you re-log they will not work because the symbols end up in a different area! Always increase the distance a little bit.

-Putting it all together-

Now that you have your constraints, you can now finish the function, mine are:

If (Dist_To_Symbol <= 30) And
(Dist_To_House <= 90) And
(Dist_To_Smith <= 90) Then

So if these are met:

Begin
Status := 'Inside of the Bank'
Result := true;
End;

So my final function looks like:

function IsInBank(): boolean;
var
Dist_To_Symbol,c,b,t,u,Dist_To_House,Dist_To_Smith :Integer;
Begin
Status := 'Outside of the bank'
Result := false;
FindDTM(DTM_Bank, x, y, 524, 3, 762, 168)
FindDTM(DTM_House, c, b, 524, 3, 762, 168)
FindDTM(DTM_Smith, t, u, 524, 3, 762, 168)
Dist_To_Symbol := Distance(X,Y,643,83);
Dist_To_House := Distance(c,b,643,83);
Dist_To_Smith := Distance(t,u,643,83);
//Writeln('Current Distance from Bank symbol:' + ToStr(Dist_To_Symbol))
//Writeln('Current Distance from House symbol:' + ToStr(Dist_To_House))
//Writeln('Current Distance from Smithing symbol:' + ToStr(Dist_To_Smith))
If (Dist_To_Symbol <= 30) And
(Dist_To_House <= 90) And
(Dist_To_Smith <= 90) Then
Begin
Status := 'Inside of the Bank'
Result := true;
End;
End;


So my whole Program looks like this (if you want to tweak it)

{$i srl/srl.simba}
Var
X,Y,DTM_House,DTM_Bank,DTM_Smith:Integer;
//IsInBank:Boolean;
Status:String;
Procedure WriteStatus;
Begin
Wait(400);
ClearDebug;
Writeln('Status:' + status);
End;
Procedure FreeMem;
Begin
FreeDTM(DTM_Bank);
FreeDTM(DTM_House);
FreeDTM(DTM_Smith);
End;
Procedure LoadDTM;
Begin
DTM_Bank := DTMFromString('mQwAAAHicY2ZgYEhgYmBIAeJwIE4D8jOBOB mI31xMYGBmFAVjfiAfhhmRMBAAANchBNY=');
DTM_House := DTMFromString('mWAAAAHicY2FgYOhnYmCYDMSdQDwViIOBYr 5A7A/EYUDMzCiKgvmBYsiYEQ2DAAAaywQ2');
DTM_Smith := DTMFromString('mrAAAAHic42BgYHBgYmBwB2JHKHYDYlcgdg FiOyC2ZYBgFyA2A2IrIHYCYnMgdgWx7YIYmBlFseK8nGQGfqAa fJiRAIYBADx3B0A=');
End;
function IsInBank(): boolean;
var
Dist_To_Symbol,c,b,t,u,Dist_To_House,Dist_To_Smith :Integer;
Begin
Status := 'Outside of the bank'
Result := false;
FindDTM(DTM_Bank, x, y, 524, 3, 762, 168)
FindDTM(DTM_House, c, b, 524, 3, 762, 168)
FindDTM(DTM_Smith, t, u, 524, 3, 762, 168)
Dist_To_Symbol := Distance(X,Y,643,83);
Dist_To_House := Distance(c,b,643,83);
Dist_To_Smith := Distance(t,u,643,83);
//Writeln('Current Distance from Bank symbol:' + ToStr(Dist_To_Symbol))
//Writeln('Current Distance from House symbol:' + ToStr(Dist_To_House))
//Writeln('Current Distance from Smithing symbol:' + ToStr(Dist_To_Smith))
If (Dist_To_Symbol <= 30) And
(Dist_To_House <= 700) And
(Dist_To_Smith <= 700) Then
Begin
Status := 'Inside of the Bank'
Result := true;
End;
End;
Begin
LoadDTM;
Repeat
IsInBank;
WriteStatus;
Until False;
AddOnTerminate('FreeMem');
End.
Now you are done!


If you have any questons, feel free to post them here. If you have a suggestion for me to explain my thoughts better PLEASE post them, because I am not the best tutorial writer out there :p

helcast
03-15-2013, 12:28 AM
Oo, I like this method. Bookmarked for later use! :)

sahibjs
03-15-2013, 12:35 AM
I was trying to figuire out yesterday how to do this. Thanks for the guide!

Element17
03-15-2013, 01:59 AM
What about using the NPCs? Since they don't move, or if they do I assume it would be less than the symbols. Just a suggestion! Either or like I said in the other topic I like this function. Gonna play with it and post some results.

rj
03-15-2013, 02:15 AM
What about using the NPCs? Since they don't move, or if they do I assume it would be less than the symbols. Just a suggestion! Either or like I said in the other topic I like this function. Gonna play with it and post some results.

There's more then 1 NPC dot and it might give you unwanted results by giving you the distance to a dot that you don't want

Element17
03-15-2013, 02:19 AM
Ahhh good point.

happy hippo
03-17-2013, 10:40 PM
Thiss will help me out For Sure Thanks

The Killer
03-20-2013, 04:12 PM
You could use symbol finding functions instead of having to make a dtm :)

StickToTheScript
03-20-2013, 04:20 PM
This is awesome! I will make sure that i use this the next time that i need to make a script that involves a lot of walking.

rj
03-20-2013, 07:52 PM
You could use symbol finding functions instead of having to make a dtm :)

I'm so used to making my own DTM's

The Killer
03-20-2013, 08:06 PM
I'm so used to making my own DTM's

Yeah fair enough, I'm just saying it's something you could add :)

shebee
03-21-2013, 01:16 AM
Nice and useful guide!
Will make use of this in my next script probably.

randy marsh
04-29-2013, 11:14 PM
Could I use this in rogues den when theres only one symbol and that's the bank?

rj
04-29-2013, 11:32 PM
Could I use this in rogues den when theres only one symbol and that's the bank?

Yes.