lunar Posted November 26, 2018 Report Posted November 26, 2018 I am trying to only get defined number of keys in a trade, but instead it adds all the items as they share the same id (item is a TF2 Mann co. key)here is my current code for the trade offer, (the steam id in create offer is a mates steamid as I can't test with my own account due to vac) function buy(steamID, amount){ if(isNaN(amount) || amount === undefined){ client.chatMessage(steamID, "Please enter a valid number"); } else{ var count = 0; var i = 0; client.chatMessage(steamID, "Creating Offer, please wait!"); //Check Players inventory for the keys, and make sure we have enough sets to supply var offer = manager.createOffer('76561198008100070'); offer.setMessage("Price: " + amount + " Keys. Sets: " + amount * config.buyRate); offer.getPartnerInventoryContents(440, 2, function(err, inventory, currencies){ if(err){ console.log(err); } /*for (var j = 0; j < amount; ++j){ if(inventory[i].market_hash_name == config.keysAccepted){ ++count; console.log("Adding Item"); offer.addTheirItem({id: inventory[i].id, appid: 440, contextid: 2}); } }*/ inventory.forEach(function(val){ if(val.market_hash_name == config.keysAccepted){ console.log("Adding Item"); offer.addTheirItem({id: val.instanceid, appid: 440, contextid: 2}); ++count; } }); if(count < amount){ console.log("count: "+count); client.chatMessage(steamID, "You don't have enough keys for me to send this trade."); } else{ offer.send(function(err, status){ if(err){ console.log(err); client.chatMessage(steamID, "An Error has Occured while sending offer."); } if(status == "pending"){ client.chatMessage(steamID, "Confirming Offer!"); } if(status == "sent"){ client.chatMessage(steamID, "Offer Sent!"); } }); } }); } } Quote
lunar Posted November 27, 2018 Author Report Posted November 27, 2018 Got it working var a = []; for(var i = 0; i < inventory.length; ++i){ if(inventory[i].market_hash_name == config.keysAccepted && a.length < amount){ console.log("Adding Item"); a.push(inventory[i].id); offer.addTheirItem({id: inventory[i].id, appid: 440, contextid: 2}); console.log("Length of a "+a.length); console.log(a); ++count; } } Quote
Recommended Posts
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.