Jump to content


Photo

manager.addTheirItem grabs all items with same id

node.js node-steam-tradeoffer-manager

  • Please log in to reply
1 reply to this topic

#1 lunar

lunar

    Member

  • Member
  • PipPip
  • 10 posts

Posted 26 November 2018 - 06:40 PM

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!");
					}
				});
			}
		});
	}
}


#2 lunar

lunar

    Member

  • Member
  • PipPip
  • 10 posts

Posted 26 November 2018 - 10:48 PM

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;
					}
			}






Also tagged with one or more of these keywords: node.js, node-steam-tradeoffer-manager

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users