Jump to content
McKay Development

cannot declined the wrong offer


Recommended Posts

Hi everyone. My bot works fine now but it seems didn't declined wrong offers. Anyone can help me would be very nice.

 

My code:

offers.on('newOffer', function (offer) {
manager.on("newOffer", function(offer) {
	var onlyKeys1 = (offer.itemsToReceive.every(function(item) {
		return item.name == "Mann Co. Supply Crate Key";
	}));
	var onlyRef1 = (offer.itemsToGive.every(function(item) {
		return item.name == "Refined Metal";
	}));
	var onlyKeys2 = (offer.itemsToGive.every(function(item) {
		return item.name == "Mann Co. Supply Crate Key";
	}));
	var onlyRef2 = (offer.itemsToReceive.every(function(item) {
		return item.name == "Refined Metal";
	}));
	if (onlyKeys1, onlyRef1) {
		keyAmount = offer.itemsToReceive.length
		refAmount = offer.itemsToGive.length == keyAmount * buyprice
		if (keyAmount == refAmount) {
		console.log("They are selling " + keyAmount + " keys for " + buyprice * keyAmount + " refined metal.");
		console.log("Accepting the trade offer.");
		offer.accept(function(err) {
		if (err) 
			console.log(err);
		else 
			console.log("Trade offer accepted.");
		});
	}		
	}
	if (onlyKeys2, onlyRef2) {
		keyAmount = offer.itemsToGive.length
		refAmount = offer.itemsToReceive.length == keyAmount * sellprice
		if (keyAmount == refAmount) {
		console.log("They are buying " + keyAmount + " keys for " + sellprice * keyAmount + " refined metal.");
		console.log("Accepting the trade offer.");
		offer.accept(function(err) {
		if (err) 
			console.log(err);
		else 
			console.log("Trade offer accepted.");
		});
	}
	}
	else console.log("Trade offer not validated. Declining");
		offer.decline(function(err) {
			if (err) console.log(err);
		});
	}
	})
	});
Link to comment
Share on other sites

I don't know what you are trying to do with the comma operator, but by the looks of it you want to use the and operator (&&) in your if (onlyKeys, onlyRef) checks...
 
if (onlyKeys2, onlyRef2) âž¡ if (onlyKeys2 && onlyRef2)
 
In regards to your declining offer thing... its probably to do with your lack of curly braces surrounding if and else e.g

if (x && y) {
	// code
} else {
	// code
} 

Not ...

if (x && y) // code
else // code 

What do these lines do/mean?

'refAmount = offer.itemsToGive.length == keyAmount * buyprice'

'refAmount = offer.itemsToReceive.length == keyAmount * sellprice'

 

Also, unless you want the refAmount and keyAmount to be global, you should really declare them with var ... keyAmount = offer.itemsToGive.length âž¡ var keyAmount =  offer.itemsToGive.length

 

Even though I am new to coding/scripting and I can see your code is very untidy/messy...

 

PS: What is offers.on('newOffer') ? and why is trade offer manager newOffer listener nested inside this???

Edited by adma
Link to comment
Share on other sites

I don't know what you are trying to do with the comma operator, but by the looks of it you want to use the and operator (&&) in your if (onlyKeys, onlyRef) checks...

 

if (onlyKeys2, onlyRef2) âž¡ if (onlyKeys2 && onlyRef2)

 

In regards to your declining offer thing... its probably to do with your lack of curly braces surrounding if and else e.g

if (x && y) {
	// code
} else {
	// code
} 

Not ...

if (x && y) // code
else // code 

What do these lines do/mean?

'refAmount = offer.itemsToGive.length == keyAmount * buyprice'

'refAmount = offer.itemsToReceive.length == keyAmount * sellprice'

 

Also, unless you want the refAmount and keyAmount to be global, you should really declare them with var ... keyAmount = offer.itemsToGive.length âž¡ var keyAmount =  offer.itemsToGive.length

 

Even though I am new to coding/scripting and I can see your code is very untidy/messy...

 

PS: What is offers.on('newOffer') ? and why is trade offer manager newOffer listener nested inside this???

Hi Adma,

sorry for that. but i have some questions...

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.

Edited by TextDynasty
Link to comment
Share on other sites

Maybe somethings wrong here?

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."));
        });
    }}        

(the buykeyprice set to 198 and this shows up when received offer)

Trade offer not validated. Declining
They offered 1 keys and 198 refined metals.
Edited by TextDynasty
Link to comment
Share on other sites

Whats wrong with my code??

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")
        return key++
    }));
    var FromRef1 = (offer.itemsToGive.forEach(function(item) {
        if (item.name == "Refined Metal")
        return metal += 9
        if (item.name == "Reclaimed Metal")
        return metal += 3
        if (item.name == "Scrap Metal")
        return metal++
    }));
  if (BuyKey && FromRef1) {
		
        if (metal == key) {
        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);
        });
    }
    });

Trade offer not validated. Declining
They offered 1 keys and 198 refined metals.
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...