Steam Tf2交易BOT Node.js问题

时间:2015-04-02 16:32:15

标签: node.js steam

这是我的一段代码

// Any time an item changes in the trade window
trade.on('offerChanged', function(itemAdded, item) {
if (itemAdded) {
    logger.info('User added: '+item.name)
    if (item.name == 'Festive Black Box') {
        trade.chatMsg('Cool!');
        trade.addItem('Scrap Metal');
    }
}

所以,基本上我的兄弟将这个项目放入(节日黑匣子),它应该放一个废料,但它没有,而是说"酷!" (所以我知道它有效)并且机器人没有插入废料,我等了很长时间,似乎没有用,我的库存中只有一块废金属!

以下是我的一些代码;

// After we accept the trade, we deal with the trade session
client.on('sessionStart', function(steamID) {
    inTrade = true;
    client.setPersonaState(steam.EPersonaState.Busy);
    trade.open(steamID, function() { // Pass the trade off to our steam-trade library
    trade.loadInventory(appid.TF2, contextid.TF2, function(inv) {
        inventory = inv;
        scrap = inv.filter(function(item) { return item.name == 'Scrap Metal';});
        logger.error(scrap)
            if (!inv) {
                logger.error('Error getting own inventory.  Cancelling trade.');
                client.sendMessage(steamID, 'Could not load my inventory, please contact my creator.');
                trade.cancel(steamID);
            } else {
                logger.debug('Found '+inv.length+' items in my inventory.');
                myBackpack = inv; // Now we can access it globally
                // If you want to put items up in the trade window immediately,
                // here is where you could do it. Instead we're calling a custom function.
                onTradeStart(steamID); // Our custom function
            }
        });
    });
});

2 个答案:

答案 0 :(得分:0)

尝试使用

scrap = inv.filter(function(item) { 
     return item.tags.some(function(element, index, array) {
            return element.internal_name == 'Scrap Metal';
     });
});

答案 1 :(得分:-1)

我们走了:

// Any time an item changes in the trade window
trade.on('offerChanged', function(itemAdded, item) {
    if (itemAdded) {
        logger.info('User added: '+item.name)
        if (item.name == 'Festive Black Box') {
            trade.chatMsg('Cool!');
            trade.addItem('Scrap Metal');
            logger.info(trade.addItems(scrap));
        }
    }
    //if (itemAdded)
    //    logger.info('User added: '+item.name);
    //else
    //    logger.info('User removed: '+item.name);
});