Jessecar96 / SteamBot

Automated bot software for interacting with Steam Trade
http://scrap.tf
MIT License
1.34k stars 910 forks source link

Adding Items of Same Kind #16

Closed borewik closed 12 years ago

borewik commented 12 years ago

When you input this:

 trade.AddItemByDefindex(4100,0);
 // here optional pause for ~1 sec eg. with Thread
 trade.AddItemByDefindex(4100,1);

To any event, it will move the same item from slot 0 to slot 1, instead of adding new item of same type to slot 1.

Philipp15b commented 12 years ago

Confirmed. The method should not always simply pick the first item in the inventory with the given defindex to the trade and search for the next item with that defindex if the first one is already in the trade.

Philipp15b commented 12 years ago

Currently this is impossible to fix unless the items in the trade are mirrored locally in the Trade class which is currently not the case, because otherwise a trade cannot access the items in a trade.

borewik commented 12 years ago

I also have other bug/problem... don't know if i should make another topic about it. Check how much CPU does that bot eat, run 2 in parallel and its 100% (for mine pc at last). I put in function Update() just under while(true) one line: Thread.Sleep (1); That made it barley use CPU.

Philipp15b commented 12 years ago

Yeah, this is definitely something for a seperate issue.

Philipp15b commented 12 years ago

The bug with AddItemByDefindex is actually not yet fixed. Please reopen.

Philipp15b commented 12 years ago

I said before that it is impossible to fix which is partially true, because I just discovered that we do keep a list of all items in the trade, but items are only added after the the next poll. This would allow us to do a partial fix by checking in the existing list. Or we could create a new list of items that are not yet confirmed to be added.

teliosdev commented 12 years ago

There is also the possibility of having the bot keep track of all the items it has put in the trade, and updating its local copy on the next poll; that way, you can validate it on the spot, as there's really no chance that the local copy differs, and if it does, then the local copy takes precedence over what steam tells us (as in, we should update Steam to match our local copy of items in the trade, instead of the other way around).

mango52 commented 12 years ago

Is there a way to get all the items of a certain defindex in the backpack and then get their respective ids?

Philipp15b commented 12 years ago

@mango52 Yup. There's a method called GetItemsByDefindex in Inventory.cs: Link

mango52 commented 12 years ago

@Philipp15b And it works? If so, why not just implement that code as part of AddItemByDefindex? It seems too obvious... EDIT: I wrote this without checking. The broken code already does what I was thinking. I'm confused as to why it doesn't work. EDIT 2: I understand now and redjazz's solution seems like the best option to me.

mango52 commented 12 years ago

Is there something wrong with this? https://gist.github.com/3966611

Philipp15b commented 12 years ago

@mango52 Almost right :smirk: See my changes in my fork.

mango52 commented 12 years ago

Just a stupid mistake. Not bad for my first day in C# though, I'd say. What would happen in the Trade parameter was removed from the function and replaced with 'this' in the code? Would that not work?

Philipp15b commented 12 years ago

Yeah, you can remove the trade parameter, just as in Java you can access parameters in functions only by their name or with a this.

teliosdev commented 12 years ago

Have we checked out trade.MyOfferedItems?

Philipp15b commented 12 years ago

Yes. @mango52 uses it in his fix. We just have to add the changes to the Poll() method in Trade.

teliosdev commented 12 years ago

Maybe this is what we need.

Philipp15b commented 12 years ago

Isn't that the same as mine? Or is the null check in foreachs important?

teliosdev commented 12 years ago

It was there in the code before, so I assumed an item could be null and I checked for it. And I added a RemoveItemByDefindex method.

Philipp15b commented 12 years ago

If so, this would be a bug.

teliosdev commented 12 years ago

It does keep track of it in Trade.cs (lines 221 and 235)

Philipp15b commented 12 years ago

Yeah, but this will not work if you use AddItemByDefindex to add multiple items in one go (which will likely happen for metal). The new items have to be added to the list when AddItem etc. is called. What you could do then in Poll() is validating the local list against the list from Steam.

teliosdev commented 12 years ago

Derp, I knew that.

Philipp15b commented 12 years ago

Is this now fixed?

teliosdev commented 12 years ago

I'm not sure, I'll check it later when I have direct access to steam.

teliosdev commented 12 years ago

I can confirm it is fixed.