[Function] GetPlayerDirectionFromPlayer -
Puffmac - 28.12.2009
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.
Re: [Function] GetPlayerDirectionFromPlayer -
pagie1111 - 28.12.2009
If you can get this more accurate, nearly exact.... it may be extremely useful. Nice work.
Re: [Function] GetPlayerDirectionFromPlayer -
Puffmac - 28.12.2009
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
.
Re: [Function] GetPlayerDirectionFromPlayer -
[HiC]TheKiller - 28.12.2009
This should really be in that:
http://forum.sa-mp.com/index.php?topic=12197.0
But it's a nice script, good job
.
Re: [Function] GetPlayerDirectionFromPlayer -
Puffmac - 28.12.2009
Quote:
Originally Posted by [HiC
|
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
.
Re: [Function] GetPlayerDirectionFromPlayer -
BMUK - 08.01.2010
V.Nice puffles