28.12.2009, 02:15
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
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.
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;
}
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.