Jump to content
McKay Development

Sending trade offer with gems


Recommended Posts

Hi, so I'm making a bot that send the user a trade offer with 350 gems, but the problem is that it's my first time using JS, so I find it kinda difficult to do it...

 

I found this online but I don't understand it at all....:

                                           manager.getUserInventoryContents(steamID, 753, 6, true, (err, inv) => {
						if (err) {
							throw err;
						}
						
						let gems = inv.filter(item => item.market_hash_name == "Gems");
						let item = gems[0];
						item.amount = 350;
						offer.addMyItem(item);
					
						offer.send(function(err, status) {
							if (err) {
								console.log(err);
								return;
							}

							//Some code
						});					
					});

But the problem is that I need:

 

1. Check if the user has at least 350 Gems or more in their inventory

2. Send the trade offer with the 350 gems

 

So I basically have no idea how to do it...

 

Anyone can help me out?

 

Thanks.

Edited by DGVaniX
Link to comment
Share on other sites

What you have there will work provided the user does have 350 gems in their first gem stack. It's possible to have multiple gem stacks, so you'd need to iterate the gems array and total up all the amounts to see how much the user has, then add the appropriate amount from each stack if they do.

Link to comment
Share on other sites

What you have there will work provided the user does have 350 gems in their first gem stack. It's possible to have multiple gem stacks, so you'd need to iterate the gems array and total up all the amounts to see how much the user has, then add the appropriate amount from each stack if they do.

Thanks for the reply.

 

I don't really understand what you said there... I'm not really a programmer so I don't really know the terminology. How do I 'iterate' the array? And how do I add gems from each stack?

 

Thanks.

 

--- EDIT

 

So I've googled this a bit and found some codes and I tried to use those examples but its TOO CONFUSING, I don't understand how to do it...

manager.getUserInventoryContents(steamID, 753, 6, true, function(err, inv) {
				if (err) {
					bot.chatMessage(steamID, "An error occurred while loading your inventory. Please try later");
				}else{
					if (ERR) {
                        client.chatMessage(steamID, "An error occurred while loading your inventory. Please try later");
                    } else {
                        var gemsAmount = 0;
						var botGems = [];
						for (var i = 0; i < inv.length; i++) {
                            if (CONFIG.STEAMGEMS.indexOf(inv[i].market_hash_name) >= 0) { //Don't know what to put in 'CONFIG.STEAMGEMS', I just copy/pasted
                                botgems = inv[i].amount;
                                gemsAmount = INV[i].amount;
                                inv[i].amount = itemAmount
                                botGems.push(inv[i]);
                                break;
                            }
                        }
                        if (botgems < itemAmount) {
                            client.chatMessage(steamID, "You don't have enough gems to send. (You have " + botgems + " gems)");
						} else {
                            t.addTheirItems(botgems);
                            t.send();
                            client.chatMessage(steamID, "You sent me " + itemAmount + " gems.");
                        }
Edited by DGVaniX
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...