[Help]Randoms

02/08/2010 00:01 coreymills#1
could someone help me with making a random for moonboxes so that when they open a moonbox it gives random items from a txt file.
02/08/2010 00:14 -Shunsui-#2
Just use,

Code:
#region MoonBox2
                    case 721080:
                        {
                            Random R = new Random(); // New Random
                            int Nr = R.Next(1, 6); // "Randomally" Picks a number 1-10 
                            if (Nr == 1) //Random Spot 1
                            {
                                AddItem(111006);//Helm
                                RemoveItem(I);
                            }
                            if (Nr == 2) //Random Spot 2
                            {
                                AddItem(112058);//Veil
                                RemoveItem(I);
                            }
                            if (Nr == 3) //Random Spot 3
                            {
                                AddItem(720027);//MetScroll
                                RemoveItem(I);
                            }
                            if (Nr == 4) //Random Spot 4
                            {
                                AddItem(723711);//met Tear Pack
                                RemoveItem(I);
                            }
                            if (Nr == 5) //Random Spot 5
                            {
                                AddItem(723700);//Exp Ball
                                RemoveItem(I);
                            }
                            if (Nr == 6) //Random Spot 6
                            {
                                AddItem(723584);//Black Tulip
                                RemoveItem(I);
                            }
                            break;
                        }
                    #endregion
02/08/2010 00:24 coreymills#3
question solved
#request Close
02/08/2010 03:07 pro4never#4
Why on earth would you want a script like that where you only get a pre-specified item?

Take advantage of the item type already loaded and select random equipment/armor from that

random code snippet from a co emu based source

Code:
List<Struct.ItemData> ItemData = new List<Struct.ItemData>();
                        foreach (KeyValuePair<int, Struct.ItemData> Items in Nano.Items)
                            ItemData.Add(Items.Value);
Setup the item stats and use something like

Code:
Item.ItemID = Nano.Rand.Next(111003, 601339);
                            while (!Nano.Items.ContainsKey(Item.ItemID))
                                Item.ItemID = Nano.Rand.Next(111003, 601339);
to select a random item id between 111003, 601339. If it doesn't exist in the loaded items, it tries again.

Do a calculation to get the base item (knock off the final digit) and use a percent success calculation to re-attach an item quality (1-9)

Other info such as sockets/+/bless can be done in the exact same way (seeing as you already have the item structure, you are just filling in the fields and then adding the item.
02/08/2010 03:15 coreymills#5
i hardly know any C# i'm still learning what Shunshi gave is perfect for a beginner like me