DoctorMcKay / node-tf2

Simple module to interact with the TF2 game coordinator
https://www.npmjs.com/package/tf2
MIT License
54 stars 26 forks source link

Code example #3

Open crazydenix opened 9 years ago

crazydenix commented 9 years ago

Hello. Can you give example code for delete crates? I'm sorry, but I'm newbe to this issue

DoctorMcKay commented 9 years ago

That's pretty low on my priority list. Just listen for the backpackLoaded event then console.log(tf2.backpack) to see a raw dump of your backpack contents. That should get you started.

kjsmita6 commented 9 years ago

I know this is kind of old, but one way to delete all the crates in your inventory is to add this function to your code and call it anywhere (like when you send a message, "!delete" for example).

function deleteCrates() {
    var crates;
    steamTrade.loadInventory(440, 2, function(inv) {
        crates = inventory.filter(function (item) {
            return item.tags.some(function(element, index, array) {
                return element.internal_name == 'Supply Crate';
            });
        });
    });
    if(crates.length > 0) {
        bot.gamesPlayed([440]);
        for(var i = 0; i < crates.length; i++) {
            tf2.deleteItem([crates[i].id]);
        }
    }
};

Where bot is an instance of node-steam, steamTrade is an instance of node-steam-trade, and tf2 is an instance of node-tf2 (this module).

DoctorMcKay commented 9 years ago

It would be better to use node-tf2's cached backpack.