-
Posts
23 -
Joined
-
Last visited
Community Answers
-
adma's post in cannot declined the wrong offer was marked as the answer
Next time, please present properly formatted code with curly braces... its very disorientating to follow if .. else statements that do not use curly brackets...
-
adma's post in Trade Offer Bot was marked as the answer
manager.on("newOffer", function(offer) {
var onlyKeys = (offer.itemsToReceive.every(function(item) {
return item.name == "Mann Co. Supply Crate Key";
}));
if (onlyKeys) {
keyAmount = offer.itemsToReceive.length
console.log("Received trade offer containing " + keyAmount + " keys, accepting");
offer.accept(function(err) {
if (err) console.log(err);
});
} else {
console.log("Trade offer contains non key items. Declining");
offer.decline(function(err) {
if (err) console.log(err);
});
}
}
-
adma's post in Unable to accept offer: Malformed JSON response? was marked as the answer
var keys = offer.itemsToReceive.map { if (item.name == "Mann Co. Supply Crate Key") { return item; } } var keyAmount = keys.length Something like that should work, and is handy if you wanted to send keys ... you could also do something like
var keyAmount = 0; offer.itemsToReceive.forEach(function(item) { if (item.name == "Mann Co. Supply Crate Key") { keyAmount++; } } // do something with keyAmount -
adma's post in itemsToGive with multiple items was marked as the answer
If you want to get the market hash names of each item you're giving, you would probably use forEach or a for loop to cycle through the itemsToGive array ...
e.g
manager.on('newOffer', function(offer) { offer.itemsToGive.forEach(function(item) { console.log("Item to give : " + item.market_hash_name); // Items to give: Chroma 2 Case }); }); a for ... of loop (edited from for..in loop)
manager.on('newOffer', function(offer) { for (var item of offer.itemsToGive) { console.log("Items to give : " + item.market_hash_name); // Items to give: Chroma 2 Case } }); a regular for loop
manager.on('newOffer', function(offer) { for (var i = 0; i < offer.itemsToGive.length; i++) { console.log("Items to give #" + i + " : " + offer.itemsToGive[i].market_hash_name); // Items to give #1 : Chroma 2 Case } });Same deal will apply for itemsToReceive ... or any other array you wanted to cycle through
read here https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Loops_and_iteration