Jump to content


Photo

How do you convert metals.

node.js node-steam-tradeoffer-manager

  • Please log in to reply
3 replies to this topic

#1 Yoki

Yoki

    Newbie

  • Member
  • Pip
  • 5 posts

Posted 15 February 2017 - 08:50 PM

Hi, I've been stuck with this issue for a while and can't figure any way around it, Right now I have a key bot and script is very simple -

it checks if all items offered are keys and all items I give is refined, but keys never are round number so my question is how do you make script recognize metals and they value - here's my current script:

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");
    console.log("Payed" + refAmmount "Refined metal per key.");
    console.log("Accepting the trade.");
    if (keyAmount == refAmount * 27.66)
    offer.accept(function(err) {
      if (err) console.log(err);
    });


#2 Dr. McKay

Dr. McKay

    Developer

  • Administrator
  • 1,282 posts

Posted 15 February 2017 - 09:38 PM

Déjà vu.



#3 Yoki

Yoki

    Newbie

  • Member
  • Pip
  • 5 posts

Posted 16 February 2017 - 10:57 AM

Yep, any help?



#4 TextDynasty

TextDynasty

    Advanced Member

  • Member
  • PipPipPip
  • 68 posts

Posted 18 February 2017 - 07:00 PM

Thanks for your help in my other question. I think this is what you want, getting the type of the metals and accept the offer right?

 

This is my script and I hope it can help a little bit.

//Price of items
//They are all in scrap
//Calculate it in : https://calculator.tf/
//sell order
var sellkeyprice = 249
var buykeyprice = 248



manager.on("newOffer", function(offer) {
	console.log(colors.bgBlue(timestamp("[hh:mm:ss] Incoming offer from " + offer.partner.toString())));

	var Rkey = 0
	var Gkey = 0
	var Gmetal = 0
	var Rmetal = 0

	var user = offer.partner.getSteam3RenderedID()
	
	offer.itemsToReceive.forEach(function(item) {
		if (item.name == "Mann Co. Supply Crate Key"){
			return Rkey++
		}
		else if (item.name == "Tour of Duty Ticket"){
			return RToD++
		}
		else if (item.name == "Refined Metal"){
			return Rmetal += 9
		}
		else if (item.name == "Reclaimed Metal"){
			return Rmetal += 3
		}
		else if (item.name == "Scrap Metal"){
			return Rmetal++
		}}
	);
	
	offer.itemsToGive.forEach(function(item) {
		if (item.name == "Mann Co. Supply Crate Key"){
			return Gkey++
		}
		else if (item.name == "Tour of Duty Ticket"){
			return GToD++
		}
		else if (item.name == "Refined Metal"){
			return Gmetal += 9
		}
		else if (item.name == "Reclaimed Metal"){
			return Gmetal += 3
		}
		else if (item.name == "Scrap Metal"){
			return Gmetal++
		}
	});
		
	//sell key
	if (Gkey > 0) {
		currency = Rmetal - Gmetal
		if (currency === Gkey * sellkeyprice + GToD * selltodprice) {
		offer.accept(function(err) {
		if (err) 
			console.log(err);
		else 
			console.log(colors.bgGreen(timestamp("[hh:mm:ss] Sold " + Gkey + " Keys and " + GToD + " Tour of Duty Tickets.")));
			console.log(colors.bgGreen(timestamp("[hh:mm:ss] Amount Correct! Accepting the trade offer.")));
			if (Gkey > 0) {
			client.chatMessage(admin, "Sold " + Gkey + " Mann Co. Supply Keys.");
			} else {
			client.chatMessage(admin, "Sold " + GToD + " Tour Of Duty Tickets.");
			}
			setTimeout(function() {client.chatMessage(user, "Thanks for using AshleyBot. http://steamcommunity.com/id/AshleyBot")}, 5000);
		});
	}
	else {
		offer.decline(function(err) {
			if (err)
				console.log(err);
				else 
					console.log(colors.bgRed(timestamp("[hh:mm:ss] Trade offer not validated. Declining")));
					client.chatMessage(admin, "They are buying it for " + currency + " Refined Metal.");
					client.addFriend(user);
					setTimeout(function() {client.chatMessage(user, "Your offer is incorrect. Please check it again or resent it later.")}, 10000);
		});
	}}
	
	//buy key
	else if (Rkey > 0) {
		currency = Gmetal - Rmetal
		if (currency === Rkey * buykeyprice + RToD * buytodprice) {
		offer.accept(function(err) {
		if (err) 
			console.log(err);
		else 
			console.log(colors.bgGreen(timestamp("[hh:mm:ss] Bought " + Rkey + " Keys and " + RToD + " Tour of Duty Tickets.")));
			console.log("Amount Correct! Accepting the trade offer.");
			if (Rkey > 0) {
			client.chatMessage(admin, "Bought " + Rkey + " Mann Co. Supply Keys.");
			} else {
			client.chatMessage(admin, "Bought " + RToD + " Tour Of Duty Tickets.");	
			}
			setTimeout(function() {client.chatMessage(user, "Thanks for using AshleyBot. http://steamcommunity.com/id/AshleyBot")}, 5000);
		});
	}
	else {
		offer.decline(function(err) {
			if (err) console.log(err);
				else 
					console.log("Trade offer not validated. Declining");
					client.chatMessage(admin, "They are selling it for " + currency + " Refined Metal.");
					client.addFriend(user);
					setTimeout(function() {client.chatMessage(user, "Your offer is incorrect. Please check it again or resent it later.")}, 15000);
		});
	}}
	
	//other offers will be declined
	else {
		offer.decline(function(err) {
			if (err) 
				console.log(err);
				else 
					console.log(colors.bgRed(timestamp("[hh:mm:ss] Trade offer not validated. Declining")));
					client.chatMessage(admin, "User provided a wrong offer. Declined.");
					client.addFriend(user);
					setTimeout(function() {client.chatMessage(user, "Your offer is incorrect. Please check it again or resent it later.")}, 15000);
		});
	}});

And also one more question if you can help me a bit. I don't know how to craft any metal by the bot


Edited by TextDynasty, 18 February 2017 - 07:01 PM.






Also tagged with one or more of these keywords: node.js, node-steam-tradeoffer-manager

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users