TextDynasty Posted October 10, 2016 Report Posted October 10, 2016 HiIs there any ways that we can count multiple different items in the trade offer?Thanks for helping Quote
Dr. McKay Posted October 11, 2016 Report Posted October 11, 2016 I'm not sure what you're asking. Quote
TextDynasty Posted October 11, 2016 Author Report Posted October 11, 2016 I mean count multiple currency, such as count scrap metal and refined metal to buy a key. Quote
Dr. McKay Posted October 11, 2016 Report Posted October 11, 2016 There are multiple ways to do this. You could loop the item arrays and increment counters when you find matching items. You could use filter to filter the arrays for particular items and check the length of the resulting arrays. Quote
TextDynasty Posted October 11, 2016 Author Report Posted October 11, 2016 i tried this way but it didn't increase the value of "currency" and "key" var currency = 0 var key = 0 var BuyKey = (offer.itemsToReceive.every(function(item) { return item.name == "Mann Co. Supply Crate Key"; key++ })); var FromRef1 = (offer.itemsToGive.every(function(item) { return item.name == "Refined Metal"; currency += 9 })); Quote
Dr. McKay Posted October 12, 2016 Report Posted October 12, 2016 every will stop executing as soon as it reaches an entry that doesn't return true. Also, return will stop executing the function immediately. You want forEach, and don't return if the name matches the desired value. Instead, use that check in an if. Quote
TextDynasty Posted October 12, 2016 Author Report Posted October 12, 2016 every will stop executing as soon as it reaches an entry that doesn't return true. Also, return will stop executing the function immediately. You want forEach, and don't return if the name matches the desired value. Instead, use that check in an if. Hi McKay, Do you know any problems in my script? It didn't seems working. Thanks a lot. offers.on('newOffer', function (offer) { manager.on("newOffer", function(offer) { var metal = 0 var key = 0 var BuyKey = (offer.itemsToReceive.forEach(function(item) { if (item.name == "Mann Co. Supply Crate Key") key++ })); var FromRef1 = (offer.itemsToGive.forEach(function(item) { if (item.name == "Refined Metal") metal += 9 })); var FromRec1 = (offer.itemsToGive.forEach(function(item) { if (item.name == "Reclaimed Metal") metal += 3 })); var FromScrap1 = (offer.itemsToGive.forEach(function(item) { if (item.name == "Scrap Metal") metal++ })); if (BuyKey, FromRef1, FromRec1, FromScrap1) { sell = metal buy = key * buykeyprice if (sell == buy) { offer.accept(function(err) { if (err) console.log(err); else console.log("They are selling " + key + " keys for " + buy + " refined metal."); console.log(colors.red("Accepting the trade offer.")); console.log(colors.green("Trade offer accepted.")); }); } if (sell != buy){ console.log("Trade offer not validated. Declining"); console.log("They offered " + key + " keys and " + metal + " refined metals. ") offer.decline(function(err) { if (err) console.log(err); }); }} }) }); Quote
Dr. McKay Posted October 12, 2016 Report Posted October 12, 2016 Why are you constantly using commas when you mean to use &&? Quote
TextDynasty Posted October 12, 2016 Author Report Posted October 12, 2016 thanks for reply. i changed the comma to && but it didn't work too. : ( offers.on('newOffer', function (offer) { manager.on("newOffer", function(offer) { var metal = 0 var key = 0 var BuyKey = (offer.itemsToReceive.forEach(function(item) { if (item.name == "Mann Co. Supply Crate Key") key++ })); var FromRef1 = (offer.itemsToGive.forEach(function(item) { if (item.name == "Refined Metal") metal += 9 })); var FromRec1 = (offer.itemsToGive.forEach(function(item) { if (item.name == "Reclaimed Metal") metal += 3 })); var FromScrap1 = (offer.itemsToGive.forEach(function(item) { if (item.name == "Scrap Metal") metal++ })); if (BuyKey && FromRef1 && FromRec1 && FromScrap1) { sell = metal buy = key * buykeyprice if (sell == buy) { offer.accept(function(err) { if (err) console.log(err); else console.log("They are selling " + key + " keys for " + buy + " refined metal."); console.log(colors.red("Accepting the trade offer.")); console.log(colors.green("Trade offer accepted.")); }); } if (sell != buy){ console.log("Trade offer not validated. Declining"); console.log("They offered " + key + " keys and " + metal + " refined metals. ") offer.decline(function(err) { if (err) console.log(err); }); }} }) }); Quote
Dr. McKay Posted October 13, 2016 Report Posted October 13, 2016 What's with the nested listeners on newOffer? And on separate emitters? Quote
TextDynasty Posted October 13, 2016 Author Report Posted October 13, 2016 (edited) My bot keeps declining my offer even i offer the correct amount of metals. manager.on("newOffer", function(offer) { var metal = 0 var key = 0 var BuyKey = (offer.itemsToReceive.forEach(function(item) { if (item.name == "Mann Co. Supply Crate Key") key++ })); var FromRef1 = (offer.itemsToGive.forEach(function(item) { if (item.name == "Refined Metal") metal += 9 if (item.name == "Reclaimed Metal") metal += 3 if (item.name == "Scrap Metal") metal++ })); if (BuyKey, FromRef1) { if (metal = key * buykeyprice) { offer.accept(function(err) { if (err) console.log(err); else console.log("They are selling " + key + " keys for " + buykeyprice * key + " refined metal."); console.log(colors.red("Accepting the trade offer.")); console.log(colors.green("Trade offer accepted.")); }); }} else { console.log("Trade offer not validated. Declining"); console.log("They offered " + key + " keys and " + metal + " refined metals. ") offer.decline(function(err) { if (err) console.log(err); }); } }); When I sent a correct offer, it declines it ( my buying price is 198 ) Trade offer not validated. Declining They offered 1 keys and 198 refined metals.The calculation of metals works fine and it show it is correct amount but it keeps declining it.Thanks McKay Edited October 13, 2016 by TextDynasty 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.