Majok Posted July 23, 2019 Report Posted July 23, 2019 Hi, if someone can help me out with this i dont rl know how to build this and i created such a mess here with all of this code... I tryed to search up everywhere and i cant find similar problem... I have prices database in database.json file witch bot loads and then u can acces to !prices <item name>, similar to that i created !buy <item name> command witch is triggered when user insert name of item witch exist in database.json and in bots inventory(inventory.json)... After that bot needs to create offer with this items witch are selected...There i start having some issues. Down is my messed code if someone can explain what im doing wrong, and how i can make trade offer with selected items for price thats inside of database by chat command ? } else if (command === "!buy" && itemName) { const database = JSON.parse(fs.readFileSync('./database.json', 'utf8')); if(database[itemName]) { const buyPrice = database[itemName].sell; const sellPrice = database[itemName].sell.metal let offer = manager.createOffer("https://steamcommunity.com/tradeoffer/new/?partner=12345678&token=xxxxxxxx"); let t = manager.createOffer(steamID.getSteamID64()); t.getUserDetails((ERR, ME, THEM) => { if (ERR) { console.log("## An error occurred while getting trade holds: " + ERR); client.chatMessage(steamID, "An error occurred while getting your trade holds. Please try again"); } else if (ME.escrowDays == 0 && THEM.escrowDays == 0) { client.chatMessage(steamID, "Processing your request."); manager.getUserInventoryContents(steamID.getSteamID64(), 440, 2, true, (ERR, INV, CURR) => { offer.addTheirItems(INV); offer.addMyItems(INV); var MyItems = require(`./Inventory.JSON`); offer.send(function(err, status) { }, client.chatMessage(steamID, "Prepairing offer...")); if (ETradeOfferState == 12) { console.log(`Offer #${offer.id} sent, but requires confirmation`); community.acceptConfirmationForObject("identitySecret", offer.id, function(err) { if (err) { console.log(err); } else { console.log("Offer confirmed"); } }); } else { console.log(`Offer #${offer.id} sent successfully`); client.chatMessage(steamID, `Trade offer created ! [ offer ID: ${offer.id} ]`); } if (ERR) { console.log("## An error occurred while getting inventory: " + ERR); client.chatMessage(steamID, "An error occurred while loading your inventory. Please try later, or check if your inventory isnt on private ! \n If is that not case error is caused by Steam servers witch seems to be offline... \n Try to sent offer with up given price at link:\n https://steamcommunity.com/tradeoffer/new/?partner=xxxxxxxx "); } }); } }); Quote
SnaBe Posted July 23, 2019 Report Posted July 23, 2019 (edited) Alright, there's primarily to parts of creating a systen like this. 1. Handling chat commands / buy & sell requests from Steam chat.2. Searching inventories for the required items and creating the trade offer. Luckily for you, other users have had similar questions regarding this topic. Here's an entry regarding chat commands. Here's an entry regarding looping trough the inventory and looking for item matches. I hope this helps! Edited July 23, 2019 by SnaBe Dr. McKay 1 Quote
Majok Posted July 23, 2019 Author Report Posted July 23, 2019 Alright, there's primarily to parts of creating a systen like this. 1. Handling chat commands / buy & sell requests from Steam chat.2. Searching inventories for the required items and creating the trade offer. Luckily for you, other users have had similar questions regarding this topic. Here's an entry regarding chat commands. Here's an entry regarding looping trough the inventory and looking for item matches. I hope this helps! Well, i think u didn't understand me i don't build system such as on lvlup bot or just specified items bot so i can use .market_hash_name to define witch keys or stuff it accepts... I need to link it into database and make him put in offer how many metal it need + item witch bot trade to person... I already saw this posts and why you think if they can solve my problem i made new post ? I searched every single forum and stuff and i cant find anything similar. If i try to follow some guide on github for this specific module but it seems like its rl outdated since im getting errors inside of bot modules, im using newer version of module then when this guide was made.Here again:I need to create system witch will with command triggered when called by name of item existing in database & bots inventory creates trade offer with item witch is called by command and enough currency based on database (ref metal in this situtation), thats why i simply cannot use ..market_hash_name... Bot already understands how much 1 ref =, 1 rec =, 1 scrap is...If i used .market_hash_name it can be either 1,2,3,4,5 ref in offer not 2.33 for example. Quote
SnaBe Posted July 23, 2019 Report Posted July 23, 2019 What I posted is the basics you need to know for creating commands & trades. But since you're looking for an example that solves your exact problem, this old post of mine might help. I wanted to loop trough an inventory and add the correct metal for a specific amount of Mann Co. Keys, after this I can create the trade offer. You don't see this in the post, but if you read the steam-tradeoffer-manager documentation you should be able to do it. Or just use parts of your posted code. There's not many cases out there where users have published their code for solving a specfic problem you might have. You need to use your knowlegde of NodeJS, the modules you're using and code a solution yourself. But here's how I would do it: If the item you got from the command is in your JSON file, save the price in a local varaible. Loop trough an inventory, find the items until the amount match the metal price of the item and parse them to an array. Calculating this is simple math, you can always look at my post for refference. Now you can create an offer with the createOffer method. With the theirKeys array used in the example, you've the assetids of the keys (this can be apllied for any item in Valve's games.) in the array. You just need to use the addMyItems or addTheirItems methods of the module and parse the array as an argument. This is all you need to add items to a trade offer, after this, simply send and confirm the offer. Again make use of the methods of the steam-tradeoffer-manager module. I hopes this helps! 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.