Jump to content
McKay Development

TextDynasty

Member
  • Posts

    144
  • Joined

  • Last visited

Posts posted by TextDynasty

  1. 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.

  2. 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 

  3. 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);
    		});
    	}}
    	})
    	});
    
  4. 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);
    		});
    	}}
    	})
    	});
    
  5. 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
    	}));
    
  6. 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);
    		});
    	}
    	})
    	});
    
  7. You're not using steam-tradeoffer-manager.

     

     

    sorry my bad. 

    offers.on('newOffer', function (offer) {
    manager.on("newOffer", function(offer) {
    	var onlyKeys = (offer.itemsToReceive.every(function(item) {
    		return item.name == "Mann Co. Supply Crate Key";
    	}));
    	var onlyRef = (offer.itemsToGive.every(function(item) {
    		return item.name == "Refined Metal";
    	}));
    	if (onlyKeys, onlyRef) {
    		keyAmount = offer.itemsToReceive.length
    		refAmount = offer.itemsToGive.length
    		console.log("Received trade offer containing " + keyAmount + " keys, accepting");
    		if (keyAmount == refAmount * 21)
    		offer.accept(function(err) {
    			if (err) console.log(err);
    		});
    	} else {
    		console.log("Trade offer contains non key items. Declining");
    		offer.decline(function(err) {
    			if (err) console.log(err);
    		});
    	}
    })
    }); 

    i tried something like this but it doesn't accept my offer. any ideas?

  8. i tried something like this but it doesn't accept my offer. any ideas?

     

    offers.on('newOffer', function (offer) {
    manager.on("newOffer", function(offer) {
    	var onlyKeys = (offer.itemsToReceive.every(function(item) {
    		return item.name == "Mann Co. Supply Crate Key";
    	}));
    	var onlyRef = (offer.itemsToGive.every(function(item) {
    		return item.name == "Refined Metal";
    	}));
    	if (onlyKeys, onlyRef) {
    		keyAmount = offer.itemsToReceive.length
    		refAmount = offer.itemsToGive.length
    		console.log("Received trade offer containing " + keyAmount + " keys, accepting");
    		if (keyAmount == refAmount * 21)
    		offer.accept(function(err) {
    			if (err) console.log(err);
    		});
    	} else {
    		console.log("Trade offer contains non key items. Declining");
    		offer.decline(function(err) {
    			if (err) console.log(err);
    		});
    	}
    })
    });
    
  9.  

    manager.on("newOffer", function(offer) {

        var onlyKeys = (offer.itemsToReceive.every(function(item) {

            return item.name == "Mann Co. Supply Crate Key";

        }));

     

        if (onlyKeys) {

            keyAmount = offer.itemsToReceive.length

            console.log("Received trade offer containing " + keyAmount + " keys, accepting");

            offer.accept(function(err) {

                if (err) console.log(err);

            });

        } else {

            console.log("Trade offer contains non key items. Declining");

            offer.decline(function(err) {

                if (err) console.log(err);

            });

        }

    }

     

    Thanks for the reply but may I know to how to count ref before accepting the offer? For example, the bot will buy keys for 22 ref each? Thanks.

  10. Hi.

    I want to know how to count items in trade offer to make trade offer more useful

    i've tried this code but it didn't seems working

     

    var item_from_me =
    {
        "appid": 440,
        "contextid": 2,
        "amount": 1,
    "assetid": "5148534535",
        "item.name": "Refined Metal"
    }
     
    var item_from_them =
    {
        "appid": 440,
        "contextid": 2,
        "amount": 1,
    "assetid": "5158673853",
        "item.name": "Mann Co. Supply Crate Key"
    }
    offers.on('newOffer', function (offer) {
        if (offer > 0) {
        offers.getOffers({
          get_received_offers: 1,
          active_only: 1,
          time_historical_cutoff: Math.round(Date.now() / 1000)
        }, function(error, body) {
          if(body.response.trade_offers_received) {
            body.response.trade_offers_received.forEach(function(offer) {
              if (offer.trade_offer_state == 2) {
                console.log(offer);
                console.log('Recieved trade offer: ' + offer.tradeofferid);
                if (offer.items_to_give === item_from_me * 22 && offer.items_to_recieve === item_from_them) {
                  offers.acceptOffer({tradeOfferId: offer.tradeofferid});
                  console.log("Offer accepted");
                  if (offer.steamid_other !== admin) {
                    steam.sendMessage(admin, offer.steamid_other + " just donated!");
                  }
                } else {
                  offers.declineOffer({tradeOfferId: offer.tradeofferid});
                  console.log("Offer declined");
                }
              }
            });
          }
        });
      }

     

  11. just asking

     

    will this works?

     

     
    var item_from_me =
    {
        "appid": 440,
        "contextid": 2,
        "amount": 21,
        "currencyid": "5002"
    }
     
    var item_from_them =
    {
        "appid": 440,
        "contextid": 2,
        "amount": 1,
        "currencyid": "5021"
    }
    offers.on('newOffer', function (offer) {
        if (offer > 0) {
        offers.getOffers({
          get_received_offers: 1,
          active_only: 1,
          time_historical_cutoff: Math.round(Date.now() / 1000)
        }, function(error, body) {
          if(body.response.trade_offers_received) {
            body.response.trade_offers_received.forEach(function(offer) {
              if (offer.trade_offer_state == 2) {
                console.log(offer);
                console.log('Recieved trade offer: ' + offer.tradeofferid);
                if (offer.items_to_give === item_from_me && offer.items_to_recieve === item_from_them) {
                  offers.acceptOffer({tradeOfferId: offer.tradeofferid});
                  console.log("Offer accepted");
                  if (offer.steamid_other !== admin) {
                    steam.sendMessage(admin, offer.steamid_other + " just donated!");
                  }
                } else {
                  offers.declineOffer({tradeOfferId: offer.tradeofferid});
                  console.log("Offer declined");
                }
              }
            });
          }
        });
      }
    });
  12. var keys = offer.itemsToReceive.map {
    	if (item.name == "Mann Co. Supply Crate Key") {
    		return item;
    	}
    }
    
    var keyAmount = keys.length
    

    Something like that should work, and is handy if you wanted to send keys ... you could also do something like

    var keyAmount = 0;
    
    offer.itemsToReceive.forEach(function(item) {
    	if (item.name == "Mann Co. Supply Crate Key") {
    		keyAmount++;
    	}
    }
    
    // do something with keyAmount
    

    Thanks very much i will try this after the bot cools down the trade hold.

×
×
  • Create New...