Jump to content
McKay Development

adma

Member
  • Posts

    23
  • Joined

  • Last visited

Everything posted by adma

  1. Next time, please present properly formatted code with curly braces... its very disorientating to follow if .. else statements that do not use curly brackets...
  2. 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???
  3. 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); }); } }
  4. 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
  5. 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
  6. Anyway, for the time being I will use offer.data to do something like offer.data('accepted', 'true') when a trade offer is accepted, and then just do a check for true on realTimeTradeCompleted
  7. Hi McKay, I found some time to fiddle around and try to remake the scenario. \ info: [tradeStarted] Started real time trade info: Ended real trade due to pending info: Offer pending with trade offer 1543634806 info: [newOffer] Received trade offer 1543634806 info: [30 seconds after receiving trade offer 1543634806] warn: Trade offer 1543634806 state : Active I'm sure when accepting this offer, realTimeTradeCompleted will emit. Right now the TF2 / Steam / whatever services are being slow and giving lots of Error 28's and 'Data Temporarily Unavailable' ... I'll edit this post when it works. edit... eventually accepted it. info: [realTimeTradeCompleted] Real time trade 1543634806 completed warn: [realTimeTradeCompleted] Real time trade 1543634806 state : Accepted info: Received trade offer 1543634806 changed from 2 to 3
  8. It seems I can't reproduce this behavior anymore, but I can tell you that it occurred when http://steamstat.us reported the TF2 API as being 'slow' I'll keep trying and see what I can find.
  9. Yes, this is happening through real time trading requested by me to the bot through Steam chat. And I made a mistake in my previous post, the bot does not decline the offer, the bot ignores it.
  10. Yes. I'll break it down so we both don't get confused ... I will be 'user' , bot will be 'bot' This is what initially happened when bot accepts trade offer regardless of realTimeTrade, User trades bot and gives 1 key to bot User confirms mobile confirmation Bot emits 'newOffer' event (from the real time trade) Bot then accepts trade offer from 'newOffer', then does 'functions' Bot emits 'realTimeTradeCompleted', then does 'functions' Conclusion, bot does 'functions' twice from one real time tradeThis is what happened when bot does ignores trade offers that are realTimeTrade (ie. manager.newOffer .... if (!offer.realTimeTrade) { carry out 'functions' }) User trades bot and gives 1 key to bot User confirms mobile confirmation Bot emits 'newOffer' event (from the real time trade) Bot does nothing with the trade from 'newOffer' because it is a realTimeTrade, so 'functions' aren't carried out Bot does not emit 'realTimeTradeCompleted' because trade offer from 'newOffer' isn't accepted Conclusion, bot does not carry out 'functions'I hope I'm making sense
  11. When I didn't accept it, realTimeTradeCompleted didn't emit. {"level":"warn","message":"Received trade offer 1541120781 from real trade, ignoring","timestamp":"2016-09-26T22:45:21.723Z"} {"level":"info","message":"Received trade offer 1541120781 changed from 2 to 6","timestamp":"2016-09-26T23:07:22.553Z"} // I cancelled the trade offer ~20 minutes after
  12. To mobile confirm you have to use steam-community newConfirmation event community.on("newConfirmation", function(conf) { var time = Math.floor(Date.now() / 1000); conf.respond(time, SteamTotp.getConfirmationKey(PLACEYOURCONFKEYHERE, time, "allow"), true, function(err) { if (err) { // error } else { // anything you want to do when you mobile confirm } }); });
  13. Well you see, in my original post for some reason the real time trade emitted the newOffer , as in it made a trade offer from the real trade. info: Received new trade offer from adma [U:1:94759074] // Bot receives trade offer (newOffer) info: Attempting to accept trade offer 1539324331 // Bot attempts to accept it info: Accepted trade offer 1539324331 containing 1 keys // Accepts it info: Real time trade offer 1539324331 completed // After accepting the trade offer, realTimeTradeCompleted is emitted This was generated from a real time trade where I gave the bot 1 key. When I did what you said in your previous post, the bot ignored the trade offer because it was from a realTimeTrade, and consequently left the trade offer just sitting there. For some odd reason an actual trade offer (that requires the bot to accept it) was made from the real time trade. {"level":"info","message":"Started trade with adma [U:1:94759074]","timestamp":"2016-09-26T22:43:41.250Z"} {"level":"info","message":"Ended real trade due to pending","timestamp":"2016-09-26T22:44:07.576Z"} {"level":"info","message":"Offer pending with trade offer 1541120781","timestamp":"2016-09-26T22:44:07.577Z"} {"level":"warn","message":"Received trade offer 1541120781 from real trade, ignoring","timestamp":"2016-09-26T22:45:21.723Z"} // this is newOffer I have messed around with it and can't seem to reproduce it anymore after passing a node-steam-user instance to the trade offer manager. Don't know if thats what fixed it.
  14. If I don't do anything in newOffer if the offer is fromRealTimeTrade , then realTimeTradeCompleted won't be emitted because I didn't accept it. Wouldn't I need something like fromTradeOffer and check that in realTimeTradeCompleted? I know that sounds silly because for realTimeTradeCompleted to emit the offer has to be from a real trade, but I don't have any other ideas.
  15. As the title says, occasionally, the newOffer event will trigger from a real trade. This is undesirable as I need to carry some functions out when a real trade is completed OR when a trade offer is received. This means that the 'functions' will sometimes occur twice. Is this intended or do I just have to work my way around it? Thanks. info: Received new trade offer from adma [U:1:94759074] info: Attempting to accept trade offer 1539324331 info: Accepted trade offer 1539324331 containing 1 keys info: Real time trade offer 1539324331 accepted
  16. I honestly can't believe how prompt you were with implementing this. Thanks very much McKay!
  17. Alright, thanks for the information McKay. In the mean time I will make the bot trade the user when the user tries to trade the bot. Appreciate your help
  18. It doesn't seem I can get the bot to send the offer. I stripped the trade down to that so the bot instantly confirms, and also waited a few seconds before confirming myself. It still asks me to confirm the mobile end, and once I do the bot receives the items instantly like before... trade.on("ready", function(){ trade.ready(); trade.confirm(); }); Also tried confirming first, and the same happens. In both cases when the offer was mobile accepted on my end, the bots pollData emitted a '3' (Accepted). trade.on("ready", function(){ trade.ready(); trade.chatMsg("Confirming trade in 10 seconds"); setTimeout(function(){ trade.confirm(); }, 10000); }); "1531655513":3, "1531678634":3 However, unknownOfferSent , receivedOfferChanged, newOffer, nor sentOfferChanged events were emitted. Is there any simple way to detect the user mobile confirming or am I missing something crucial? ** TO clarify, the bot (in this case) only receives items. The user does not receive any items.
  19. Thanks for the reply Doctor Mckay, I'll fool around with real trades and see how it works with the unknownOfferSent and sentOfferChanged events..
  20. Hi, I have a bot that accepts keys and does stuff with the partners name, steamid and amount of keys in the trade. Right now I am using the trade manager manager.on('newOffer') to decline offers with non key items and accept offers with only keys,and it works fine with offers that are made using trade offers. However, in test conditions I traded the bot a non key item in a normal trade and accepted my end of the mobile confirmations. Once I accepted the mobile confirmation on my end, the bot doesn't get receive a trade offer and insteads receives the items straight away, bypassing the newOffer event. I confirmed that it bypasses this and receives the item straight away by commenting out the newOffer listen, the bot still receives the items straight away. I can check if the trade is keys only in the real trade but how do I listen for the items being received from a mobile confirmed real trade, and can I get the partners information (steamid, name) from that? I hope I made it clear. Thanks.
×
×
  • Create New...