Distance and xyintrontofplayer - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Distance and xyintrontofplayer (
/showthread.php?tid=118604)
Distance and xyintrontofplayer -
boelie - 04.01.2010
Hello and Happy New Year!
I have a question about what i made here;
Im checking the xyinfront of a player and if an npc is standing there but now i want the player to check how far the distance is between the npc(other player).
I tried changing the inrangeofpoint part but that made the xyinfrontofme go mad

So wich values doe i need to change and how?
Heres what i did;
Code:
new giveid[MAX_PLAYERS];
forward OnplayerCheckNPC(playerid);
Code:
stock GetXYInFrontOfPlayer(playerid, &Float:x, &Float:y, Float:distance)
{
new Float:a;
GetPlayerPos(playerid, x, y, a);
GetPlayerFacingAngle(playerid, a);
x += (distance * floatsin(-a, degrees));
y += (distance * floatcos(-a, degrees));
}
Code:
public OnplayerCheckNPC(playerid)
{
new Float:X, Float:Y, FLoat:Z;
GetPlayerPos(playerid,X,Y,Z);
GetXYInFrontOfPlayer(playerid, X, Y, 5.0);
for(new i = 0; i < MAX_PLAYERS; i++)
if(IsPlayerInRangeOfPoint(i, 5.0, X,Y,Z))
{
new keys, updown, leftright;
GetPlayerKeys(playerid, keys, updown, leftright);
if ((keys & 4) && (keys & 128))
{
if (IsPlayerNPC(i))
{
SendClientMessageToSkin(68, 0x00FF4096, "you are in front of me");
}
}
}
}