clear inv

08/01/2010 09:57 Fish*#1
Would this work to clear inventory?
Is for the 5018 source.
Code:
                    case "/clearinv"://Not tested yet
                        {
                            foreach (IConquerItem I in MyChar.Inventory)
                            {
                                MyChar.RemoveInventory(I.ID);
                            }
                            break;
                        }
08/01/2010 10:43 Arcо#2
How about
case "#clearinv":
Client.Inventory.Clear();
break;
08/01/2010 10:52 Arcо#3
Quote:
Originally Posted by Eliminationn View Post
LOL!!! Acro just pwned you.
Uhm, no. Either one works, just mine is the correct way to do it. No one pwned anybody. But thanks for the spam mate. And the misspelling of my name.
08/01/2010 21:38 _tao4229_#4
Quote:
Originally Posted by .Arco View Post
How about
case "#clearinv":
Client.Inventory.Clear();
break;
Because that doesn't send the remove item packet.
08/01/2010 22:56 CptSky#5
The two methods are wrong... The first will throw an exception. You will remove a key while you are enumerating the dictionary/hashtable... The second will remove all items for sure, but not on the client. You can just use the two methods combined :) You send the packet for each items and after, you clear the dictionary/hashtable.
08/02/2010 00:07 _tao4229_#6
Quote:
Originally Posted by CptSky View Post
The two methods are wrong... The first will throw an exception. You will remove a key while you are enumerating the dictionary/hashtable... The second will remove all items for sure, but not on the client. You can just use the two methods combined :) You send the packet for each items and after, you clear the dictionary/hashtable.
It depends on what kind of collection you're looping through, how you're looping through it, and also how you're removing the data.

Even if you're looping through like he is you can still remove it using RemoveAt(idx) without throwing an exception.