All pastes #284170 Raw Edit

Something

public c v1 · immutable
#284170 ·published 2006-12-18 22:25 UTC
rendered paste body
GetAngleFromDiffSet(var xDiff, var yDiff){	var theNewAngle = atan(abs(xDiff)/abs(yDiff));	if (theNewAngle < 0)	{		theNewAngle = abs(theNewAngle);	}		if (theNewAngle > MATH_TWOPI)		theNewAngle -= MATH_TWOPI;	if (theNewAngle > MATH_PI)		theNewAngle -= MATH_PI;	if (theNewAngle > (MATH_PI / 2))		theNewAngle -= (MATH_PI / 2);		if ((xDiff < 0) && (yDiff < 0))		return theNewAngle;	if ((xDiff < 0) && (yDiff > 0))		return MATH_PI + (-1 * theNewAngle);	if ((xDiff > 0) && (yDiff > 0))		return MATH_PI + theNewAngle;	if ((xDiff > 0) && (yDiff < 0))		return MATH_TWOPI + (-1 * theNewAngle);	return 0.0;}MovePlayerTo(var xPos, var yPos){	var currentX = GetPlayerLocationX();	var currentY = GetPlayerLocationY();	var diffX = currentX - xPos;	var diffY = currentY - yPos;		var theNewAngle = GetAngleFromDiffSet(diffX,diffY);	DebugWrite("New Angle: ");	DebugWriteLine(theNewAngle);		var angleDiff = GetPlayerLocationDirection() - theNewAngle;	DebugWrite("Angle Diff: ");	DebugWriteLine(angleDiff);		while (abs(angleDiff) > (MATH_TWOPI / 32))	{		angleDiff = GetPlayerLocationDirection() - theNewAngle;		DebugWrite("Angle Diff: ");		DebugWriteLine(angleDiff);		if (angleDiff < 0)		{			if (abs(angleDiff) < MATH_PI)			{				KeyDown(vkKey_TurnRight);				KeyUp(vkKey_TurnLeft);			} else {				KeyDown(vkKey_TurnLeft);				KeyUp(vkKey_TurnRight);			}		}		else		{			if (abs(angleDiff) < MATH_PI)			{				KeyDown(vkKey_TurnLeft);				KeyUp(vkKey_TurnRight);			} else {				KeyDown(vkKey_TurnRight);				KeyUp(vkKey_TurnLeft);			}		}				Delay(RandRange(43,92));		angleDiff = GetPlayerLocationDirection() - theNewAngle;	}	KeyUp(vkKey_TurnRight);	KeyUp(vkKey_TurnLeft);		KeyDown(vkKey_Forward);	while((abs(xPos - GetPlayerLocationX()) > 0.50) || (abs(yPos - GetPlayerLocationY()) > 0.50))	{		if ((!PlayerIsWalking) && (sqrt(((xPos - GetPlayerLocationX()) * (xPos - GetPlayerLocationX())) + ((yPos - GetPlayerLocationY()) * (yPos - GetPlayerLocationY()))) < 5.0))		{			KeyUp(vkKey_TurnRight);			KeyUp(vkKey_TurnLeft);			KeyClick(vkKey_RunWalk,DefaultKeyClickTime);			PlayerIsWalking = true;		}		theNewAngle = GetAngleFromDiffSet((GetPlayerLocationX() - xPos),(GetPlayerLocationY() - yPos));		DebugWrite("New Angle: ");		DebugWriteLine(theNewAngle);				angleDiff = GetPlayerLocationDirection() - theNewAngle;		DebugWrite("Angle Diff: ");		DebugWriteLine(angleDiff);				if (angleDiff < 0)		{			if (abs(angleDiff) < MATH_PI)			{				KeyDown(vkKey_TurnRight);				KeyUp(vkKey_TurnLeft);			} else {				KeyDown(vkKey_TurnLeft);				KeyUp(vkKey_TurnRight);			}		}		else		{			if (abs(angleDiff) < MATH_PI)			{				KeyDown(vkKey_TurnLeft);				KeyUp(vkKey_TurnRight);			} else {				KeyDown(vkKey_TurnRight);				KeyUp(vkKey_TurnLeft);			}		}			}	KeyUp(vkKey_Forward);	KeyUp(vkKey_TurnRight);	KeyUp(vkKey_TurnLeft);	if (PlayerIsWalking)	{		KeyClick(vkKey_RunWalk,DefaultKeyClickTime);		PlayerIsWalking = false;	}}