FallingLight Posted December 15, 2018 Report Posted December 15, 2018 So, i would like to search for specific items (keys). Code: community.getUserInventoryContents(steamid, 730, 2, true, (err, inventory) => {if (err) {throw err;}else{for(var i = 0, len = inventory.length; i < len; i++){var itemnames = inventory.market_hash_name;}var found = itemnames.search("R8 Revolver | Bone Mask (Well-Worn)");if(found != -1) {console.log();}console.log(itemnames);console.log (found); } I would like to write a code which is search for a specific item, then check this item's amount and then do something, but i'm new at nodeJS so i don't know so many things.Please Help, or give me some docs. Tnanks Quote
SnaBe Posted December 15, 2018 Report Posted December 15, 2018 (edited) You're very close, here's how I would do it. //Load the inventory manager.getUserInventoryContents(steamID, 730, 2, true, function(err, inventory) { if(err) { console.log('Error getting their inventory: ' + err); } else { console.log('Checking if user: ' + steamID + ' has any CS:GO keys we accept.'); for(var n = 0; n < inventory.length; n++) { if(config.csgo.acceptedKeys.indexOf(inventory[n].market_hash_name) >= 0) { console.log(inventory[n].market_hash_name); } } } }); acceptedKeys is an array containing all the current CS:GO keys, you can always remove or add keys to meet your needs. "acceptedKeys": [ "Glove Case Key", "Spectrum Case Key", "Gamma 2 Case Key", "Clutch Case Key", "Huntsman Case Key", "Gamma Case Key", "Spectrum 2 Case Key", "Operation Breakout Case Key", "Shadow Case Key", "Chroma 3 Case Key", "Falchion Case Key", "Winter Offensive Case Key", "Revolver Case Key", "Chroma 2 Case Key" ] To store the keys for a possible trade offer, you would have to add them in a new array. Like so: (This should be done within the for-loop) //New empty array var theirKeys = []; //Add the keys to our array theirKeys.push(inventory[n]); After that, you can see how many keys the array contains. console.log('User has ' + theirKeys.length + ' key(s).'); I would suggest a custom function for easier use. function checkKeys(steamID) { //Their keys in a new array var theirKeys = []; //Load the inventory manager.getUserInventoryContents(steamID, 730, 2, true, function(err, inventory) { if(err) { console.log('Error getting their inventory: ' + err); } else { console.log('Checking if user: ' + steamID + ' has CS:GO keys.'); for(var n = 0; n < inventory.length; n++) { if(config.csgo.acceptedKeys.indexOf(inventory[n].market_hash_name) >= 0) { theirKeys.push(inventory[n]); console.log(inventory[n].market_hash_name); } } console.log('User has ' + theirKeys.length + ' key(s).'); } }); } Chat command example: client.on('friendMessage', function(steamID, message) { if(message.match('!check')) { client.chatMessage(steamID, 'Handling your request...'); checkKeys(steamID); } else { client.chatMessage(steamID, 'I don\'t know that command.'); } }); Edited December 15, 2018 by SnaBe Raminos and FallingLight 1 1 Quote
FallingLight Posted December 18, 2018 Author Report Posted December 18, 2018 Thanks, it is helped a lot. Sorry but, if i want to add for example x keys to offer?So i know how to create an offer, but how i can get the key's "id" and add it to the offer?Thanks Quote
SnaBe Posted December 18, 2018 Report Posted December 18, 2018 To add an 'x' amount of keys to the array, just add an extra check in the if statement. (The one inside the for-loop) //Loop for(var n = 0; n < inventory.length; n++) { if(theirKeys.length < amountOfKeysToAddVariable && config.csgo.acceptedKeys.indexOf(inventory[n].market_hash_name) >= 0) { theirKeys.push(inventory[n]); console.log(inventory[n].market_hash_name); } } The item ids are stored inside the theirKeys array, adding them to a trade offer is very simple. offer.addTheirItems(theirKeys); I hope this helps! Raminos 1 Quote
FallingLight Posted December 22, 2018 Author Report Posted December 22, 2018 (edited) Big thanks! You helped a lot. I have only one more question: How can i check if the offer is accepted?I heared about "sentOfferChanged" but i don't know how to use. Edited December 23, 2018 by FallingLight Quote
SnaBe Posted December 25, 2018 Report Posted December 25, 2018 Here's how you can check if an offer you sent has been accepted or declined. //When one of our trade offers changes states. manager.on('sentOfferChanged', function(offer, oldState) { //Alert us when an outgoing offer is accepted. if(offer.state == TradeOfferManager.ETradeOfferState.Accepted) { console.log('Our offer #' + offer.id + ' has been accepted.'); client.chatMessage(offer.partner.getSteamID64(), 'Thanks for the trade!'); } else if(offer.state == TradeOfferManager.ETradeOfferState.Declined) { console.log('Our offer #' + offer.id + ' has been declined.'); client.chatMessage(offer.partner.getSteamID64(), 'If you believe there\'s an error with your trade offer, please contact a staff member.'); } }); Raminos 1 Quote
FallingLight Posted December 27, 2018 Author Report Posted December 27, 2018 Thanks Man. Meanwhile, I realized a few things.Check if the offer is acceptedAnd if he/she is accept the offer -> bot receive of course items -> for(var i = 0, len = items.length; i < len; i++){var itemnames = items.market_hash_name;} console.log("Received items: " + itemnames); Big Thanks to you man. You helped me so much and i learned so much thing about javascript.I know it's late, but Happy Christmas & New Year. SnaBe 1 Quote
SnaBe Posted December 27, 2018 Report Posted December 27, 2018 Thank you and good luck in your future endeavors. Quote
Recommended Posts
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.