2015-04-02 55 views
-2

這裏是我的一段代碼蒸汽Tf2的貿易BOT Node.js加載問題

// 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 
      } 
     }); 
    }); 
}); 
+0

你有沒有登錄'item.name'? – 2015-04-02 17:21:55

+0

不,我不知道它到底是什麼,也許'Scrap Metal'item.name? – EEVV 2015-04-02 17:29:50

+0

@TomA請舉例? – EEVV 2015-04-02 17:31:20

回答

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

嘗試使用

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

謝謝,雖然相當晚,我會很快回到機器人 – EEVV 2015-09-26 14:21:17