27.05.2013, 14:11
pawn Код:
stock SetPlayerLookAt(playerid, Float:x, Float:y)
{
new Float:Px, Float:Py, Float: Pa;
if(IsPlayerInAnyVehicle(playerid)) GetVehiclePos(GetPlayerVehicleID(playerid), Px, Py, Pa);
else GetPlayerPos(playerid, Px, Py, Pa);
Pa = floatabs(atan((y-Py)/(x-Px)));
if(x <= Px && y >= Py) Pa = floatsub(180, Pa);
else if(x < Px && y < Py) Pa = floatadd(Pa, 180);
else if(x >= Px && y <= Py) Pa = floatsub(360.0, Pa);
Pa = floatsub(Pa, 90.0);
if(Pa >= 360.0) Pa = floatsub(Pa, 360.0);
if(!IsPlayerInAnyVehicle(playerid)) SetPlayerFacingAngle(playerid, Pa);
else SetVehicleZAngle(GetPlayerVehicleID(playerid), Pa);
}
If you don't want the function to actually set the players' angle, you could just make it return 'Pa' instead (and remember to add a Float: tag to the function).