This has been added to SPS-RS3, so no need to copy into your scripts
A function that checks whether you are inside a polygon. This is more customisable than using a simple pointInBox. The polygon can have 3+ vertices, as demonstrated with the SPS Path Generator:
Just declare your polygon as a TPA, exactly the same way you do when making a SPS path (you can just copy the TPA from the path generator):
Simba Code:
function TSPSArea.isInPolygon(const poly: array of TPoint): boolean;
var
p: TPoint;
i, j: integer;
begin
result := false;
p := self.getPlayerPos();
j := high(poly);
for i := low(poly) to high(poly) do
begin
if ((((poly[i].y <= p.y) and (p.y < poly[j].y)) or ((poly[j].y <= p.y) and
(p.y < poly[i].y)) ) and (p.x < ((poly[j].x - poly[i].x) *
(p.y - poly[i].y) / (poly[j].y - poly[i].y) + poly[i].x))) then
result := not result;
j := i;
end;
end;
Some test code would look something like:
Simba Code:
var
Polygon: array of TPoint;
begin
clearDebug();
setupSRL();
sps.setup('DRAYNOR_01', RUNESCAPE_OTHER);
Polygon := [Point(159, 259), Point(117, 345), Point(224, 346), Point(173, 271)];
repeat
writeLn(sps.isInPolygon(Polygon));
until false;
end.