Code:
stock SetPlayerLookAtPos(playerid, Float:pos_x, Float:pos_y)
{
? ? new
? ? Float:w_px,
? ? Float:w_py,
? ? Float: angle;
? ? GetPlayerPos(playerid, w_px, w_py, angle);
? ? angle = floatabs(atan((pos_y-w_py)/(pos_x-w_px)));
? ? if (pos_x <= w_px && pos_y >= w_py)
? ? angle = floatsub(180.0, angle);
? ? else if (pos_x < w_px && pos_y < w_py)
? ? angle = floatadd(angle, 180.0);
? ? else if (pos_x >= w_px && pos_y <= w_py)
? ? angle = floatsub(360.0, angle);
? ?
? ? angle = floatsub(angle, 90.0);
? ? if (angle >= 360.0)//Prevent angle more than at 360?
? ? angle = floatsub(angle, 360.0);
? ?
? ? SetPlayerFacingAngle(playerid, angle);
? ? return 1;
}
stock GetPlayerAngleAtPos(playerid, Float:pos_x, Float:pos_y)
{
? ? new
? ? Float:w_px,
? ? Float:w_py,
? ? Float: angle;
? ? GetPlayerPos(playerid, w_px, w_py, angle);
? ? angle = floatabs(atan((pos_y-w_y)/(pos_x-w_px)));
? ? if (pos_x <= w_px && pos_y >= w_py)
? ? angle = floatsub(180.0, angle);
? ? else if (pos_x < w_px && pos_y < w_py)
? ? angle = floatadd(angle, 180.0);
? ? else if (pos_x >= w_px && pos_y <= w_py)
? ? angle = floatsub(360.0, angle);
? ?
? ? angle = floatsub(angle, 90.0);
? ? if (angle >= 360.0)//Prevent angle more than at 360?
? ? angle = floatsub(angle, 360.0);
? ?
? ? return angle;
}
stock SetPlayerLookAtObject(playerid, objectid)
{
if(!IsPlayerConnected(playerid))
return 0;
? ? new
? ? Float:w_px,
? ? Float:w_py,
? ? Float:w_ox,
? ? Float:w_oy,
? ? Float:w_oz,
? ? Float: angle;
? ? GetPlayerPos(playerid, w_px, w_py, angle);
? ? GetObjectPos(objectid, w_ox, w_oy, w_oz);
? ? angle = floatabs(atan((w_oy-w_py)/(w_ox-w_px)));
? ? if (w_ox <= w_px && w_oy >= w_py)
? ? angle = floatsub(180.0, angle);
? ? else if (w_ox < w_px && w_oy < w_py)
? ? angle = floatadd(angle, 180.0);
? ? else if (w_ox >= w_px && w_oy <= w_py)
? ? angle = floatsub(360.0, angle);
? ?
? ? angle = floatsub(angle, 90.0);
? ? if (angle >= 360.0)//Prevent angle more than at 360?
? ? angle = floatsub(angle, 360.0);
? ?
? ? SetPlayerFacingAngle(playerid, angle);
? ? return 1;
}
stock GetPlayerAngleAtObject(playerid, objectid)
{
if(!IsPlayerConnected(playerid))
return 0;
? ? new
? ? Float:w_px,
? ? Float:w_py,
? ? Float:w_ox,
? ? Float:w_oy,
? ? Float:w_oz,
? ? Float: angle;
? ? GetPlayerPos(playerid, w_px, w_py, angle);
? ? GetObjectPos(objectid, w_ox, w_oy, w_oz);
? ? angle = floatabs(atan((w_oy-w_py)/(w_ox-w_px)));
? ? if (w_ox <= w_px && w_oy >= w_py)
? ? angle = floatsub(180.0, angle);
? ? else if (w_ox < w_px && w_oy < w_py)
? ? angle = floatadd(angle, 180.0);
? ? else if (w_ox >= w_px && w_oy <= w_py)
? ? angle = floatsub(360.0, angle);
? ?
? ? angle = floatsub(angle, 90.0);
? ? if (angle >= 360.0)//Prevent angle more than at 360?
? ? angle = floatsub(angle, 360.0);
? ?
? ? return angle;
}
stock GetPlayerAngleAtObject(playerid, objectid)
{
if(!IsPlayerConnected(playerid))
return 0;
? ? new
? ? Float:w_px,
? ? Float:w_py,
? ? Float:w_ox,
? ? Float:w_oy,
? ? Float:w_oz,
? ? Float: angle;
? ? GetPlayerPos(playerid, w_px, w_py, angle);
? ? GetDynamicObjectPos(objectid, w_ox, w_oy, w_oz);
? ? angle = floatabs(atan((w_oy-w_py)/(w_ox-w_px)));
? ? if (w_ox <= w_px && w_oy >= w_py)
? ? angle = floatsub(180.0, angle);
? ? else if (w_ox < w_px && w_oy < w_py)
? ? angle = floatadd(angle, 180.0);
? ? else if (w_ox >= w_px && w_oy <= w_py)
? ? angle = floatsub(360.0, angle);
? ?
? ? angle = floatsub(angle, 90.0);
? ? if (angle >= 360.0)//Prevent angle more than at 360?
? ? angle = floatsub(angle, 360.0);
? ?
? ? return angle;
}