Jump to content
McKay Development

Crafting a trade


theFarmer

Recommended Posts

Hi all! 

I am able to generate trades from my "bot" account using `offer.addMyItems(items)` as long as there aren't more than 1 of each item. The moment I trie to add a second item I face issues. I am combining and updating the amount. Here are two console logs:
 

[[[allAssetIds]]] [
  '4472701497518213337',
  '4472701497518213337',
  '4472701497518213337',
  '4472701497518213337',
  '4472701497519256933'
]

 

[[[FORMATEED TEMS]]] [
  {
    appid: 252490,
    contextid: '2',
    assetid: '4472701497518213337',
    amount: 4
  },
  {
    appid: 252490,
    contextid: '2',
    assetid: '4472701497519256933',
    amount: 1
  }
]

The first is the raw items I need to add, and the second is my "formatted" items. However, I get the "Error: There was an error sending your trade offer.  Please try again later. (26)" error. It only happens if there is more than 1 of an item, so I think I'm doing something wrong rather than something wrong with the library.

 

Thanks so much!

Link to comment
Share on other sites

I am just noting my progress. It seems that the assetid is not unique to the item, even though I assumed it was. Searching for the name, I was able to find that the amount of items exists, just that each one's assetid was different. So, I will try to take my requested items and match them against the inventory using the market_hash_name instead. I will post back with the outcome on this.

Yep! That fixed it. Maybe a better way but my solution looks something like:
 

function prepareTrade(combinedItems, inventory) {
  let allAssetIds = [];
  combinedItems.forEach(item => {
    // Find the index of the item in inventory that matches the current item
    const foundIndex = inventory.findIndex(invItem => invItem.market_hash_name === item.markethashname);
    if (foundIndex !== -1) {
      // If the item is found, push its asset id and remove it from the inventory
      allAssetIds.push(inventory[foundIndex].assetid);
      inventory.splice(foundIndex, 1);
    }
  });
  return allAssetIds;
}

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...