#loadLibrary 'ZcSysLib' #loadLibrary 'ZcWinLib' #loadLibrary 'ZcMathLb' /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// /////// GoatCheez's Automatic Upgrader Script V 0.1 /////// /////// Tested on USKO - Xigenon /////// /////// Assumes you have enough scrolls and that /////// /////// the scroll stack is in the lower right slot /////// /////// of the inventory. Inventory must be empty /////// /////// except for the stack of scrolls. /////// /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// //set these next two. this script upgrades items from the //armor merchant. ItemPage is the page the item is on, and //ItemToUpgrade is the icon of the item being upgraded. const ItemToUpgrade = "ICON_Armor_Mage_Level2_Pads"; const ItemPage = 2; const usingItemLocation = true; const itemLocationX = 0; const itemLocationY = 2; const MouseClickDelaySpeed1 = 375; const MouseClickDelaySpeed2 = 550; const GeneralDelaySpeed1 = 1000; const DefaultKeyClickTime = 350; const DefaultMouseClickTime = 350; //use this to decide between weapon and armor merchant const usingWeaponMerchant = false; const AnvilWatchStartX = 675; const AnvilWatchStartY = 90; const AnvilInventoryStartX = 668; const AnvilInventoryStartY = 356; const AnvilInventoryWidth = 342; const AnvilInventoryHeight = 202; const SellerInventoryStartX = 685; const SellerInventoryStartY = 356; const SellerInventoryWidth = 330; const SellerInventoryHeight = 188; const InventoryItemCountX = 7; const InventoryItemCountY = 4; const SellerPageStartX = 698; // to 1010 == 312 width const SellerPageStartY = 62; // to 268 == 206 height const SellerPageWidth = 312; const SellerPageHeight = 206; const SellerPageItemCountX = 6; const SellerPageItemCountY = 4; const InnInventoryStartX = 682; const InnInventoryStartY = 354; const InnInventoryWidth = 331; const InnInventoryHeight = 193; const InnDropSpotX = 725; const InnDropSpotY = 90; const vkKey_Forward = 87; const vkKey_Back = 83; const vkKey_TurnLeft = 65; const vkKey_TurnRight = 68; const vkKey_SelectNearestNPC = 66; const vkKey_PointOfViewChange = 120; const vkKey_RunWalk = 84; const MATH_PI = 3.14159265; const MATH_TWOPI = 6.2831853; var PlayerIsWalking = false; MyMouseLeftClick(var clickDelay) { MouseLeftDown(); Delay(clickDelay); MouseLeftUp(); } MyMouseRightClick(var clickDelay) { MouseRightDown(); Delay(clickDelay); MouseRightUp(); } MouseClick(var clickDelay) { MouseLeftDown(); Delay(clickDelay); MouseLeftUp(); } KeyClick(var vkKey, var holdDelay) { KeyDown(vkKey); Delay(holdDelay); KeyUp(vkKey); } ToggleFirstToThird() { KeyClick(vkKey_PointOfViewChange,DefaultKeyClickTime); Delay(DefaultKeyClickTime*2); KeyClick(vkKey_PointOfViewChange,DefaultKeyClickTime); } 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); var angleDiff = GetPlayerLocationDirection() - theNewAngle; while (abs(angleDiff) > (MATH_TWOPI / 32)) { angleDiff = GetPlayerLocationDirection() - theNewAngle; 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.25) || (abs(yPos - GetPlayerLocationY()) > 0.25)) { if ((!PlayerIsWalking) && (sqrt(((xPos - GetPlayerLocationX()) * (xPos - GetPlayerLocationX())) + ((yPos - GetPlayerLocationY()) * (yPos - GetPlayerLocationY()))) < 6.0)) { KeyUp(vkKey_TurnRight); KeyUp(vkKey_TurnLeft); KeyClick(vkKey_RunWalk,DefaultKeyClickTime); PlayerIsWalking = true; } theNewAngle = GetAngleFromDiffSet((GetPlayerLocationX() - xPos),(GetPlayerLocationY() - yPos)); angleDiff = GetPlayerLocationDirection() - theNewAngle; 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(5,12)); } KeyUp(vkKey_Forward); KeyUp(vkKey_TurnRight); KeyUp(vkKey_TurnLeft); if (PlayerIsWalking) { KeyClick(vkKey_RunWalk,DefaultKeyClickTime); PlayerIsWalking = false; } } OpenAnvilForUpgrading() { KeyDown(vkKey_SelectNearestNPC); //42 is the B button on the keyboard Delay(MouseClickDelaySpeed1); KeyUp(vkKey_SelectNearestNPC); //KeyClick(vkKey_Forward,333); MouseMoveTo(1024 / 2, 768 / 2); Delay(MouseClickDelaySpeed2); MyMouseRightClick(MouseClickDelaySpeed1); Delay(MouseClickDelaySpeed1 * 3); MouseMoveTo(490,390); Delay(MouseClickDelaySpeed2); MyMouseLeftClick(MouseClickDelaySpeed1); Delay(MouseClickDelaySpeed1 * 3); } OpenUpMerchantAndBuyAFullSetOfItem() { //this macro assumes that you are "on top" of the merchant and KeyDown(vkKey_SelectNearestNPC); //42 is the B button on the keyboard Delay(MouseClickDelaySpeed1); KeyUp(vkKey_SelectNearestNPC); MouseMoveTo(1024 / 2, 768 / 2); Delay(750); MyMouseRightClick(MouseClickDelaySpeed1); Delay(MouseClickDelaySpeed1); MouseMoveTo(420,370); Delay(750); MyMouseLeftClick(MouseClickDelaySpeed1); Delay(750); for (var currentPage = 1; currentPage < ItemPage; currentPage++) { //first, find the icon to move to the next page. var xStartPos = 890; var yStartPos = 285; DebugWriteLine("XStartPos: " + xStartPos + "; YStartPos: " + yStartPos); if (IsObjectIn("GUI_Inventory_Page_Next",xStartPos,yStartPos,48,48,32)) { DebugWriteLine("XEndPos: " + xStartPos + "; YEndPos: " + yStartPos); MouseMoveTo(xStartPos+6,yStartPos+6); Delay(MouseClickDelaySpeed1); MyMouseLeftClick(DefaultMouseClickTime); Delay(MouseClickDelaySpeed1); } else { throw "Error finding the next page in the inventory!"; } Delay(MouseClickDelaySpeed2); } //now we're on the right page, so we need to find the location of the item. var itemWidth = SellerPageWidth / SellerPageItemCountX; var itemHeight = SellerPageHeight / SellerPageItemCountY; var found = false; var itemXPos = 0; var itemYPos = 0; if (!usingItemLocation) { for (var itemLocY = 0; itemLocY < SellerPageItemCountY; itemLocY++) { for (var itemLocX = 0; itemLocX < SellerPageItemCountX; itemLocX++) { var xStartPos = ceil(SellerPageStartX + (itemLocX * itemWidth)); var yStartPos = ceil(SellerPageStartY + (itemLocY * itemHeight)); if (IsObjectIn(ItemToUpgrade,xStartPos,yStartPos,12,12,32)) { itemXPos = xStartPos + 12; itemYPos = yStartPos + 12; itemLocY = SellerPageItemCountY; itemLocX = SellerPageItemCountX; found = true; } } } if (!found) { throw "Unable to find the item! Are you sure you set the script up properly?"; } } else { found = true; itemXPos = ceil(SellerPageStartX + (itemLocationX * itemWidth)) + 16; itemYPos = ceil(SellerPageStartY + (itemLocationY * itemHeight)) + 16; } for (var i = 0; i < ((InventoryItemCountX * InventoryItemCountY) - 1); i++) { MouseMoveTo(itemXPos,itemYPos); Delay(MouseClickDelaySpeed2); MouseLeftDown(); Delay(MouseClickDelaySpeed1); MouseMoveTo( SellerInventoryStartX + (SellerInventoryWidth / 2), SellerInventoryStartY + (SellerInventoryHeight / 2) ); Delay(MouseClickDelaySpeed2); MouseLeftUp(); Delay(MouseClickDelaySpeed1); } } ThrowPageOfItemsIntoInn() { KeyDown(vkKey_SelectNearestNPC); //42 is the B button on the keyboard Delay(MouseClickDelaySpeed1); KeyUp(vkKey_SelectNearestNPC); MouseMoveTo(1024 / 2, 768 / 2); Delay(750); MyMouseRightClick(MouseClickDelaySpeed1); Delay(MouseClickDelaySpeed1); MouseMoveTo(420,342); Delay(750); MyMouseLeftClick(MouseClickDelaySpeed1); Delay(MouseClickDelaySpeed2 * 3); var itemWidth = InnInventoryWidth / InventoryItemCountX; var itemHeight = InnInventoryHeight / InventoryItemCountY; for (var itemY = 0; itemY < InventoryItemCountY; itemY++) { for (var itemX = 0; itemX < InventoryItemCountX; itemX++) { DebugWriteLine("Checking spot " + itemX + "," + itemY); var xStartPos = ceil(InnInventoryStartX + (itemX * itemWidth)); var yStartPos = ceil(InnInventoryStartY + (itemY * itemHeight)); DebugWriteLine("Coordinates: " + xStartPos + "," + yStartPos); if (IsObjectIn(ItemToUpgrade,xStartPos,yStartPos,42,42,192)) { MouseMoveTo(xStartPos + 10, yStartPos + 10); Delay(MouseClickDelaySpeed2); MouseLeftDown(); Delay(DefaultMouseClickTime); MouseMoveTo(InnDropSpotX,InnDropSpotY); Delay(DefaultMouseClickTime); MouseLeftUp(); Delay(DefaultMouseClickTime); } } } } UpgradeAFullPage() { var itemWidth = AnvilInventoryWidth / InventoryItemCountX; var itemHeight = AnvilInventoryHeight / InventoryItemCountY; for (var itemY = 0; itemY < InventoryItemCountY; itemY++) { for (var itemX = 0; itemX < InventoryItemCountX; itemX++) { DebugWriteLine("Checking spot " + itemX + "," + itemY); var xStartPos = ceil(AnvilInventoryStartX + (itemX * itemWidth)); var yStartPos = ceil(AnvilInventoryStartY + (itemY * itemHeight)); DebugWriteLine("Coordinates: " + xStartPos + "," + yStartPos); if (IsObjectIn(ItemToUpgrade,xStartPos,yStartPos,42,42,192)) { DebugWriteLine("Found item at: " + xStartPos + "," + yStartPos); MouseMoveTo(xStartPos + 12, yStartPos + 12); Delay(MouseClickDelaySpeed1); MyMouseRightClick(MouseClickDelaySpeed1); Delay(MouseClickDelaySpeed1); MouseMoveTo( AnvilInventoryStartX + AnvilInventoryWidth - (itemWidth / 2), AnvilInventoryStartY + AnvilInventoryHeight - (itemHeight / 2) ); Delay(MouseClickDelaySpeed2); MyMouseRightClick(MouseClickDelaySpeed2); Delay(MouseClickDelaySpeed2); MouseMoveTo(760,280); Delay(MouseClickDelaySpeed2); MyMouseLeftClick(MouseClickDelaySpeed2); Delay(MouseClickDelaySpeed2); MouseMoveTo(740,350); Delay(MouseClickDelaySpeed2); MyMouseLeftClick(MouseClickDelaySpeed2); Delay(MouseClickDelaySpeed2); DebugWriteLine("Upgrading..."); MouseMoveTo(500,200); Delay(MouseClickDelaySpeed2); //now we need to wait for the anvil to finish upgrading.... var doneWaiting = false; DebugWriteLine("Waiting For Anvil..."); Delay(MouseClickDelaySpeed2 * 6); while (!doneWaiting) { DebugWriteLine("Wait..."); var dax = AnvilWatchStartX; //I can't juse use the const values because the function var day = AnvilWatchStartY; //stores the actual item coords in the start vars... if (IsObjectIn("GUI_Anvil_Empty_And_Clear",dax,day,32,32,192)) { doneWaiting = true; } Delay(MouseClickDelaySpeed2); } Delay(MouseClickDelaySpeed1); //Delay(6000); } } } } UpgradeItemsInInventory(var numberOfUpgrades) { for (var i = 0; i < numberOfUpgrades; i++) { UpgradeAFullPage(); } } MoveFromMerchantToAnvil() { MovePlayerTo(386,369); MovePlayerTo(340,372); MovePlayerTo(330,384); MovePlayerTo(323,376); MovePlayerTo(336,388); } MoveFromAnvilToHumanInn() { MovePlayerTo(328,381); MovePlayerTo(320,409); MovePlayerTo(364,421); } MoveFromHumanInnToArmorMerchant() { MovePlayerTo(374,399); MovePlayerTo(386,369); MovePlayerTo(397,362); } MoveFromHumanInnToWeaponMerchant() { MovePlayerTo(374,399); MovePlayerTo(386,369); MovePlayerTo(397,372); } main() { //initial startup.... make sure window has input focus... MouseMoveTo(1024 / 2, 768 / 2); Delay(2000); MouseClick(1); MovePlayerTo(386,369); if (usingWeaponMerchant) { MovePlayerTo(397,372); } else { MovePlayerTo(397,362); } while(true) { ToggleFirstToThird(); OpenUpMerchantAndBuyAFullSetOfItem(); ToggleFirstToThird(); MoveFromMerchantToAnvil(); ToggleFirstToThird(); OpenAnvilForUpgrading(); ToggleFirstToThird(); UpgradeItemsInInventory(6); MoveFromAnvilToHumanInn(); ToggleFirstToThird(); ThrowPageOfItemsIntoInn(); ToggleFirstToThird(); if (usingWeaponMerchant) { MoveFromHumanInnToWeaponMerchant(); } else { MoveFromHumanInnToArmorMerchant(); } } }