Jump to content
McKay Development

Recommended Posts

i tried this way but it didn't increase the value of "currency" and "key"

var currency = 0
	var key = 0
	
	var BuyKey = (offer.itemsToReceive.every(function(item) {
		return item.name == "Mann Co. Supply Crate Key";
		key++
	}));
	var FromRef1 = (offer.itemsToGive.every(function(item) {
		return item.name == "Refined Metal";
		currency += 9
	}));
Link to comment
Share on other sites

every will stop executing as soon as it reaches an entry that doesn't return true. Also, return will stop executing the function immediately.

 

You want forEach, and don't return if the name matches the desired value. Instead, use that check in an if.

 Hi McKay, 

Do you know any problems in my script? It didn't seems working. Thanks a lot.

offers.on('newOffer', function (offer) {
manager.on("newOffer", function(offer) {
	var metal = 0
	var key = 0	
	var BuyKey = (offer.itemsToReceive.forEach(function(item) {
		if (item.name == "Mann Co. Supply Crate Key")
		key++
	}));
	var FromRef1 = (offer.itemsToGive.forEach(function(item) {
		if (item.name == "Refined Metal")
		metal += 9
	}));
	var FromRec1 = (offer.itemsToGive.forEach(function(item) {
		if (item.name == "Reclaimed Metal")
		metal += 3
	}));
	var FromScrap1 = (offer.itemsToGive.forEach(function(item) {
		if (item.name == "Scrap Metal")
		metal++
	}));
	
	if (BuyKey, FromRef1, FromRec1, FromScrap1) {
		sell = metal
		buy = key * buykeyprice
		if (sell == buy) {
		offer.accept(function(err) {
		if (err) 
			console.log(err);
		else 
			console.log("They are selling " + key + " keys for " + buy + " refined metal.");
			console.log(colors.red("Accepting the trade offer."));
			console.log(colors.green("Trade offer accepted."));
		});
	}
	
	if (sell != buy){
		console.log("Trade offer not validated. Declining");
		console.log("They offered " + key + " keys and " + metal + " refined metals. ")
		offer.decline(function(err) {
			if (err) console.log(err);
		});
	}}
	})
	});
Link to comment
Share on other sites

thanks for reply. i changed the comma to && but it didn't work too. : (

offers.on('newOffer', function (offer) {
manager.on("newOffer", function(offer) {
	var metal = 0
	var key = 0	
	var BuyKey = (offer.itemsToReceive.forEach(function(item) {
		if (item.name == "Mann Co. Supply Crate Key")
		key++
	}));
	var FromRef1 = (offer.itemsToGive.forEach(function(item) {
		if (item.name == "Refined Metal")
		metal += 9
	}));
	var FromRec1 = (offer.itemsToGive.forEach(function(item) {
		if (item.name == "Reclaimed Metal")
		metal += 3
	}));
	var FromScrap1 = (offer.itemsToGive.forEach(function(item) {
		if (item.name == "Scrap Metal")
		metal++
	}));
	
	if (BuyKey && FromRef1 && FromRec1 && FromScrap1) {
		sell = metal
		buy = key * buykeyprice
		if (sell == buy) {
		offer.accept(function(err) {
		if (err) 
			console.log(err);
		else 
			console.log("They are selling " + key + " keys for " + buy + " refined metal.");
			console.log(colors.red("Accepting the trade offer."));
			console.log(colors.green("Trade offer accepted."));
		});
	}
	
	if (sell != buy){
		console.log("Trade offer not validated. Declining");
		console.log("They offered " + key + " keys and " + metal + " refined metals. ")
		offer.decline(function(err) {
			if (err) console.log(err);
		});
	}}
	})
	});
Link to comment
Share on other sites

My bot keeps declining my offer even i offer the correct amount of metals.

manager.on("newOffer", function(offer) {
	var metal = 0
	var key = 0	
	
	var BuyKey = (offer.itemsToReceive.forEach(function(item) {
		if (item.name == "Mann Co. Supply Crate Key")
		key++
	}));
	var FromRef1 = (offer.itemsToGive.forEach(function(item) {
		if (item.name == "Refined Metal")
		metal += 9
		if (item.name == "Reclaimed Metal")
		metal += 3
		if (item.name == "Scrap Metal")
		metal++
	}));
	if (BuyKey, FromRef1) {
		if (metal = key * buykeyprice) {
		offer.accept(function(err) {
		if (err) 
			console.log(err);
		else 
			console.log("They are selling " + key + " keys for " + buykeyprice * key + " refined metal.");
			console.log(colors.red("Accepting the trade offer."));
			console.log(colors.green("Trade offer accepted."));
		});
	}}		
	else {
		console.log("Trade offer not validated. Declining");
		console.log("They offered " + key + " keys and " + metal + " refined metals. ")
		offer.decline(function(err) {
			if (err) console.log(err);
		});
	}
	});

When I sent a correct offer, it declines it ( my buying price is 198 )

Trade offer not validated. Declining
They offered 1 keys and 198 refined metals.

The calculation of metals works fine and it show it is correct amount but it keeps declining it.

Thanks McKay 

Edited by TextDynasty
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...