Jump to content
McKay Development

[HELP] how to continue?


Recommended Posts

So, i would like to search for specific items (keys).
 
Code:
 
community.getUserInventoryContents(steamid, 730, 2, true, (err, inventory) => {
if (err) {
throw err;
}else{
for(var i = 0, len = inventory.length; i < len; i++){
var itemnames = inventory.market_hash_name;
}
var found = itemnames.search("R8 Revolver | Bone Mask (Well-Worn)");
if(found != -1) {
console.log();
}
console.log(itemnames);
console.log (found);
 
}
 
I would like to write a code which is search for a specific item, then check this item's amount and then do something, but i'm new at nodeJS so i don't know so many things.
Please Help, or give me some docs. Tnanks

 

Link to comment
Share on other sites

You're very close, here's how I would do it.

//Load the inventory
manager.getUserInventoryContents(steamID, 730, 2, true, function(err, inventory) {
  if(err) {
    console.log('Error getting their inventory: ' + err);
  } else {
    console.log('Checking if user: ' + steamID + ' has any CS:GO keys we accept.');
    for(var n = 0; n < inventory.length; n++) {
      if(config.csgo.acceptedKeys.indexOf(inventory[n].market_hash_name) >= 0) {
        console.log(inventory[n].market_hash_name);
      }
    }
  }
});

acceptedKeys is an array containing all the current CS:GO keys, you can always remove or add keys to meet your needs.

"acceptedKeys": [
  "Glove Case Key",
  "Spectrum Case Key",
  "Gamma 2 Case Key",
  "Clutch Case Key",
  "Huntsman Case Key",
  "Gamma Case Key",
  "Spectrum 2 Case Key",
  "Operation Breakout Case Key",
  "Shadow Case Key",
  "Chroma 3 Case Key",
  "Falchion Case Key",
  "Winter Offensive Case Key",
  "Revolver Case Key",
  "Chroma 2 Case Key"
] 

To store the keys for a possible trade offer, you would have to add them in a new array. Like so: 

(This should be done within the for-loop)

//New empty array
var theirKeys = [];
//Add the keys to our array 
theirKeys.push(inventory[n]);	

After that, you can see how many keys the array contains.

console.log('User has ' + theirKeys.length + ' key(s).');

I would suggest a custom function for easier use.

function checkKeys(steamID) {
  //Their keys in a new array
  var theirKeys = [];
  //Load the inventory
  manager.getUserInventoryContents(steamID, 730, 2, true, function(err, inventory) {
    if(err) {
      console.log('Error getting their inventory: ' + err);
    } else {
      console.log('Checking if user: ' + steamID + ' has CS:GO keys.');
      for(var n = 0; n < inventory.length; n++) {
        if(config.csgo.acceptedKeys.indexOf(inventory[n].market_hash_name) >= 0) {
          theirKeys.push(inventory[n]); 
          console.log(inventory[n].market_hash_name);
        }
      }
      console.log('User has ' + theirKeys.length + ' key(s).');
    }
  });
}

Chat command example:

client.on('friendMessage', function(steamID, message) {
  if(message.match('!check')) {
    client.chatMessage(steamID, 'Handling your request...');
    checkKeys(steamID);
  } else {
  	client.chatMessage(steamID, 'I don\'t know that command.');
  }
});
Edited by SnaBe
Link to comment
Share on other sites

To add an 'x' amount of keys to the array, just add an extra check in the if statement. (The one inside the for-loop)

//Loop
for(var n = 0; n < inventory.length; n++) {
  if(theirKeys.length < amountOfKeysToAddVariable && config.csgo.acceptedKeys.indexOf(inventory[n].market_hash_name) >= 0) {
    theirKeys.push(inventory[n]); 
    console.log(inventory[n].market_hash_name);
  }
}

The item ids are stored inside the theirKeys array, adding them to a trade offer is very simple.

offer.addTheirItems(theirKeys);

I hope this helps!

Link to comment
Share on other sites

Here's how you can check if an offer you sent has been accepted or declined.

//When one of our trade offers changes states.
manager.on('sentOfferChanged', function(offer, oldState) {
  //Alert us when an outgoing offer is accepted.
  if(offer.state == TradeOfferManager.ETradeOfferState.Accepted) {
    console.log('Our offer #' + offer.id + ' has been accepted.');
    client.chatMessage(offer.partner.getSteamID64(), 'Thanks for the trade!');
  } else if(offer.state == TradeOfferManager.ETradeOfferState.Declined) {
    console.log('Our offer #' + offer.id + ' has been declined.');
    client.chatMessage(offer.partner.getSteamID64(), 'If you believe there\'s an error with your trade offer, please contact a staff member.');
  }
});

Link to comment
Share on other sites

Thanks Man. Meanwhile, I realized a few things.

Check if the offer is accepted

And if he/she is accept the offer -> bot receive of course items ->

 

for(var i = 0, len = items.length; i < len; i++){
var itemnames = items.market_hash_name;
}
 
console.log("Received items: " + itemnames);
 
Big Thanks to you man. You helped me so much and i learned so much thing about javascript.
I know it's late, but Happy Christmas & New Year.
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...