Question

In Jassecar's SteamBot, is there a way to count items of different defindexes and add them up? I tried this:

switch(message.ToLower())
{
    case "ticket":
        foreach (ulong id in Trade.OtherOfferedItems)
        {
            int totalScrap = 0;
            Trade.SendMessage("Please pay 3.44 ref");

            var items = Trade.OtherOfferedItems;
            var itemType = Trade.OtherInventory.GetItem(id);

            if (itemType.Defindex == 5002)
            {
                totalScrap = items.Count * 9;
            }
            else if (itemType.Defindex == 5001)
            {
                totalScrap = items.Count * 3;
            }
            else if (itemType.Defindex == 5000)
            {
                totalScrap = items.Count;
            }


            Trade.RemoveAllItems();
            if (totalScrap > 31)
            {
                Trade.AddItemByDefindex(725);
                int Change = 31 - totalScrap;
                while(Change > 0)
                {
                    Trade.AddItemByDefindex(5000);
                    Change - 1;
                }
            }
            else
            {
                Trade.SendMessage("You have only added a total of " + totalScrap + " Scrap, please put up the correct amount and type ticket again");
            }
        }

        break;

But it will count 1 Scrap (item Defindex of 5000) and 1 Refined Metal (item Defindex of 5002) as both 9 and say to the user he has added a total of 18 scrap where he as only added 10. (1 refined = 9 Scrap)

Était-ce utile?

La solution

You're iterating over id's in Trade.OtherOfferedItems.

Error#1 On every iteration of the loop you're clearing totalScrap, by setting it to 0.

Error#2 In here:

`totalScrap = items.Count * 9`

you're saying "the total amount of scrap is the ammount of my items multiplied by 9" which is wrong, because if you've got 2 items with possibly different Defindexes (5002 and 5000 in your case), it gives you 18.

Error#3 Then you've got:

Trade.RemoveAllItems();

which I suppose will remove all the items from the collection you're actually iterating over - I'm really amazed that your loop doesn't crash. Put the totalScrap outside. Iterate over every item and THEN do all the clearing, removing and checking whether the sum is>31 or not.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top