Jump to content


Photo

Find one item by classid

node.js node-steam-tradeoffer-manager

  • Please log in to reply
2 replies to this topic

#1 PonyExpress

PonyExpress

    Member

  • Member
  • PipPip
  • 14 posts

Posted 06 February 2019 - 09:07 PM

I try to create code that will convert steamtradematcher.com URL and send trade offer.

steamtradematcher.com URL looks like:
 _ttps://www.steamtradematcher.com/action/startTradeOffer/239296914/2nqDtNKM/1935295573;2139754079/1930661303;2139726948
From this line I get all the data: Partner, Token and Items.

However, I think I'm doing something wrong. My method looks pretty complicated and doesn't work anyway.
My question is how can I find the first any item with classid="1935295573" to add it to the trade later? (One item)
 
            //  MSG = "STM https://www.steamtradematcher.com/action/startTradeOffer/239296914/2nqDtNKM/1935295573;2139754079/1930661303;2139726948"
            let stmUrl = MSG.split("/"),
                tradePartner = "[U:1:" + stmUrl[5] + "]",
                tradeToken = stmUrl[6],
                stmHisItems = stmUrl[8].split(";"),
                stmMyItems = stmUrl[7].split(";");
            if (stmHisItems.length != stmMyItems.length) {
                console.log("ERROR 1: Bad url");
            } else {
                let t = manager.createOffer(tradePartner, tradeToken);
                t.getUserDetails((ERR, ME, THEM) => {
                    if (ERR) {
                        console.log("ERROR 2: " + ERR);
                    } else if (ME.escrowDays == 0 && THEM.escrowDays == 0) {
                        let hisItems = [],
                            myItems = [];
                        manager.getUserInventoryContents(tradePartner, 753, 6, true, (ERR, INV, CURR) => {
                            if (ERR) {
                                console.log("ERROR 3: " + ERR);
                            } else {
                                INV = INV.filter((ITEM) => ITEM.getTag("item_class").internal_name == "item_class_2"); // <<<<<<<<<<<<
                                for (let i = 0; i < INV.length; i++) {                // <<<<<<<<<<<<
                                    for (let j = 0; j < stmHisItems.length; j++) {    // <<<<<<<<<<<<
                                        if (stmHisItems[j] == INV[i].classid) {       // <<<<<<<<<<<<
                                            hisItems.push(INV[i]);                    // <<<<<<<<<<<<
                                            console.log("PUSH:" + i);                 // <<<<<<<<<<<<
                                            stmHisItems[j] = "need_only_one.";        // <<<<<<<<<<<<
                                        }
                                    }
                                }
                                // 2. find my items and 3. add his/my items in trade 4. send trade
                             }
                        });
                    }
                });
            }

 



#2 PonyExpress

PonyExpress

    Member

  • Member
  • PipPip
  • 14 posts

Posted 07 February 2019 - 12:36 PM

I think I found the solution myself

                                INV = INV.filter((ITEM) => ITEM.getTag("item_class").internal_name == "item_class_2");
                                for (let i = 0; i < stmHisItems.length; i++) {
                                    hisItems.push(    INV.find((ITEM) => ITEM.classid == stmHisItems[i])      );
                                }

_

 

Yes, it works great. Only I after a few trades, I began to receive an error:
 
TradeOffer.js:254
if (typeof details.appid === 'undefined' || typeof details.contextid === 'undefined' || (typeof details.assetid === 'undefined' && typeof details.id === 'undefined')) {
TypeError: Cannot read property 'appid' of undefined
 
I think I need to stop find and trade  if the at least 1 item is not found.

Do you think I should check my inventory first or partner's inventory? Or is there no difference?


Edited by PonyExpress, 07 February 2019 - 03:02 PM.


#3 Dr. McKay

Dr. McKay

    Developer

  • Administrator
  • 1,944 posts

Posted 07 February 2019 - 07:53 PM

That error means you're calling addMyItem/addTheirItem with an undefined argument.

 

It doesn't matter which inventory you check first.







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

1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users