Да,знаю, есть функция от пользователя RyDeR`, но проблема в том, что она, лично у меня, корректно не работает.
Ссылка на тему: http://forum.sa-mp.com/showthread.ph...on#post1154971
Я просто её переписал под рабочий вариант и изменил параметры функции, ибо на мой взгляд удобнее в параметрах указать массив с координатами, нежели их записывать в функцию.
Значение MAX_POLYGON_POINTS меняйте в том случае, если количество точек полигона больше, чем 32.
Пример использования:PHP код:
stock IsPointInPolygon( Float: pointX, Float: pointY, Float: polygon[], totalPoints = sizeof( polygon ) ){
#define MAX_POLYGON_POINTS (32) // empty statement with 'polygonSize' =_=
new
polygonSize = ( totalPoints / 2 ), // get polygon size
Float: points[ MAX_POLYGON_POINTS ][ 2 ], // x and y
i = 0,
j = 0,
result = false
;
#undef MAX_POLYGON_POINTS
for( ; j != polygonSize ; j ++, i++ ) { // add points in array
points[ j ][ 0 ] = polygon[ i ] ; // x
points[ j ][ 1 ] = polygon[ ++i ] ; // y
}
for( i = 0, j -= 1; i < polygonSize; j = i++ ) { // first 'i' and last 'j'
if( ( ( points[ i ][ 1 ] >= pointY ) != ( points[ j ][ 1 ] >= pointY ) ) && ( pointX <= ( points[ j ][ 0 ] - points[ i ][ 0 ] ) * ( pointY - points[ i ][ 1 ] ) / ( points[ j ][ 1 ] - points[ i ][ 1 ] ) + points[ i ][ 0 ] ) )
result = !result; // MEGA OPTIMIZATOR 3500
}
return result ;
}
PHP код:
new Float:country_points_0[] = { // "Los Santos"
3000.0,-3000.0,2996.0,-1040.0,1376.0,-684.0,84.0,-1000.0,100.0,-2996.0,3000.0,-3000.0
};
...
new Float: x, Float: y, Float: z ;
GetPlayerPos( playerid, x, y, z );
if( IsPointInPolygon( x, y, country_points_0 ) ) { // los santos
SendClientMessage( playerid, -1, "Вы в Лос Сантосе." );
}