-2

Ok so I have a code from a steam bot the accepts and declines trades if the offer state is correct. But I would like it to accept trade offers that give me things but decline trade offers that are made by someone else asking for things.

      if(body.response.trade_offers_received){
    body.response.trade_offers_received.forEach(function(offer) {

      if (offer.trade_offer_state == 2){
          offers.acceptOffer({tradeOfferId: offer.tradeofferid});
          }
        else {
          offers.declineOffer({tradeOfferId: offer.tradeofferid});
        }
      }
    );
  }
TheFalcon
  • 27
  • 1
  • 1
  • 4

1 Answers1

2

Not exactly sure what bot you're basing your code off, however after looking at the steam api for trade offers, there should be an array called "items_to_give" which you could check and see if it is empty before accepting.

if (offer.trade_offer_state === 2 && (!offer.hasOwnProperty("items_to_give") || offer.items_to_give.length === 0)){

So above we check if we do not have the "items_to_give" key, which doesn't exist if you are giving nothing. Then we check to make 100% sure that it has no items in it, just in case Steam decides to include empty keys with their API at a later date.

After looking at the steam api again, I believe your code could be improved if you also checked for TradeOfferStateCountered(4), which would let you accept counter offers as well. Here is the code for that

if ((offer.trade_offer_state === 2 || offer.trade_offer_state === 4) && (!offer.hasOwnProperty("items_to_give") || offer.items_to_give.length === 0)){
feildmaster
  • 114
  • 6
  • What I mean is lets say someone sends me an offer that giving me something I want it to accept. But if someone sends me an offer thats asking me to give them something want it to accept – TheFalcon Mar 20 '15 at 00:34
  • 1
    Right, if you change the "if" statement to what I posted, this should work. – feildmaster Mar 20 '15 at 00:38
  • But if someone sends an item to me and requests an item it will also request – TheFalcon Mar 20 '15 at 00:48
  • No, if they request an item it will decline – feildmaster Mar 20 '15 at 01:01
  • It doesn't? I see you're using [node-steam-tradeoffers](https://github.com/Alex7Kom/node-steam-tradeoffers/) which uses [node steam](https://github.com/seishun/node-steam/), which should be returning that array... Oh. I know what it is. Give me a second I'll edit my answer. – feildmaster Mar 20 '15 at 01:25
  • Ok I just tested but it just declines the trade? – TheFalcon Mar 20 '15 at 01:31
  • You are welcome, I'm glad we got it working. :) I have another edit if you'd like... Let me edit my post again, it will be a new bit of code. – feildmaster Mar 20 '15 at 01:39
  • I have added an additional helpful thing for you, I hope it helps you. – feildmaster Mar 20 '15 at 01:43
  • Thank you is there anyway I can get into contact with you away from this site? skype or email? – TheFalcon Mar 20 '15 at 01:48