Jump to content
McKay Development

How to counter incoming trade offer?


Recommended Posts

Hello, how did I counter an incoming trade offer?
I know that I need to use "offer.counter()", but I don't know how to use it.

 

I got this following code to counter an offer, but it will show an error "Cannot add item to an already-sent offer".

manager.on('newOffer', function(offer) {
   if (offer.partner.getSteamID64() == admin){

      //Counter an offer by adding new item
      offer.counter();
      offer.addMyItem({"appid": 753, "contextid": 6, "assetid": "5222324266"}); //error here
      offer.send(function(err, status){
         if (err){
            console.log("Error: "+err);
         }
         console.log("Status: "+status)
      });
   }
}

Can anyone show the correct code please? I would really appreciate it.

Thanks :)

Edited by Vanilla
Link to comment
Share on other sites

offer.counter() returns a new TradeOffer object. You need to perform your changes on that TradeOffer that it returns.

So, I need to use offer.counter() to get tradeoffer object, make change on that, and send new trade offer?

Edited by Vanilla
Link to comment
Share on other sites

Correct.

 

Thanks, just successfully make a counter offer.

I only need to add "counter()" everytime I want to counter an offer.

 

This is the working counter offer code (for those who got same problem)

 

manager.on('newOffer', function(offer) {
   if (offer.partner.getSteamID64() == admin){

      //Counter an offer
      offer.counter().addMyItem({"appid": 753, "contextid": 6, "assetid": "5222324266"}); 
      offer.counter().send(function(err, status){
         if (err){
            console.log("Error: "+err);
         }
         console.log("Status: "+status)
      });
      //confirmation
   }
}
Edited by Vanilla
Link to comment
Share on other sites

No, that's wrong. Don't call counter() more than once. Call it once and store the result in a variable.

 

Lol, so that's why I'm unable to add new item.  :D

 

Now works like a charm, thanks.

 

manager.on('newOffer', function(offer) {
   if (offer.partner.getSteamID64() == admin){

      //Counter an offer by adding new item
      var counteroffer = offer.counter();
      counteroffer.addMyItem({"appid": 753, "contextid": 6, "assetid": "5222324266"}); 
      counteroffer.send(function(err, status){
         if (err){
            console.log("Error: "+err);
         }
         console.log("Status: "+status)
      });
      //confirmation
   }
}
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...