SRL Archive - Reflection Tutorials

How to Make a Reflection Location Check


benjaa

2009-01-08 20:10:47

How to do a Reflection Location Check


Problem - 'My script uses a procedure that walks into a room, but as a failsafe, I want to test if he indeed gets to the room'.

Solution -
function InRoom : boolean;

Introduction
Welcome to my tutorial on How to Make a Function which questions whether your character made it to a certain location. Along the way I will teach you;
- How to find a point using SCAR
- How to find a point using Sumilions PathMaker

For this tutorial you will need:
- SCAR 3.15+ with Latest SVN Includes
- SMART
- Reflection (Get it here!)
- Sumilion's PathMaker (Get it here!)

Getting Started
Now that you have all the software that you need, move your character into the square room that will be your target. I choose the Alkharid Tannery.



Next, you will need to get the points of the North-West and South-East points. These are both in a TPoint of the tile. When you put the two points together, they will create the TBox "area" for testing.



How to find a Point using SCAR
So first of all, let's find the point using SCAR. Here's the piece of script we will be using;

program New;
{.include srl/srl/misc/Smart.scar}
{.include SRL\SRL.scar}
{.include SRL\SRL\Reflection\Reflection.scar}
const
SmartWorld = 50;
Members = False;

procedure DeclarePlayers;
begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;

Players[0].Name :='';
Players[0].Pass :='';
Players[0].Nick :='';
Players[0].Active := True;
end;

procedure RecordPos;
var
TP : Tpoint;
begin
TP := GetMyPos;
Writeln('Point('+Inttostr(TP.x)+', '+IntToStr(TP.y)+')');
end;

procedure SetupSmart;
begin
SmartSetupEx(SmartWorld, Members, true, false);
while not SmartActive do wait(100);
SetTargetDC(SmartGetDC);
end;

begin
SetupSRL;
SetupSmart;
if(not LoggedIn)then LoginPlayer;
RecordPos;
end.

Finding the NWPoint
Now move your character as close as you can to the North-West corner. As you can see, in the tannery my position is 1 Tile south of where the corner is. This can easily be fixed by adding 1 to the y value that the script above will give.I ran my script and got; Point(3270, 3193+1). This value will be known as "NWPoint'.



Finding the SEPoint
Next, we move our character to the "SEPoint". Once again, run the script and note the answer. I got; Point(3277, 3189)

.



Building the function
Now that we have these points, we are ready to build the function! So, here it is.

function InTannery : boolean;//i renamed mine
var
Area : TBox;
SEPoint, NWPoint2, MP : TPoint;
begin
if(not LoggedIn)then exit;//don't touch
SEPoint := TileToMM(Point(3277+1, 3189-1));//replace the numbers - 3277, 3189 - with
//your numbers, but leave in the +1 and -1
NWPoint := TileToMM(Point(3270-1, 3194+1));//same deal with - 3270, 3194

//leave these alone
Area := PointToBox(Point2, Point1);
MP := TileToMM(GetMyPos);
Result := PointInBox(MP, Area);
end;

How to Test It
You can now test this script by using this;

program New;
{.include srl/srl/misc/Smart.scar}
{.include SRL\SRL.scar}
{.include SRL\SRL\Reflection\Reflection.scar}
const
SmartWorld = 50;
Members = False;

procedure DeclarePlayers;
begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;

Players[0].Name := '';
Players[0].Pass := '';
Players[0].Nick := '';
Players[0].Active := True;
end;

function InTannery : boolean;
//by benjaa
var
Area : TBox;
SEPoint, NWPoint2, MP : TPoint;
begin
if(not LoggedIn)then exit;
SEPoint := TileToMM(Point(3277+1, 3189-1));//remember to change these
NWPoint := TileToMM(Point(3270-1, 3194+1));//remember to change these

Area := PointToBox(Point2, Point1);
MP := TileToMM(GetMyPos);
Result := PointInBox(MP, Area);
end;

procedure SetupSmart;
begin
SmartSetupEx(SmartWorld, Members, true, false);
while not SmartActive do wait(100);
SetTargetDC(SmartGetDC);
end;

begin
SetupSRL;
SetupSmart;
DeclarePlayers;
If(not Loggedin)then LoginPlayer;
Writeln(BoolToStr(InTannery));//this will tell you True/False
end.

And now you're done! Run it and test it.

————————————————————————
How to find Points using PathMaker

On a small offnote I will teach you how to do this using Sumilion's PathMaker. This will not always work because the map does not cover the whole RS map, but it is much easier.

Open PathMaker.
Press Image -> Load Image -> RSWorld.jpg
Move the cursor to your room.

Select the NW Corner and SE Corner, and note the values in the top right corner. These can be put straight into the function InPlace featured above.



Hey Presto!

———————————————————————–

I hope you enjoyed my tutorial on How to Make a Reflection Location Check. Please post results, suggestions, criticisms and rate the thread.

Good luck with Reflection Scripting!

benjaa

2009-01-08 20:12:02

~Reserved for all InRoom functions~

function InTannery : boolean;
var
Area : TBox;
SEPoint, NWPoint, MP : TPoint;
begin
if(not LoggedIn)then exit;
SEPoint := TileToMM(Point(3277+1, 3189-1));
NWPoint := TileToMM(Point(3270-1, 3194+1));

Area := PointToBox(SePoint, NWPoint);
MP := TileToMM(GetMyPos);
Result := PointInBox(MP, Area);
end

NCDS

2009-01-08 20:18:03

you should fix the images so they show up without having to follow a link, but other then that very nice!
rep+

Get that TUT Cup ;)

benjaa

2009-01-08 20:27:03

lol, yeah i fixed up images as soon as i posted

i used Notepad to write it, so I mispelt some links

Scaper

2009-01-12 15:25:45

keeps on throughing errors

[Runtime Error] : Out Of Range in line 453 in script C:\Program Files\SCAR 3.15\includes\SRL/SRL/Core/Login.scar

Lancelot074

2009-01-12 18:38:58

Yours does not work, it should be;

function InTannery : boolean;
var
Area : TBox;
SEPoint, NWPoint, MP : TPoint;
begin
if(not LoggedIn)then exit;
SEPoint := TileToMM(Point(3277+1, 3189-1));
NWPoint := TileToMM(Point(3270-1, 3194+1));

Area := PointToBox(SePoint, NWPoint);
MP := TileToMM(GetMyPos);
Result := PointInBox(MP, Area);
end;

Heysus

2009-01-12 19:06:26

Nice tut. :)
You could have also done Area := IntToBox(3277+1, 3189-1, 3270-1, 3194+1). Takes up a little less space ;)

ZaSz

2009-01-12 19:38:39

Nice job, but your making it too complicated then what it actually is.


var
P: TPoint;
Begin
P := GetMyPos;
if PointInBox(P, IntToBox(x1, x2, y1, y2)) then //(x1,y1 = top left) x2,y2 = bottom left.
begin
writeln('You are in the box!');
end;
End.