[Function] GetPlayerDirectionFromPlayer
#1

Introduction
Hello,

This function returns the rough direction of a player, relative you your position. It utilises the four cardinal directions (North, South, East and West), and the four intermediate directions (North East, North West, South East, South West).

It's not the most efficient code ever, and I will probably end up revising it, but I just wanted to get it finished for my server and rushed it .

Tested in 0.3

Source
pawn Code:
stock GetPlayerDirectionFromPlayer(playerid,targetid)
{
    new
        Float:tpX,
        Float:tpY,
        Float:tpZ,
        Float:tpX2,
        Float:tpY2,
        Float:tpZ2,
        Float:pX,
        Float:pY,
        Float:pX2,
        Float:pY2,
        tDir[20];

    GetPlayerPos(playerid,tpX,tpY,tpZ);
    GetPlayerPos(targetid,tpX2,tpY2,tpZ2);

    pX = floatround(tpX,floatround_round);
    pY = floatround(tpY,floatround_round);
    pX2 = floatround(tpX2,floatround_round);
    pY2 = floatround(tpY2,floatround_round);

    if((pX2 < pX) && (pY2 < pY))
        tDir = "South West";
    else if((pX2 > pX) && (pY2 > pY))
        tDir = "North East";
    else if((pX2 < pX) && (pY2 > pY))
        tDir = "North West";
    else if((pX2 > pX) && (pY2 < pY))
        tDir = "South East";
    else if((pX2 == pX) && (pY2 > pY))
        tDir = "North";
    else if((pX2 == pX) && (pY2 < pY))
        tDir = "South";
    else if((pY2 == pY) && (pX2 < pX))
        tDir = "West";
    else
        tDir = "East";

    return tDir;
}
Updates
I'll post an example command sometime tomorrow, if someone on this forum doesn't do so before me, in order to fully show the potential of this function.

Enjoy & Comment!

Puffmac.
Reply


Messages In This Thread
[Function] GetPlayerDirectionFromPlayer - by Puffmac - 28.12.2009, 02:15
Re: [Function] GetPlayerDirectionFromPlayer - by pagie1111 - 28.12.2009, 02:17
Re: [Function] GetPlayerDirectionFromPlayer - by Puffmac - 28.12.2009, 02:18
Re: [Function] GetPlayerDirectionFromPlayer - by [HiC]TheKiller - 28.12.2009, 02:24
Re: [Function] GetPlayerDirectionFromPlayer - by Puffmac - 28.12.2009, 02:26
Re: [Function] GetPlayerDirectionFromPlayer - by BMUK - 08.01.2010, 21:41

Forum Jump:


Users browsing this thread: 1 Guest(s)