Jump to content
McKay Development

Recommended Posts

Posted

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

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

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...