TextDynasty Posted October 10, 2016 Report Posted October 10, 2016 Hi everyone. My bot works fine now but it seems didn't declined wrong offers. Anyone can help me would be very nice. My code: offers.on('newOffer', function (offer) { manager.on("newOffer", function(offer) { var onlyKeys1 = (offer.itemsToReceive.every(function(item) { return item.name == "Mann Co. Supply Crate Key"; })); var onlyRef1 = (offer.itemsToGive.every(function(item) { return item.name == "Refined Metal"; })); var onlyKeys2 = (offer.itemsToGive.every(function(item) { return item.name == "Mann Co. Supply Crate Key"; })); var onlyRef2 = (offer.itemsToReceive.every(function(item) { return item.name == "Refined Metal"; })); if (onlyKeys1, onlyRef1) { keyAmount = offer.itemsToReceive.length refAmount = offer.itemsToGive.length == keyAmount * buyprice if (keyAmount == refAmount) { console.log("They are selling " + keyAmount + " keys for " + buyprice * keyAmount + " refined metal."); console.log("Accepting the trade offer."); offer.accept(function(err) { if (err) console.log(err); else console.log("Trade offer accepted."); }); } } if (onlyKeys2, onlyRef2) { keyAmount = offer.itemsToGive.length refAmount = offer.itemsToReceive.length == keyAmount * sellprice if (keyAmount == refAmount) { console.log("They are buying " + keyAmount + " keys for " + sellprice * keyAmount + " refined metal."); console.log("Accepting the trade offer."); offer.accept(function(err) { if (err) console.log(err); else console.log("Trade offer accepted."); }); } } else console.log("Trade offer not validated. Declining"); offer.decline(function(err) { if (err) console.log(err); }); } }) }); Quote
adma Posted October 10, 2016 Report Posted October 10, 2016 (edited) I don't know what you are trying to do with the comma operator, but by the looks of it you want to use the and operator (&&) in your if (onlyKeys, onlyRef) checks... if (onlyKeys2, onlyRef2) âž¡ if (onlyKeys2 && onlyRef2) In regards to your declining offer thing... its probably to do with your lack of curly braces surrounding if and else e.g if (x && y) { // code } else { // code } Not ... if (x && y) // code else // code What do these lines do/mean?'refAmount = offer.itemsToGive.length == keyAmount * buyprice''refAmount = offer.itemsToReceive.length == keyAmount * sellprice' Also, unless you want the refAmount and keyAmount to be global, you should really declare them with var ... keyAmount = offer.itemsToGive.length âž¡ var keyAmount = offer.itemsToGive.length Even though I am new to coding/scripting and I can see your code is very untidy/messy... PS: What is offers.on('newOffer') ? and why is trade offer manager newOffer listener nested inside this??? Edited October 10, 2016 by adma Dr. McKay 1 Quote
TextDynasty Posted October 13, 2016 Author Report Posted October 13, 2016 (edited) I don't know what you are trying to do with the comma operator, but by the looks of it you want to use the and operator (&&) in your if (onlyKeys, onlyRef) checks... if (onlyKeys2, onlyRef2) âž¡ if (onlyKeys2 && onlyRef2) In regards to your declining offer thing... its probably to do with your lack of curly braces surrounding if and else e.g if (x && y) { // code } else { // code } Not ... if (x && y) // code else // code What do these lines do/mean?'refAmount = offer.itemsToGive.length == keyAmount * buyprice''refAmount = offer.itemsToReceive.length == keyAmount * sellprice' Also, unless you want the refAmount and keyAmount to be global, you should really declare them with var ... keyAmount = offer.itemsToGive.length âž¡ var keyAmount = offer.itemsToGive.length Even though I am new to coding/scripting and I can see your code is very untidy/messy... PS: What is offers.on('newOffer') ? and why is trade offer manager newOffer listener nested inside this???Hi Adma,sorry for that. but i have some questions...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. Edited October 13, 2016 by TextDynasty Quote
Dr. McKay Posted October 13, 2016 Report Posted October 13, 2016 You aren't assigning anything to BuyKey and FromRef1. forEach doesn't return anything. Also, further on down you're using = when you want to use == TextDynasty 1 Quote
TextDynasty Posted October 13, 2016 Author Report Posted October 13, 2016 You aren't assigning anything to BuyKey and FromRef1. forEach doesn't return anything. Also, further on down you're using = when you want to use ==Thanks for the reply but what should i assign? return key++ or what? Thanks Quote
TextDynasty Posted October 13, 2016 Author Report Posted October 13, 2016 (edited) Maybe somethings wrong here? 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.")); }); }} (the buykeyprice set to 198 and this shows up when received offer) Trade offer not validated. Declining They offered 1 keys and 198 refined metals. Edited October 13, 2016 by TextDynasty Quote
Dr. McKay Posted October 13, 2016 Report Posted October 13, 2016 Up to you. Maybe make sure key and metal aren't 0. Quote
TextDynasty Posted October 13, 2016 Author Report Posted October 13, 2016 Up to you. Maybe make sure key and metal aren't 0.It is not 0, the calculation is correct but i don't know why it didn't accept my offer Quote
TextDynasty Posted October 14, 2016 Author Report Posted October 14, 2016 Can you help me correct it a bit?Thanks Quote
TextDynasty Posted October 14, 2016 Author Report Posted October 14, 2016 (edited) Whats wrong with my code?? 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") return key++ })); var FromRef1 = (offer.itemsToGive.forEach(function(item) { if (item.name == "Refined Metal") return metal += 9 if (item.name == "Reclaimed Metal") return metal += 3 if (item.name == "Scrap Metal") return metal++ })); if (BuyKey && FromRef1) { if (metal == key) { 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); }); } }); Trade offer not validated. Declining They offered 1 keys and 198 refined metals. Edited October 14, 2016 by TextDynasty Quote
adma Posted October 16, 2016 Report Posted October 16, 2016 Next time, please present properly formatted code with curly braces... its very disorientating to follow if .. else statements that do not use curly brackets... TextDynasty 1 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.