12.06.2014, 04:13
This function casts a ray between two points in the world, and tells you information about the point that was hit, if any.
Example:
Additional features:
native IsValidVehicle(vehicleid);
plugin MapAndreas: https://sampforum.blast.hk/showthread.php?tid=275492
Preview:
by Seregamil
PHP код:
processLineOfSight(
//start
Float: start_x,
Float: start_y,
Float: start_z,
//finish
&Float: end_x,
&Float: end_y,
&Float: end_z,
bool: check_vehicles,
bool: check_players )
PHP код:
forward processLineOfSight( Float: start_x, Float: start_y, Float: start_z, &Float: end_x, &Float: end_y, &Float: end_z, bool: check_vehicles, bool: check_players );
public processLineOfSight( Float: start_x, Float: start_y, Float: start_z, &Float: end_x, &Float: end_y, &Float: end_z, bool: check_vehicles, bool: check_players ){//by Seregamil
new distance_between_points = floatround( VectorSize( end_x - start_x, end_y - start_y, end_z - start_z ) );
if( distance_between_points == 0 )
return ;
new Float: pack_pos_x = floatdiv( end_x - start_x, float( distance_between_points ) ),
Float: pack_pos_y = floatdiv( end_y - start_y, float( distance_between_points ) ),
Float: pack_pos_z = floatdiv( end_z - start_z, float( distance_between_points ) ),
Float: map_z = 0.0,
j = -1, Float: pos_x, Float: pos_y, Float: pos_z , i = 0;
do{
start_x += pack_pos_x;
start_y += pack_pos_y;
start_z += pack_pos_z;
if( check_vehicles ){
for( i = 0; i != MAX_VEHICLES; i++ ){
if( !IsValidVehicle( i ) ) continue;
GetVehiclePos( i, pos_x, pos_y, pos_z );
if( VectorSize( pos_x - start_x, pos_y - start_y, pos_z - start_z ) > 3.0 ) continue;
end_x = start_x;
end_y = start_y;
end_z = start_z;
return ;
}
}
if( check_players ){
for( i = GetMaxPlayers() - 1; i != -1; i-- ){
if( IsPlayerNPC( i ) || !IsPlayerConnected( i ) ) continue;
GetPlayerPos( i, pos_x, pos_y, pos_z );
if( !IsPlayerInRangeOfPoint( i , 3.0, pos_x, pos_y, pos_z ) ) continue;
end_x = start_x;
end_y = start_y;
end_z = start_z;
return ;
}
}
MapAndreas_FindZ_For2DCoord( start_x, start_y, map_z );
if( map_z < start_z )
continue;
end_x = start_x;
end_y = start_y;
end_z = start_z;
break;
}
while( ++j < distance_between_points );
}
PHP код:
new Float:x = 0.0, Float:y = 0.0, Float:z = 0.0, Object = CreateObject( 2000, -10.4548,55.2839,12.1676, 0.0, 0.0, 0.0 );
processLineOfSight( -10.4548,55.2839,12.1676, x,y,z, false, true );
MoveObject(Object, x,y,z,3.0);
native IsValidVehicle(vehicleid);
plugin MapAndreas: https://sampforum.blast.hk/showthread.php?tid=275492
Preview:
by Seregamil