//------------------------------------------wikithing wich i want to use because im learning! XD GetXYInFrontOfMe(Float:x, &Float:y, Float:distance) { new Float:z,Float:a; GetMyPos( x, y, z); GetMyFacingAngle(a); x += (distance * floatsin(-a, degrees)); y += (distance * floatcos(-a, degrees)); } //------------------------------------------ public OnNPCCheckplayer() { new Float:x, Float:y ; GetXYInFrontOfMe(x, y, 5.0); for(new i = 0; i < MAX_PLAYERS; i++) if(IsPlayerInRangeOfPoint(i, 5.0, x,y,5.0)) { SendChat("I 'see' a player is in front of me ."); } }
#define RECORDING "npc15" #define RECORDING_TYPE 2 #include <a_npc> main(){} public OnRecordingPlaybackEnd() StartRecordingPlayback(RECORDING_TYPE, RECORDING); public OnNPCEnterVehicle(vehicleid, seatid) StartRecordingPlayback(RECORDING_TYPE, RECORDING); public OnNPCExitVehicle() StopRecordingPlayback(); forward OnNPCCheckplayer(); public OnNPCSpawn() { StartRecordingPlayback(RECORDING_TYPE, RECORDING); SetTimer("OnNPCCheckplayer",5000,1); return 1; } //------------------------------------------ stock GetXYInFrontOfMe(Float:x, &Float:y, Float:distance) { new Float:z,Float:a; GetMyPos( x, y, z); GetMyFacingAngle(a); x += (distance * floatsin(-a, degrees)); y += (distance * floatcos(-a, degrees)); } //------------------------------------------ public OnNPCCheckplayer() { new Float:x, Float:y ; GetXYInFrontOfMe(x, y, 5.0); for(new i = 0; i < MAX_PLAYERS; i++) if(IsPlayerInRangeOfPoint(i, 5.0, x,y,5.0)) { SendChat("I 'see' a player is in front of me !."); } }
so just GetMyPos and IsPlayerInRangeOfPoint ? |
(opposite) (d) = position infront of player (p) = player
(d)____________ To get XY infront of player, you need player's position, player's facing angle and the distance you want infront of player.
\ | Lets make ourselves a random values:
\ | - distance(hypotenuse) = 20.0 feet
\ | - player's facing angle = 30.0 degrees
\ |
(hypotenuse) \ | (adjacent) opposite = sine 30.0 * 20.0 (try with your calculator)
\ | adjacent = cosine 30.0 * 20.0
\ |
\ | 20.0 * floatsin(-30.0, degrees) = 10.0 feet (opposite) //floatsin(Float:value, anglemode) in this case anglemode is degrees
\ | 20.0 * floatcos(-30.0, degrees) = 17.3 feet (adjacent) //-30.0 because SA-MP has angles inverted
\ |
\ | Add opposite to player's X position and adjacent to Y position.
\| X += opposite Y+= adjacent
(p) The function returns a new X and a new Y floatvalues.
#define RECORDING "npc15"
#define RECORDING_TYPE 2
#include <a_npc>
main(){}
public OnRecordingPlaybackEnd() StartRecordingPlayback(RECORDING_TYPE, RECORDING);
public OnNPCEnterVehicle(vehicleid, seatid) StartRecordingPlayback(RECORDING_TYPE, RECORDING);
public OnNPCExitVehicle() StopRecordingPlayback();
forward OnNPCCheckplayer();
public OnNPCSpawn()
{
StartRecordingPlayback(RECORDING_TYPE, RECORDING);
SetTimer("OnNPCCheckplayer",5000,1);
return 1;
}
//------------------------------------------
stock GetXYInFrontOfMe(&Float:x, &Float:y, Float:distance)
{
new Float:z,Float:a;
GetMyPos( x, y, z);
GetMyFacingAngle(a);
x += (distance * floatsin(-a, degrees));
y += (distance * floatcos(-a, degrees));
}
//------------------------------------------
public OnNPCCheckplayer()
{
new Float:x, Float:y,Float:unusedx,Float:unusedy,Float:tempz;
GetMyPos(unusedx,unusedy,tempz);
GetXYInFrontOfMe(x, y, 5.0);
for(new i = 0; i < MAX_PLAYERS; i++){
if(IsPlayerConnected(i) && IsPlayerInRangeOfPoint(i, 5.0, x,y,tempz))
{
SendChat("I 'see' a player is in front of me !.");
}
}
}