Jump to content
McKay Development

Find one item by classid


Recommended Posts

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
                             }
                        });
                    }
                });
            }

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • 3 weeks later...

Here is my finished code, maybe someone will need it.
Just copy STM-link from scan page, send to bot and the trade will be sent in a couple of seconds.
You can send offers with a very large amount cards, and you do not need to wait a few minutes until the inventory is loaded.

if (MSG.toUpperCase().indexOf("HTTPS://WWW.STEAMTRADEMATCHER.COM/ACTION/STARTTRADEOFFER/") >= 0) {
    let stmUrl = MSG.split("/"),
        tradePartner = "[U:1:" + stmUrl[5] + "]",
        tradeToken = stmUrl[6],
        stmHisItems = stmUrl[7].split(";"),
        stmBotItems = stmUrl[8].split(";");
    if (stmHisItems.length != stmBotItems.length) {
        console.log("Error: Invalid URL");
    } else {
        let trade = manager.createOffer(tradePartner, tradeToken);
        trade.getUserDetails((ERR, BotDetails, UserDetails) => {
            if (ERR) {
                console.log("An error occurred while getting trade holds: " + ERR);
            } else if (UserDetails.escrowDays == 0) {
                manager.getUserInventoryContents(tradePartner, 753, 6, true, (ERR, INV) => {
                    if (ERR) {
                        console.log("An error occurred while getting inventory: " + ERR);
                    } else {
                        let hisItems = [];
                        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]));
                        }
                        manager.getUserInventoryContents(client.steamID, 753, 6, true, (ERR, INV) => {
                            if (ERR) {
                                console.log("An error occurred while getting bot inventory: " + ERR);
                            } else {
                                let botItems = [];
                                INV = INV.filter((ITEM) => ITEM.getTag("item_class").internal_name == "item_class_2");
                                for (let i = 0; i < stmBotItems.length; i++) {
                                    botItems.push(INV.find((ITEM) => ITEM.classid == stmBotItems[i]));
                                }
                                if (hisItems.length != botItems.length) {
                                    console.log("Error: Unknown error");
                                } else {
                                    for (let i = 0; i < hisItems.length; i++) {
                                        if (hisItems[i] === undefined) {
                                            console.log("Error: Unknown partner item");
                                            return;
                                        }
                                    }
                                    for (let i = 0; i < botItems.length; i++) {
                                        if (botItems[i] === undefined) {
                                            console.log("Error: Unknown bot item");
                                            return;
                                        }
                                    }
                                    trade.addTheirItems(hisItems);
                                    trade.addMyItems(botItems);
                                    trade.setMessage("Steam Trade Matcher");
                                    trade.send((ERR) => {
                                        if (ERR) {
                                            console.log("An error occurred while sending trade: " + ERR);
                                        } else {
                                            console.log("Trade offer sent");
                                        }
                                    });
                                }
                            }
                        });
                    }
                });
            }
        });
    }
}
 
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...