SRL Archive - OSR Help

~*~*Checking if in a certain area~*~*


Recursive

2012-05-14 21:26:47

Okay so I am trying to add something to a script that will check if the character is in a certain area, then it will do the actions in that area. So far this is what I did:

The 2 points that I chose above {Point(197, 448), Point(423, 258)}, will they form a rectangle like this and the script will check inside this rectangle?


Also, this is what the code I am using to check this looks like (I am using Mat's InArea function):

This is the function:
function InArea(Pt1, Pt2: TPoint): Boolean;
var
Loc: TPoint;
Box: TBox;
begin
Loc := SPS_GetMyPos;
Box := PointToBox(Pt1, Pt2);
if (PointInBox(Loc, Box)) then
Result := true else
if NOT (PointInBox(Loc, Box)) then
Result := false;
end;

And this is how I am using it to check the area:
If InArea(Point(197, 448), Point(423, 258)) then
begin
if Not(FindBitMapToleranceIn(Ess, px, py, MiX1, MiY1, MiX2, MiY2, 45)) then
begin
Runbank;
end else
RunAltar;
FindObstacle;
CraftingRunes;
CosmicCount;
Runbank;
Inc(Runs);
IncEx(CosmicCount, RuneCount);

What am I doing wrong? Cause everytime I run it, it just sits there and does nothing.

Also, if you know a better way of doing what I am attempting, please feel free to share :D

tehq

2012-05-14 21:31:49

The points of the box should be pt1: top left, pt2: bottom right

Recursive

2012-05-14 21:35:05

Okay so does that mean it will check for your current position inside a box made up of those 2 points kinda like what I attempted to draw above?

tehq

2012-05-14 21:39:59

That's exactly what it does :) just switch around the points to a point in top left and bottom right in your function. Also, there's a problem with the second part of your code. You're missing a begin/end after an else ;)

Recursive

2012-05-14 22:09:29

Thank you so much!

John

2012-05-15 00:26:08

Note to this, You could just use ObjDTM for area getting, It has proven quite helpful for me .

J J

2012-05-15 06:43:24

From: John
Note to this, You could just use ObjDTM for area getting, It has proven quite helpful for me .

I would probably use this ^ or SPS.

This is what I've used to check if my player has been kicked out of the GOP minigame. It also double checks it by counting colors.
function CheckGOPLobby: Boolean;
var
MyPos: TPoint;
GopLobbyBox: TBox;

begin
SMART_DrawDotsEx(False, ActionBoxTPA, RGBtoColor(194, 178, 146));
SMART_DrawText(290, 429, UpChars, 'check if at gop lobby', clWhite);
GopLobbyBox := IntToBox(39803, 3015, 39863, 3079);
SPS_Setup(RUNESCAPE_SURFACE, ['99_7']);
MyPos := SPS_GetMyPos;
WriteLn('My position is x: '+inttostr(MyPos.x)+' y: '+inttostr(MyPos.y));
if MyPos = Point(-1, -1) then
begin
Exit;
end;
if PointInBox(MyPos, GopLobbyBox) then
begin
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.23, 0.88);
WriteLn('Blue colors: '+IntToStr(CountColorTolerance(7301651, MMX1, MMY1, MMX2, MMY2, 10))+'');
if CountColorTolerance(7301651, MMX1, MMY1, MMX2, MMY2, 10) > 2000 then
begin
WriteLn('We are at the Gop lobby');
Result:=True;
end else
begin
WriteLn('We are NOT at the Gop lobby');
Exit;
end;
end else
begin
Exit;
end;
end;

You basicly use this
WriteLn('My position is x: '+inttostr(MyPos.x)+' y: '+inttostr(MyPos.y));
to determine the box co-ords.

Then you make a TBox with all the co-ords of the box stored in it. If your position matches a point in the box, you will be in the desired area so the result is true. You don't even need to add failsafe like I did, but I'm using a total of 7 different SPS maps and some times it will think that it is at the GOP lobby even though it isn't. So I added a countcolor function to make sure the player has indeed been kicked. It's not necessary for your script I think :P

C:\Simba\Includes\SPS\img\runescape_other
zanaris

is in there
SPS_Setup(RUNESCAPE_OTHER, [zanaris']);
is what you have to use

function CheckZanaris: Boolean;
var
MyPos: TPoint;
ZanarisBox: TBox;

begin
ZanarisBox := IntToBox(1, 2, 3, 4);
SPS_Setup(RUNESCAPE_OTHER, ['zanaris']);
MyPos := SPS_GetMyPos;
WriteLn('My position is x: '+inttostr(MyPos.x)+' y: '+inttostr(MyPos.y));
if MyPos = Point(-1, -1) then
begin
Exit;
end;
if PointInBox(MyPos, ZanarisBox) then
begin
WriteLn('We are at the correct position');
Result:=True;
end else
begin
WriteLn('We are NOT at the correct position');
Exit;
end;
end;
^ that would work if you get the co-ords

if CheckZanaris then
begin
*things to do when you are in that box*
end;

riwu

2012-05-15 06:48:28

the easiest way to check if you are in an area is to use FindSymbols–only 1/2 line required ;) the limitation are that there must be symbols in that area (duh) and that u may have to lower SymbolAccuracy in case it gets distorted.