[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
#2

If you can get this more accurate, nearly exact.... it may be extremely useful. Nice work.
Reply
#3

Quote:
Originally Posted by Awaran[Enemy-Plus
; ]
If you can get this more accurate, nearly exact.... it may be extremely useful. Nice work.
I'm working on it .
Reply
#4

This should really be in that:
http://forum.sa-mp.com/index.php?topic=12197.0

But it's a nice script, good job .
Reply
#5

Quote:
Originally Posted by [HiC
TheKiller ]
This should really be in that:
http://forum.sa-mp.com/index.php?topic=12197.0

But it's a nice script, good job .
My appologies! It's been a while since I've released anything to the community. I'm sure if it's a nescessity that it be placed there, an admin will be in touch .
Reply
#6

V.Nice puffles
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)