Audiophr3ak

25/02/2013, 08:22 AM

Im trying to find out the most efficient way to detect angles correlation bewteen two players. For example we have 4 sides for our player (FRONT, BACK, LEFT, RIGHT) and we got another player attacking him with his own angle. So the task is to detect from which side our first player is beign attacked. Any ideas?

http://img834.imageshack.us/img834/8852/schemer.jpg

Variant 1:

public OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid)

{

if(issuerid != INVALID_PLAYER_ID)

{

new Float:pangle; GetPlayerFacingAngle(playerid, pangle);

new Float:iangle; GetPlayerFacingAngle(issuerid, iangle);

if(((pangle + 225) >= (iangle + 225)) && ((pangle - 225) <= (iangle - 225))) SendClientMessage(playerid, 0xFFFFFFAA, "FRONT");

if(((pangle + 45) >= (iangle + 45)) && ((pangle - 45) <= (iangle - 45))) SendClientMessage(playerid, 0xFFFFFFAA, "BACK");

if(((pangle + 135) >= (iangle + 135)) && ((pangle - 135) <= (iangle - 135))) SendClientMessage(playerid, 0xFFFFFFAA, "LEFT");

if(((pangle + 315) >= (iangle + 315)) && ((pangle - 315) <= (iangle - 315))) SendClientMessage(playerid, 0xFFFFFFAA, "RIGHT");

}

return 1;

}

Variant 2:

public OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid)

{

if(issuerid != INVALID_PLAYER_ID)

{

new Float:pangle; GetPlayerFacingAngle(playerid, pangle);

new Float:iangle; GetPlayerFacingAngle(issuerid, iangle);

new Float:result = pangle - iangle;

if(result >= 315 && result <= 45) SendClientMessage(playerid, 0xFFFFFFAA, "BACK");

else if(result >= 45 && result <= 135) SendClientMessage(playerid, 0xFFFFFFAA, "LEFT");

else if(result >= 135 && result <= 225) SendClientMessage(playerid, 0xFFFFFFAA, "FRONT");

else if(result >= 225 && result <= 315) SendClientMessage(playerid, 0xFFFFFFAA, "RIGHT");

}

return 1;

}

http://img834.imageshack.us/img834/8852/schemer.jpg

Variant 1:

public OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid)

{

if(issuerid != INVALID_PLAYER_ID)

{

new Float:pangle; GetPlayerFacingAngle(playerid, pangle);

new Float:iangle; GetPlayerFacingAngle(issuerid, iangle);

if(((pangle + 225) >= (iangle + 225)) && ((pangle - 225) <= (iangle - 225))) SendClientMessage(playerid, 0xFFFFFFAA, "FRONT");

if(((pangle + 45) >= (iangle + 45)) && ((pangle - 45) <= (iangle - 45))) SendClientMessage(playerid, 0xFFFFFFAA, "BACK");

if(((pangle + 135) >= (iangle + 135)) && ((pangle - 135) <= (iangle - 135))) SendClientMessage(playerid, 0xFFFFFFAA, "LEFT");

if(((pangle + 315) >= (iangle + 315)) && ((pangle - 315) <= (iangle - 315))) SendClientMessage(playerid, 0xFFFFFFAA, "RIGHT");

}

return 1;

}

Variant 2:

public OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid)

{

if(issuerid != INVALID_PLAYER_ID)

{

new Float:pangle; GetPlayerFacingAngle(playerid, pangle);

new Float:iangle; GetPlayerFacingAngle(issuerid, iangle);

new Float:result = pangle - iangle;

if(result >= 315 && result <= 45) SendClientMessage(playerid, 0xFFFFFFAA, "BACK");

else if(result >= 45 && result <= 135) SendClientMessage(playerid, 0xFFFFFFAA, "LEFT");

else if(result >= 135 && result <= 225) SendClientMessage(playerid, 0xFFFFFFAA, "FRONT");

else if(result >= 225 && result <= 315) SendClientMessage(playerid, 0xFFFFFFAA, "RIGHT");

}

return 1;

}