[Release]Another lotto script

06/10/2009 17:54 Kiyono#1
NPCTalk.cs:
Code:
case 923:// Lady Luck enter
                    {
                        if (LinkBack == 0)
                        {
                            if (InventoryContains(710212, 1, CSocket))
                            {
                                Text("I see that you have a lottery ticket, do you want to do the lottery in exchange for the ticket?", CSocket);
                                Link("Yes", 2, CSocket);
                                Link("No", 255, CSocket);
                                Face(30, CSocket);
                                End(CSocket);
                            }
                            else
                            {
                                Text("And I charge you only 27 CPs for each admission. Come on, Try your luck right now!", CSocket);
                                Link("Wow, good deal!", 1, CSocket);
                                Link("No Thanks!", 255, CSocket);
                                Face(30, CSocket);
                                End(CSocket);
                            }
                        }
                        else if (LinkBack == 1)
                        {
                            if (CSocket.Client.Level >= 70)
                            {
                                if (CSocket.Client.CPs >= 27)
                                {
                                    CSocket.Client.LotteryBox = true;
                                    Teleport(700, 50, 50, 0, CSocket);
                                    CPs(-27, CSocket);
                                }
                                else
                                {
                                    Text("I'm sorry you do not have the required CPs.", CSocket);
                                    Link("Okay, I will be back when I have 27 CPs.", 255, CSocket);
                                    Face(30, CSocket);
                                    End(CSocket);
                                }
                            }
                            else
                            {
                                Text("I'm sorry you do not have the required Level 70.", CSocket);
                                Link("Okay, I will be back when I have level 70.", 255, CSocket);
                                Face(30, CSocket);
                                End(CSocket);
                            }
                        }
                        else if (LinkBack == 2)
                        {
                            if (CSocket.Client.Level >= 70)
                            {
                                int uid = ReturnUID(710212, CSocket);
                                CSocket.Client.Inventory.Remove(uid);
                                CSocket.Send(ConquerPacket.ItemUsage(uid, 255, Struct.ItemUsage.RemoveItem));
                                Database.Database.DeleteItem(uid);
                                CSocket.Client.LotteryBox = true;
                                Teleport(700, 50, 50, 0, CSocket);
                            }
                        }
                        else
                        {
                            Text("I'm sorry you do not have the required Level 70.", CSocket);
                            Link("Okay, I will be back when I have level 70.", 255, CSocket);
                            Face(30, CSocket);
                            End(CSocket);
                        }
                        break;
                    }
                case 924:
                    {
                        if (LinkBack == 0)
                        {
                            if (CSocket.Client.LotteryBox == true)
                            {
                                Text("Don't you want to pick a box?", CSocket);
                                Link("Well duh ofcourse I want.", 255, CSocket);
                                Face(20, CSocket);
                                End(CSocket);
                            }
                            else
                            {
                                Text("Want to leave?", CSocket);
                                Link("Yes", 1, CSocket);
                                Link("No", 255, CSocket);
                                Face(20, CSocket);
                                End(CSocket);
                            }
                        }
                        else if (LinkBack == 1)
                        {
                            Teleport(1036, 211, 196, 0, CSocket);
                        }
                        break;
                    }
                case 925:
                case 926:
                case 927:
                case 928:
                case 929:
                case 930:
                case 931:
                case 932:
                case 933:
                case 934:
                case 935:
                case 936:
                case 937:
                case 938:
                case 939:
                case 940:
                case 942:
                case 943:
                case 944:
                case 945:
                    {
                        int PriceIndex = Nano.Rand.Next(0, Nano.Lottery.Count - 1);

                        Structs.Struct.PrizeInfo Price = Nano.Lottery[PriceIndex];
                        if (CSocket.Client.LotteryBox == true)
                        {
                            CSocket.Client.LotteryBox = false;
                            if (Price.ItemID == 1)
                            {
                                CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "Too bad, you haven't won anything.", Struct.ChatType.Top));
                            }
                            else
                            {
                                List<Struct.ItemData> ItemData = new List<Struct.ItemData>();
                                foreach (KeyValuePair<int, Struct.ItemData> Items in Nano.Items)
                                    ItemData.Add(Items.Value);
                                string ItemName = Nano.Items[Price.ItemID].Name;
                                Struct.ItemInfo Item = new Struct.ItemInfo();
                                Item.Progress = Item.Bless = Item.Enchant = Item.Position = Item.Color = 0;
                                Item.Dura = 1;
                                Item.UID = Nano.Rand.Next(1, 9999999);
                                Item.ItemID = Price.ItemID;
                                Item.Plus = Price.Plus;
                                Item.Soc1 = Price.Soc1;
                                Item.Soc2 = Price.Soc2;
                                CSocket.Client.Inventory.Add(Item.UID, Item);
                                CSocket.Send(ConquerPacket.ItemInfo(Item.UID, Item.ItemID, Item.Plus, Item.Progress, Item.Bless, Item.Enchant, Item.Soc1, Item.Soc2, Item.Dura, Item.MaxDura, Item.Position, Item.Color));
Database.Database.NewItem(Item, CSocket);

                                CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", CSocket.Client.Name, "You have won a " + ItemName + ".", Struct.ChatType.Top));

                                if (Price.Message == 1)
                                {
                                    CSocket.Send(ConquerPacket.Chat(0, "SYSTEM", "ALLUSERS", CSocket.Client.Name + " is so lucky to win a(n) " + Price.Description + ItemName + ".", Struct.ChatType.Talk));
                                }
                            }
                        }
                    break;
            }
