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 Defindex
es (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.