I got something to work, but now when its rotated it should stop the loop. but now when its finisht whit rotating it first rotating right than left and it goes on like that...
int X = dbObjectPositionX(NPC);
int Z = dbObjectPositionZ(NPC);
int TX = dbObjectPositionX(Target);
int TZ = dbObjectPositionZ(Target);
int Angle = dbAtanFull( TX-X, Z-TZ );
if(Angle == 90) { Angle = -90; }
if(Angle > 90) { Angle = Angle - 90; }
while(dbObjectAngleY(NPC) != Angle)
{
int l = dbObjectAngleY(NPC) ;
if(dbObjectAngleY(NPC) < Angle)
{
dbTurnObjectRight(NPC,1);
}
else if(dbObjectAngleY(NPC) > Angle)
{
dbTurnObjectLeft(NPC,1);
}
dbSync();
}