Jump to content
McKay Development

Recommended Posts

Posted

Hi.

I want to know how to count items in trade offer to make trade offer more useful

i've tried this code but it didn't seems working

 

var item_from_me =
{
    "appid": 440,
    "contextid": 2,
    "amount": 1,
"assetid": "5148534535",
    "item.name": "Refined Metal"
}
 
var item_from_them =
{
    "appid": 440,
    "contextid": 2,
    "amount": 1,
"assetid": "5158673853",
    "item.name": "Mann Co. Supply Crate Key"
}
offers.on('newOffer', function (offer) {
    if (offer > 0) {
    offers.getOffers({
      get_received_offers: 1,
      active_only: 1,
      time_historical_cutoff: Math.round(Date.now() / 1000)
    }, function(error, body) {
      if(body.response.trade_offers_received) {
        body.response.trade_offers_received.forEach(function(offer) {
          if (offer.trade_offer_state == 2) {
            console.log(offer);
            console.log('Recieved trade offer: ' + offer.tradeofferid);
            if (offer.items_to_give === item_from_me * 22 && offer.items_to_recieve === item_from_them) {
              offers.acceptOffer({tradeOfferId: offer.tradeofferid});
              console.log("Offer accepted");
              if (offer.steamid_other !== admin) {
                steam.sendMessage(admin, offer.steamid_other + " just donated!");
              }
            } else {
              offers.declineOffer({tradeOfferId: offer.tradeofferid});
              console.log("Offer declined");
            }
          }
        });
      }
    });
  }

 

Posted (edited)
You're not using steam-tradeoffer-manager.

 

 

sorry my bad. 

offers.on('newOffer', function (offer) {
manager.on("newOffer", function(offer) {
	var onlyKeys = (offer.itemsToReceive.every(function(item) {
		return item.name == "Mann Co. Supply Crate Key";
	}));
	var onlyRef = (offer.itemsToGive.every(function(item) {
		return item.name == "Refined Metal";
	}));
	if (onlyKeys, onlyRef) {
		keyAmount = offer.itemsToReceive.length
		refAmount = offer.itemsToGive.length
		console.log("Received trade offer containing " + keyAmount + " keys, accepting");
		if (keyAmount == refAmount * 21)
		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);
		});
	}
})
}); 

i tried something like this but it doesn't accept my offer. any ideas?

Edited by TextDynasty

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...