Jump to content


Photo
Question

check if trade success

node.js node-steam-tradeoffer-manager

  • Please log in to reply
7 replies to this topic

#1 CellSplitter

CellSplitter

    Member

  • Member
  • PipPip
  • 11 posts

Posted 08 May 2019 - 01:56 PM

Hey iam working on a GameBot.

Example: someone want a Gamepackage, it cost 2 TF2 Keys.

I sent the TradePartner an offer with 2 Keys from his Inventory.

Here is my Code:

function GetItems(){

manager.getUserInventoryContents(TradePartnerSteamID64, 440, 2, true, (err, inv) => {
if (err) {
console.log(err);
} else {
var Volume = 2; // Get X Amount of Items

// Filter out all
var Keys = inv.filter(function(item) {
return item.market_hash_name.match('Mann Co. Supply Crate Key')
});

// Check if TradePartner have enough Keys
if(Keys.length < Volume) {
console.log('Not enough Mann Co. Supply Crate Keys');
return true;
}

// Start a new TradeOffer
var offer = manager.createOffer(TradePartnerSteamID64);

// Add the Items to TradeOffer
console.log('Adding ' + Volume + ' Mann Co. Supply Crate Key');
offer.addTheirItems(Keys.slice(0, Volume))

// Send the TradeOffer
offer.send(function(err, status) {
if(err) {
console.log(err);
} else if(status == 'pending') {
community.acceptConfirmationForObject(Config.IDENTITYSECRET, offer.id, function(err) {
if(err) {
console.log(err);
} else {
console.log("TradeOffer confirmed");
}
});
} else {
console.log('TradeOffer sent successfully');
}
});
}
});

};

...ok that works.

But how can i check if the Trade decline, finish or Items changed by TradePartner?

Like:

If trade done sent GameCodes
If trade decline do anything
If trade changed kick him i his ass :)

Iam newbie in node, pls help me.

Thx in advance....

#2 SnaBe

SnaBe

    Member

  • Member
  • PipPip
  • 29 posts
  • LocationDenmark

Posted 08 May 2019 - 02:00 PM

You can use Steam Trade Offer Manager to check for sent offers & check the offer state with ETradeOfferState.

manager.on('sentOfferChanged', (offer, oldState) => {
  console.log(`Bot ${this.client.steamID.getSteamID64()}'s offer #${offer.id} changed: ${TradeOfferManager.ETradeOfferState[oldState]} -> ${TradeOfferManager.ETradeOfferState[offer.state]}`);
});


#3 CellSplitter

CellSplitter

    Member

  • Member
  • PipPip
  • 11 posts

Posted 08 May 2019 - 02:17 PM

Ok, thx for fast help, i will try it.

If i have probs, i write again

#4 CellSplitter

CellSplitter

    Member

  • Member
  • PipPip
  • 11 posts

Posted 10 May 2019 - 02:10 AM

Ok, i have try it, but there was an error if tradeoffer items changed by OfferPartner ( Offer.state == 4 )

 

how can i cancel the changed TradeOffer from OfferPartner?

Send TradeOffer Function:

// Send TradeOffer to TradePartnerSteamID64
function GetItems(){
    manager.getUserInventoryContents(TradePartnerSteamID64, 440, 2, true, (err, inv) => {
        if (err) {
            log("[" + getTime() + "] [ERROR] Get User Inventory Contents: " + err);
        } else {
            var Volume = 1; // Get X Amount of Items
            
            // Filter out all the TF2 Keys
            var Tf2Keys = inv.filter(function(item) {
                return item.market_hash_name.match('Mann Co. Supply Crate Key')
            });
        
            // Let the user know we don't have enough Tf2Keys
            if(Tf2Keys.length < Volume) {
                log("[" + getTime() + "] [INFO] Not enough Mann Co. Supply Crate Keys in TradePartnerSteamID64's Inventory");
                return true; // Give up
            }
            
            // Start a new trade offer
            Offer = manager.createOffer(TradePartnerSteamID64);
            // Add what we should to the current trade
            log("[" + getTime() + "] [INFO] Adding " + Volume + " Mann Co. Supply Crate Keys to TradeOffer");
            Offer.addTheirItems(Tf2Keys.slice(0, Volume))
            
            // Send the offer
            Offer.send(function(err, status) {
                if(err) {
                    log(err);
                } else if(status == 'pending') {
                    community.acceptConfirmationForObject(Config.IDENTITYSECRET, Offer.id, function(err) {
                        if(err) {
                            log(err);
                        } else {
                            log("[" + getTime() + "][INFO] TradeOffer confirmed with TradeOfferID: #" + Offer.id);
                        }
                    });
                } else if(status == "accepted") {
                    log("[" + getTime() + "][INFO] TradeOffer accepted");
                     
                } else {
                    log("[" + getTime() + "][INFO] TradeOffer #" + Offer.id + " sent successfully");
                }
            });
         }
    });
    
};