Character.cs
Code:
public bool LotteryBox = false;
Item.cs
Code:
public class PrizeInfo
        {
            public int ItemID;
            public int Plus;
            public int Soc1;
            public int Soc2;
            public int Chance;
            public string Description;
            public int Message;    
        }
Nano.cs
Code:
public static List<Struct.PrizeInfo> Lottery = new List<Struct.PrizeInfo>();
Then search for:
Code:
public static void StartServer()
And add:
Code:
Database.Database.GetPrizes();
DataBase.cs
Code:
public static void GetPrizes()
        {
            MySqlCommand Cmd = new MySqlCommand("SELECT * FROM `lotteryitems`", DatabaseConnection.NewConnection());
            MySqlDataReader DR = Cmd.ExecuteReader(CommandBehavior.CloseConnection);
            while (DR.Read())
            {
                Struct.PrizeInfo Item = new Struct.PrizeInfo();
                Item.ItemID = Convert.ToInt32(DR["ItemID"]);
                Item.Plus = Convert.ToInt32(DR["Plus"]);
                Item.Chance = Convert.ToInt32(DR["Chance"]);
                Item.Soc1 = Convert.ToInt32(DR["Soc1"]);
                Item.Soc2 = Convert.ToInt32(DR["Soc2"]);
                Item.Description = Convert.ToString(DR["Description"]);
                Item.Message = Convert.ToInt32(DR["Message"]);

                for (int i = 0; i < Item.Chance; i++)
                {
                    Nano.Lottery.Add(Item);
                }
            }
            Console.WriteLine("[GameServer] Loaded " + Nano.Lottery.Count + " lottery prizes from the DB.");
            DR.Close();
            Cmd.Dispose();
        }
Then just execute the SQl file to add the lotteryitems table.

Credits:
CoFuture Reloaded source by Future (leavemealone)


#Updated
#Updated
#Updated
#Bug fixed, items save now.
#New table, garments can be won.
#Probably the last update.
#Updated
06/10/2009 18:52 danielachraf#2
Nice code .. Going to try it
06/10/2009 19:27 nTL3fTy#3
I believe this is interchangeable and would remove the typecasting here:
Code:
Structs.Struct.PrizeInfo Price = (Structs.Struct.PrizeInfo)Nano.Lottery[PriceIndex];
to
Code:
Structs.Struct.PrizeInfo Price = Nano.Lottery[PriceIndex];
Replace:
Code:
public static ArrayList Lottery = new ArrayList();
with:
Code:
public static List<Struct.PrizeInfo> Lottery = new List<Struct.PrizeInfo>();
06/10/2009 21:44 $HaDoW#4
Update the SQL File
06/10/2009 22:57 danielachraf#5
ok .. Works fine .. i restarted the pc and open the project and saw this error :
Quote:
ConquerPacket.ItemInfo(Item.UID, Item.ItemID, Item.Plus, Item.Progress, Item.Bless, Item.Enchant, Item.Soc1, Item.Soc2, Item.Dura, Item.MaxDura, Item.Position, Item.Color
and the error
Quote:
No overload for method 'IntemInfo' takes '12' arguments
and i closed the proj and open the server , i didn't find anything wrong in lottery or in the game
06/10/2009 23:00 Zeroxelli#6
Remove
Code:
, Item.Progress
It's because he added my WuxingOven code, he has item progress. Most people don't have that code.
06/10/2009 23:41 Kiyono#7
Quote:
Originally Posted by Zeroxelli View Post
Remove
Code:
, Item.Progress
It's because he added my WuxingOven code, he has item progress. Most people don't have that code.
Most people should just add your awesome code =)
06/10/2009 23:45 Zeroxelli#8
Quote:
Originally Posted by Kiyono View Post
Most people should just add your awesome code =)
True :handsdown:

Unfortunately, people like to add things one at a time. Instead of try and get everything done then compile. Human nature, but it leads to a lot of errors xD
06/11/2009 00:01 Kiyono#9
I found a bug xD the items disappear if you log out lol
Oh well cba to fix it cause I'm sleepy.
06/11/2009 00:22 Zeroxelli#10
You didn't fix update item? :o
06/11/2009 02:08 m4l4ria#11
I have Three Error ;)
The Name 'InventoryContains' does not exist in the current context
The Name 'ReturnUID' does not exist in the current context
The Name 'RandomController' does not exist in the current context
06/11/2009 17:19 Kiyono#12
Fixed the little bug, items save now.
06/12/2009 00:10 Incariuz#13
Sorry to be a pain, getting a small error with this.

The type name 'PrizeInfo' does not exist in the type 'CoEmu_v2_GameServer.Structs.Struct'

Anyone able to help me fix this?
06/12/2009 02:46 danielachraf#14
The new update is full of errors
edit:i didn't find any error in the old one .. :)
06/12/2009 02:52 Incariuz#15
well I originaly had a bunch of errors, but the majority were easily fixed. 2 were fixed by reverting 1 of the lines back to the old code, but I dunno what to do with the last error I posted.