Jump to content
McKay Development

How to only accept CSGO keys in 'newOffer'


Coyeks

Recommended Posts

Alright so the title says it all, i'm fairly new to Steam bots.

 

I'm trying to make it so it only accepts CSGO keys i know the code below is horrible, but if someone could point me in the right direction it would help a lot.

offers.on('newOffer', function (offer) {
    console.log("New offer #"+ offer.id +" from "+ offer.partner.getSteam3RenderedID());
	
	// Accept any trade offer from Admin.
    if (offer.partner.getSteamID64() === config.admin && appid === appid.CSGO){
        console.log("ADMIN offered a trade. Trying to accept offer.");
        offer.accept(function (err) {
            if (err) {
                console.log("Unable to accept offer "+ offer.id +": " + err.message);
            } else {
                console.log("Offer accepted because ADMIN sent the offer");
            }
        });
    }
	else { //Otherwise deny it and message the user
        console.log("User "+ offer.partner.getSteam3RenderedID() +" offered an invalid trade.  Declining offer.");
        offer.decline(function (err) {
            if (err) {
                console.log("Unable to decline offer "+ offer.id +": " + err.message);
            } else {
                console.log("Offer declined");
                // Message the user
                client.chatMessage(offer.partner.getSteamID64(), "Invalid offer.");
            }
        });
    }
});

I know it also only accepts if its the admin, that's just for testing.

Link to comment
Share on other sites

Set a language in your constructor if you haven't already, and then the item should have a name property you can check.

 

Hey, thanks fro the reply, i have a language set and could you possibly give an example of how to check the name in the code i provided above? thanks :)

Link to comment
Share on other sites

offer.itemsToReceive contains an array of the items you'd receive if you accepted this offer. For each item in this array, check appid to make sure it's CS:GO and name to make sure it's a key. For example:

var allItemsAreGood = offer.itemsToReceive.every(function(item) { return item.appid == 730 && item.name == "CS:GO Case Key"; });
Link to comment
Share on other sites

 

offer.itemsToReceive contains an array of the items you'd receive if you accepted this offer. For each item in this array, check appid to make sure it's CS:GO and name to make sure it's a key. For example:

var allItemsAreGood = offer.itemsToReceive.every(function(item) { return item.appid == 730 && item.name == "CS:GO Case Key"; });

 

Thank you, appreciate it.

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