SA-MP Forums Archive
GetPlayerDistanceFromPoint in 0.3c RC3? - 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)
+--- Thread: GetPlayerDistanceFromPoint in 0.3c RC3? (/showthread.php?tid=294490)



GetPlayerDistanceFromPoint in 0.3c RC3? - Jack_Leslie - 01.11.2011

How do I use GetPlayerDistanceFromPoint in RC3? Apart from using RC4/5....


Re: GetPlayerDistanceFromPoint in 0.3c RC3? - ikkentim - 01.11.2011

Maths: http://en.wikipedia.org/wiki/Sinus


Re: GetPlayerDistanceFromPoint in 0.3c RC3? - Jack_Leslie - 01.11.2011

Quote:
Originally Posted by ikkentim
Посмотреть сообщение
Get out. http://en.wikipedia.org/Wiki/Lean2Help


Re: GetPlayerDistanceFromPoint in 0.3c RC3? - ikkentim - 01.11.2011

Really, maths is the only way, unfortunately, i am not verry good at maths


Re: GetPlayerDistanceFromPoint in 0.3c RC3? - Jack_Leslie - 01.11.2011

Quote:
Originally Posted by ikkentim
Посмотреть сообщение
Really, maths is the only way, unfortunately, i am not verry good at maths
I asked how I would use the function in RC3, not how I would make the function.


Re: GetPlayerDistanceFromPoint in 0.3c RC3? - ikkentim - 01.11.2011

pawn Код:
stock Float:GetPlayerDistanceFromPoint(playerid, Float:X, Float:Y, Float:Z)
{
   new Float:pPos[3];
   GetPlayerPos(playerid);
   return floatsqroot(floatpower(floatsub(X, pPos[0]), 2.0) + floatpower(floatsub(Y, pPos[1]), 2.0) + floatpower(floatsub(Z, pPos[2]), 2.0));
}
Is that what you mean?


Re: GetPlayerDistanceFromPoint in 0.3c RC3? - Sascha - 01.11.2011

lol depends on how you define it..
if you do it like this:
pawn Код:
stock GetPlayerDistanceFromPoint(playerid, Float:x, Float:y, Float:z)
stock GetPlayerDistanceFromPoint(playerid, Float:x, Float:y, Float:z)
{
    if(IsPlayerConnected(playerid))
    {
        new Float:rst, Float:Coords[3];
        GetPlayerPos(playerid, Coords[0], Coords[1], Coords[2]);
        Coords[0] = floatabs(Coords[0]) - x;
        Coords[1] = floatabs(Coords[1]) - y;
        Coords[2] = floatabs(Coords[2]) - z;
        rst = floatsqroot((Coords[0] * Coords[0]) + (Coords[1] * Coords[1]) + (Coords[2] * Coords[2]));
        return rst;
    }
    return 0;
}
(not sure if this function is correct, just wrote it for this purpose)

Then you need to use it in code like this:
pawn Код:
new Float:distance = GetPlayerDistanceFromPoint(playerid, Xcoord, Ycoord, Zcoord);



Re: GetPlayerDistanceFromPoint in 0.3c RC3? - Jack_Leslie - 02.11.2011

Quote:
Originally Posted by ikkentim
Посмотреть сообщение
pawn Код:
stock Float:GetPlayerDistanceFromPoint(playerid, Float:X, Float:Y, Float:Z)
{
   new Float:pPos[3];
   GetPlayerPos(playerid);
   return floatsqroot(floatpower(floatsub(X, pPos[0]), 2.0) + floatpower(floatsub(Y, pPos[1]), 2.0) + floatpower(floatsub(Z, pPos[2]), 2.0));
}
Is that what you mean?
That is what I mean, thank you!

Sascha, your code has a tag mismatch on the return.


Re: GetPlayerDistanceFromPoint in 0.3c RC3? - Joe Staff - 02.11.2011

He forgot to fill in GetPlayerPos. Please read code before copying it.