Check TradeOffer States :

// Check TradeOffer States
manager.on("sentOfferChanged", (Offer, oldstate) => {
	if (Offer.state == 1) {
	log("[" + getTime() + "] [WARN] Invalid TradeOffer");
		
	} else if (Offer.state ==2) {
		log("[" + getTime() + "] [WARN] Active TradeOffer");
		
	} else if (Offer.state == 3) {
		log("[" + getTime() + "] [WARN] Accepted TradeOffer");
		
	} else if (Offer.state == 4) { // TradeOffer Changed
		log("[" + getTime() + "] [WARN] Countered TradeOffer");
		
		Offer.cancel((err) => {
			if(err) {
				log("["+getTime()+"] [ERROR] We can't cancel the TradeOffer: " + err);
			} else {
			    log("["+getTime()+"] [Canceled TradeOffer] OfferID: #" + Offer.id);
			}
		});
		
	} else if (Offer.state == 5) {
		log("[" + getTime() + "] [WARN] Expired TradeOffer");
		
	} else if (Offer.state == 6) {
		log("[" + getTime() + "] [WARN] Canceled TradeOffer");
		
	} else if (Offer.state == 7) {
		log("[" + getTime() + "] [WARN] Declined TradeOffer");
		
	} else if (Offer.state == 8) {
		log("[" + getTime() + "] [WARN] InvalidItems TradeOffer");
		
	} else if (Offer.state == 9) {
		log("[" + getTime() + "] [WARN] CreatedNeedsConfirmation TradeOffer");
		
	} else if (Offer.state == 10) {
		log("[" + getTime() + "] [WARN] CanceledBySecondFactor TradeOffer");
		
	} else if (Offer.state == 11) {
		log("[" + getTime() + "] [WARN] InEscrow TradeOffer");
		
	}
});

CONSOLE OUTPUT:

[10:05:2019 - 12:18:57] [INFO] Websession created and Cookies set successfully.
[10:05:2019 - 12:18:57] [INFO] Adding 1 Mann Co. Supply Crate Keys to TradeOffer
[10:05:2019 - 12:18:58] [INFO] TradeOffer #3565072757 sent successfully
[10:05:2019 - 12:19:48] [WARN] Countered TradeOffer
[10:05:2019 - 12:19:48] [ERROR] We can't cancel the TradeOffer: Error: Offer #353565072757 is not active, so it may not be cancelled or declined

------------------

I want if Offer.state == 4 cancel the offer automaticly

 

But i dont know how :-(


Edited by CellSplitter, 10 May 2019 - 05:24 AM.


#5 Dr. McKay

Dr. McKay

    Developer

  • Administrator
  • 2,070 posts

Posted 10 May 2019 - 03:03 PM

When an offer is countered, the original offer goes into state 4 and a new offer is created. You want to decline the new offer.



#6 CellSplitter

CellSplitter

    Member

  • Member
  • PipPip
  • 11 posts

Posted 10 May 2019 - 06:00 PM

Yes thats right, i want cacel the new offer from my OfferPartner

#7 CellSplitter

CellSplitter

    Member

  • Member
  • PipPip
  • 11 posts

Posted 12 May 2019 - 02:55 AM

How can i solve it, if tradeoffer changed by TradePartner and he send me new Offer that it automaticly decline?

#8 CellSplitter

CellSplitter

    Member

  • Member
  • PipPip
  • 11 posts

Posted 13 May 2019 - 09:48 AM

Post can close, i solve the Problem by my self ;)





Also tagged with one or more of these keywords: Question, node.js, node-steam-tradeoffer-manager

1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users