All pastes #208161 Raw Edit

IsPlayerInAreaEx

public text v1 · immutable
#208161 ·published 2006-10-18 13:17 UTC
rendered paste body
IsPlayerInAreaEx(playerid, Float:...)
{
	new count = numargs();
	if (count < 7 || (count % 2) == 0) return 0; // Check parameters
	// You need at least 3 points for an area and an odd number to check
	new lines;
	new Float:x, Float:y, Float:z;
	new Float:x1, Float:x2, Float:y1, Float:y2;
	GetPlayerPos(playerid, x, y, z);
	new i = 0;
	while (i < count)
	{
		x1 = Float:getarg(++i);
		y1 = Float:getarg(++i);
		if (i + 1 < count)
		{
			x2 = Float:getarg(i + 1);
			y2 = Float:getarg(i + 2);
		}
		else
		{
			x2 = Float:getarg(1);
			y2 = Float:getarg(2);
		}
		if (((y >= y1 && y <= y2) || (y >= y2 && y <= y1))
			&& (x1 + ((y - y1) * (x2 - x1) / (y2 - y1))) < x)
				lines++;
	}
	if (lines % 2 == 1)
		return 1;
	return 0;
}