Jump to content
McKay Development

Recommended Posts

ERROR

"uri": "https://steamcommunity.com/inventory/" + userID.
getSteamID64() + "/" + appID + "/" + contextID,

^

TypeError: Cannot read property 'getSteamID64' of null

My code

function sendRec(steamID, amount){
	if (!amount) {
        var amount = 1;
    }
	if (amount == 0) {
		console.log("User didn't provide a correct amount!");
		return;
	}
	
	manager.getUserInventoryContents(steamID, 440, 2, true, function (err, inventory){
		if (err) {
			console.log(err);
		} else {
			var scrap = inventory.filter(function (item) {
				return item.name == "Scrap Metal"
			});
			
			var refined = inventory.filter(function (item) {
				return item.name == "Refined Metal"
			});
				
			var NeededS = amount * 3
			var NeededR = amount / 3
			
			if (scrap.length === 0 && refined.length === 0){
				client.chatMessage(steamID, "It seems you don't have enough scrap.");
				return;
			} else if (amount > NeededS && amount > NeededR) {
				client.chatMessage(steamID, "You don't have enough scrap. You'll need " + left + " more scrap metals.");
				return;
			} else if (amount <= NeededS || amount <= NeededR) {
				manager.getInventoryContents(440, 2, true, function (err, inventory){
					if (err) {
						console.log(err);
					} else {
						var pool = inventory.filter(function (item) {
								return item.name == "Reclaimed Metal"
						});

						// Let the user know we don't have any
						if (pool.length === 0) {
							client.chatMessage(steamID, "I don't have available.  Sorry!");
							return;
						} else if (amount > pool.length) {
							console.log("User asked for more than my backpack.");
							client.chatMessage(steamID, "I only have " + pool.length + " available.  Sorry!");
							return;
						} else if (amount <= pool.length) {
							
							// Start a new trade offer
							var trade = manager.createOffer(steamID);
							
							// Add what we should to the current trade
							console.log("Adding " + amount + " rec.");
							
							
							if (scrap.length < NeededS) {
								if (Number.isInteger(NeededR) == false){
									return;
								} else {
									console.log("User doesn't have enough scrap. Sending REF OFFER!!");
									//USER ITEMS
									for (let i = 0; i < NeededR; i++) {
										trade.addTheirItem(refined[i]);
									}
									//BOT ITEMS
									for (let i = 0; i < amount; i++) {
										trade.addMyItem(pool[i]);
									}
								}							
							} else {
								console.log("User have enough scrap. Sending SCRAP OFFER!!");
								//USER ITEMS
								for (let i = 0; i < NeededS; i++) {
									trade.addTheirItem(scrap[i]);
								}
								//BOT ITEMS
								for (let i = 0; i < amount; i++) {
									trade.addMyItem(pool[i]);
								}
							}
							
							trade.setMessage("Here is your " + amount + " reclaimed metals");
							trade.send(function(err, status) {
								if (err) {
									console.log(err);
										return;
								} else if (status == 'pending') {
									console.log("Offer " + trade.id + "have been sent.");
									community.startConfirmationChecker(15 * 1000, config.identity);
									client.chatMessage(steamID, "Processing.");
									client.chatMessage(steamID, "Offer Sent!! Check your trade offer by here https://steamcommunity.com/tradeoffer/" + trade.id + "/.");
								} 
							});				
						}
					}
				});
			}
		}
	})
}
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...