slushpuppy
2012-02-29 05:17:43
I was making a harpoon and alkharid smelting script, unfortunately it was my first encounter the rather annoying inaccuracy of using SPS to determine player location-especially when you need to know whether you are properly inside the house and not just at the door for e.g.
Usage:
Results:

As you can see, it supports pretty individual houses as well as houses stacked next to each other
Go easy on me, this is like my 2nd script for simba D:
function getPolarAngle(o,pt : TPoint) : Extended;
begin
Result := ArcTan2(o.y - pt.y, o.x - pt.x) * 180 / Pi;
end;
function inArray(search : Integer; arr : array of Integer) : Integer;
var
I : Integer;
begin
for I := 0 to High(arr) do
begin
if arr[I] = search then
begin
Result := I;
Exit;
end
end;
Result := -1;
end;
function FindHouseBounds(col,tol : Integer) : TPointArray;
var
tpa,walltpa,players : TPointArray;
atpa : Array of TPointArray;
tmp, foundIndex, I : Integer;
dist1,dist2 : Extended;
MMCTP : TPoint;
degArray : Array of Integer;
knownDegrees : Array[0..360] of Integer;
begin
SetArrayLength(walltpa,1);
SetArrayLength(degArray,1);
writeln(inttostr(Length(walltpa)));
MMCTP := Point( MMCX,MMCY );
players := GetMiniMapDots('p'); //Remove if you don't want to create player filtering.
FindColorsTolerance(tpa,col,MMX1,MMY1,MMX2,MMY2,tol);
SortTPAFrom(tpa,MMCTP);
for I := 0 to High(tpa) do
begin
tmp := floor(getPolarAngle(MMCTP,tpa[I]) / 5); // decrease 5 if splittpawrap isn't capturing bounds properly
foundIndex := inArray(tmp,degArray);
if foundIndex = -1 then
begin
walltpa[Length(walltpa) - 1] := tpa[I];
degArray[Length(degArray) - 1] := tmp;
SetArrayLength(walltpa,GetArrayLength(walltpa) + 1);
SetArrayLength(degArray,GetArrayLength(degArray) + 1);
end else
begin
dist1 := DistBetween(MMCTP,walltpa[foundIndex]);
dist2 := DistBetween(MMCTP,tpa[I]);
if dist2 < dist1 then
walltpa[foundIndex] := tpa[I];
end
end;
writeln(degArray);
SplitTPAWrap(walltpa,5,atpa);
DebugATPABounds(atpa);
Result := walltpa;
end;Usage:
FindHouseBounds(16118766,25); Results:

As you can see, it supports pretty individual houses as well as houses stacked next to each other
Go easy on me, this is like my 2nd script for simba D: