Scripting/Squirrel/Functions/InPoly: Difference between revisions

From Vice City Multiplayer
Jump to navigation Jump to search
Caution icon
This wiki is using an old backup from 2020
Some information may be old/missing
No edit summary
No edit summary
Line 65: Line 65:
     return InPoly(x, y, points);
     return InPoly(x, y, points);
}
}
== Related Functions ==
{{Scripting/Squirrel/Functions/Game Functions}}

Revision as of 16:12, 23 April 2016

InPoly tests if a point lies within a polygon consisting of at least three and up to 128 points. If the given point is inside the polygon, the function returns true. If not, it returns false. If the points given do not form a valid polygon, the function throws an error.

This function only uses two-dimensional space. Passing z-coordinates will return undesired output.

Syntax

Type 1

InPoly(testX, testY, x1, y1, x2, y2, x3, y3, ...)

Arguments

  • float testX - the X-coordinate for the test point
  • float testY - the Y-coordinate for the test point
  • float x1, y1, ... - the coordinates of the points of the polygon

Type 2

InPoly(testX, testY, [x1, y1, x2, y2, x3, y3, ...])

Arguments

  • float testX - the X-coordinate for the test point
  • float testY - the Y-coordinate for the test point
  • array [x1, y1, ...] - an array of coordinates for the points of the polygon, similar to Type 1

Type 3

InPoly(testX, testY, "x1, y1, x2, y2, x3, y3")

Arguments

  • float testX - the X-coordinate for the test point
  • float testY - the Y-coordinate for the test point
  • string "x1, y1, ..." - a string of comma-separated coordinates for the points of the polygon. Passing non-numeric values for the coordinates will not fail, but will produce garbage output.

Example

The following snippets will all test if a player is around the police station in Downtown Vice City.

function IsPlayerNearStation(player) {
    local x = player.Pos.x;
    local y = player.Pos.y;

    return InPoly(x, y, -676.405, 742.559, -674.1, 829.714, -586.714, 832.304, -587.028, 743.311);
}
function IsPlayerNearStation(player) {
    local x = player.Pos.x;
    local y = player.Pos.y;
    local points = [-676.405, 742.559, -674.1, 829.714, -586.714, 832.304, -587.028, 743.311];

    return InPoly(x, y, points);
}

<source lang=squirrel> function IsPlayerNearStation(player) {

   local x = player.Pos.x;
   local y = player.Pos.y;
   local points = "-676.405, 742.559, -674.1, 829.714, -586.714, 832.304, -587.028, 743.311";
   return InPoly(x, y, points);

}

Related Functions