#Targeted item trasnfer grid(Container-2-Container)

1 messages · Page 1 of 1 (latest)

timid trench
#

I added (had gpt add) a few functions to my previous script. Now it comes with 3 targets, and repeats the 3rd.

Target 1 = Source container.
Target 2 = Destination Container
Target 3 = Item type to move (it checks the item name, and graphicID. any items matching either of those will move)
Target 4+ = Next item. It will move the next type of item into the container, continuing from where the last item was placed.

Also of note, is its adjusted to 350ms move intervals, so if you have a laggy connection you will need to increase that.

  let itemMoveDelay = 100; // Reduced delay to 100ms
  let startX = 55;
  let startY = 65;
  const gridWidth = 12;
  const maxRows = 11;
  const horizontalSpacing = 36;
  const verticalSpacing = 22;
  let totalMovedItems = 0;

  let container1 = target.query(false);
  let container2 = target.query(false);

  if (!container1 || !container2) {
    console.log("Containers not found. Exiting.");
    return;
  }

  while (true) {
    let targetGraphicID = 0x1234;
    let targetItemName; 

    const targetItem = client.findObject(target.query(false, targetGraphicID));

    if (targetItem) {
      console.log("Target item found.");
      targetItemName = targetItem.name; 
    } else {
      console.log("Target item not found. Exiting.");
      break; 
    }

    let sourceContents = (client.findObject(container1) as Item).contents; 
    // Removed the sleep here for faster checks
    let destinationContainer = container2; 
    let itemCount = 0; 

    for (let item of sourceContents) {
      if (item.graphic === targetItem.graphic || item.name === targetItemName) {
        let row = Math.floor((totalMovedItems + itemCount) / gridWidth);
        let col = (totalMovedItems + itemCount) % gridWidth;

        let currentX = startX + (col * horizontalSpacing) + (row % 2 === 1 ? 13 : 0);
        let currentY = startY + (row * verticalSpacing); 

        player.moveItem(item.serial, destinationContainer, currentX, currentY);
        // Removed sleep here to eliminate the delay after each move
        console.log("Moved:", item.name);
        itemCount++;
      }

      if (itemCount >= maxRows * gridWidth) {
        console.log("Reached maximum rows processed.");
        break; 
      }
    }

    totalMovedItems += itemCount;

    if (itemCount === 0) {
      console.log("No matching items found. Exiting.");
      break;
    }
  }
})();
#

Before