Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

UberEmu FireWorks!

Status
Not open for further replies.
Experienced Elementalist
Joined
Jan 24, 2009
Messages
226
Reaction score
166
Here is my FULL fireworks system for uberemu,
(I'm not gonna explain how to add this time,.. just explore yourself)
No sql needed! this code automaticly add the table/rows!!!

The item interation:
Code:
firework
The item interactor:
PHP:
    #region InteractorFireWork
    class InteractorFireWork : FurniInteractor
    {
        #region OnPlace
        public override void OnPlace(GameClient Session, RoomItem Item)
        {
            try
            {
                DataTable Data = null;

                using (DatabaseClient dbClient = UberEnvironment.GetDatabase().GetClient())
                {
                    Data = dbClient.ReadDataTable("SELECT * FROM firework WHERE furni = '" + Item.Id + "' LIMIT 1");
                }

                if (Data == null)
                {
                    using (DatabaseClient dbClient = UberEnvironment.GetDatabase().GetClient())
                    {
                        dbClient.ExecuteQuery("INSERT INTO firework (`id`, `furni`, `loaded`) VALUES (NULL, '" + Item.Id + "', '0')");
                    }
                }

                foreach (DataRow Row in Data.Rows)
                {
                    if ((int)Row["loaded"] >= 1)
                    {
                        Item.ExtraData = "1";
                        Item.UpdateState();
                    }
                    else
                    {
                        Item.ExtraData = "0";
                        Item.UpdateState();
                    }
                }
            }
            catch (MySqlException)
            {
                using (DatabaseClient dbClient = UberEnvironment.GetDatabase().GetClient())
                {
                    dbClient.ExecuteQuery("CREATE TABLE IF NOT EXISTS firework (`id` int(11) NOT NULL AUTO_INCREMENT, `furni` int(11) NOT NULL, `loaded` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`id`))");
                }
            }
        }
        #endregion

        #region OnRemove
        public override void OnRemove(GameClient Session, RoomItem Item) { }
        #endregion

        #region OnTrigger
        public override void OnTrigger(GameClient Session, RoomItem Item, int Request, bool UserHasRights)
        {
            RoomUser User = Item.GetRoom().GetRoomUserByHabbo(Session.GetHabbo().Id);

            if (User == null)
            {
                return;
            }

            #region ItemCoord poop!
            Coord ItemCoord1 = new Coord(Item.Coordinate.x + 1, Item.Coordinate.y);
            Coord ItemCoord2 = new Coord(Item.Coordinate.x + 1, Item.Coordinate.y + 1);
            Coord ItemCoord3 = new Coord(Item.Coordinate.x + 1, Item.Coordinate.y - 1);
            Coord ItemCoord4 = new Coord(Item.Coordinate.x - 1, Item.Coordinate.y);
            Coord ItemCoord5 = new Coord(Item.Coordinate.x - 1, Item.Coordinate.y + 1);
            Coord ItemCoord6 = new Coord(Item.Coordinate.x - 1, Item.Coordinate.y - 1);
            Coord ItemCoord7 = new Coord(Item.Coordinate.x, Item.Coordinate.y + 1);
            Coord ItemCoord8 = new Coord(Item.Coordinate.x, Item.Coordinate.y - 1);
            #endregion

            if (User.Coordinate == ItemCoord1 || User.Coordinate == ItemCoord2 || User.Coordinate == ItemCoord3 || User.Coordinate == ItemCoord4 || User.Coordinate == ItemCoord5 || User.Coordinate == ItemCoord6 || User.Coordinate == ItemCoord7 || User.Coordinate == ItemCoord8)
            {
                try
                {
                    DataTable Data = null;
                    int Type = Request;

                    if (Type == 0)
                    {
                        #region Type 0
                        using (DatabaseClient dbClient = UberEnvironment.GetDatabase().GetClient())
                        {
                            Data = dbClient.ReadDataTable("SELECT * FROM firework WHERE furni = '" + Item.Id + "' LIMIT 1");

                            if (Data == null)
                            {
                                dbClient.ExecuteQuery("INSERT INTO firework (`id`, `furni`, `loaded`) VALUES (NULL, '" + Item.Id + "', '0')");
                            }

                            foreach (DataRow Row in Data.Rows)
                            {
                                int currentMode = 0;
                                int newMode = 0;

                                try
                                {
                                    currentMode = int.Parse(Item.ExtraData);
                                }
                                catch (Exception) { }

                                if (currentMode <= 0)
                                {
                                    if ((int)Row["loaded"] >= 1)
                                    {
                                        newMode = 1;
                                    }
                                    else
                                    {
                                        DataTable Data2 = null;
                                        Data2 = dbClient.ReadDataTable("SELECT * FROM firework WHERE furni = '" + Item.Id + "' LIMIT 1");

                                        foreach (DataRow Row2 in Data2.Rows)
                                        {
                                            ServerMessage Message = new ServerMessage(629);
                                            Message.AppendUInt(Item.Id);
                                            Message.AppendInt32((int)Row2["loaded"]);
                                            Message.AppendInt32(0);
                                            Message.AppendInt32(100);
                                            Message.AppendInt32(0);
                                            Message.AppendInt32(10);
                                            Session.SendMessage(Message);
                                        }
                                    }
                                }
                                else if (currentMode == 1)
                                {
                                    newMode = 2;
                                    dbClient.ExecuteQuery("UPDATE firework SET loaded = loaded - 1 WHERE furni = '" + Item.Id + "'");

                                    ThreadPool.QueueUserWorkItem(o =>
                                        {
                                            Thread.Sleep(7000); // crappy timer ;3

                                            if ((int)Row["loaded"] >= 1)
                                            {
                                                newMode = 1;
                                            }
                                            else
                                            {
                                                newMode = 0;
                                            }

                                            Item.ExtraData = newMode.ToString();
                                            Item.UpdateState();
                                        });
                                }
                                else if (currentMode >= 2)
                                {
                                    // wait for the crappy timer,..
                                }

                                if (currentMode < 2)
                                {
                                    Item.ExtraData = newMode.ToString();
                                    Item.UpdateState();
                                }
                            }
                        }
                        #endregion
                    }
                    else if (Type == 1)
                    {
                        #region Type 1
                        using (DatabaseClient dbClient = UberEnvironment.GetDatabase().GetClient())
                        {
                            Data = dbClient.ReadDataTable("SELECT * FROM firework WHERE furni = '" + Item.Id + "' LIMIT 1");
                        }

                        foreach (DataRow Row in Data.Rows)
                        {
                            ServerMessage Message = new ServerMessage(629);
                            Message.AppendUInt(Item.Id);
                            Message.AppendInt32((int)Row["loaded"]);
                            Message.AppendInt32(0);
                            Message.AppendInt32(100);
                            Message.AppendInt32(0);
                            Message.AppendInt32(10);
                            Session.SendMessage(Message);
                        }
                        #endregion
                    }
                    else if (Type == 2)
                    {
                        #region Type 2
                        using (DatabaseClient dbClient = UberEnvironment.GetDatabase().GetClient())
                        {
                            if (Session.GetHabbo().ActivityPoints >= 100)
                            {
                                int NewPixels = Session.GetHabbo().ActivityPoints - 100;
                                dbClient.ExecuteQuery("UPDATE firework SET loaded = loaded + 10 WHERE furni = '" + Item.Id + "'");
                                Session.GetHabbo().ActivityPoints = NewPixels;
                                dbClient.ExecuteQuery("UPDATE users SET activity_points = '" + NewPixels + "' WHERE id = '" + Session.GetHabbo().Id + "' LIMIT 1");

                                Data = dbClient.ReadDataTable("SELECT * FROM firework WHERE furni = '" + Item.Id + "' LIMIT 1");

                                foreach (DataRow Row in Data.Rows)
                                {
                                    ServerMessage Message = new ServerMessage(629);
                                    Message.AppendUInt(Item.Id);
                                    Message.AppendInt32((int)Row["loaded"]);
                                    Message.AppendInt32(0);
                                    Message.AppendInt32(100);
                                    Message.AppendInt32(0);
                                    Message.AppendInt32(10);
                                    Session.SendMessage(Message);
                                }
                            }
                            else
                            {
                                //ADHIH{{1}}
                                ServerMessage Message = new ServerMessage(86);
                                Message.AppendInt32(0);
                                Message.AppendInt32(1);
                                Message.AppendInt32(0);
                                Session.SendMessage(Message);
                            }
                        }
                        #endregion
                    }
                }
                catch (MySqlException)
                {
                    using (DatabaseClient dbClient = UberEnvironment.GetDatabase().GetClient())
                    {
                        dbClient.ExecuteQuery("CREATE TABLE IF NOT EXISTS firework (`id` int(11) NOT NULL AUTO_INCREMENT, `furni` int(11) NOT NULL, `loaded` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`id`))");
                    }
                }
            }
            else if (User.CanWalk)
            {
                User.MoveTo(Item.SquareInFront);
            }
        }
        #endregion
    }
    #endregion
Video:


Credits:
TopErwin - making whole code :thumbup:
 
Last edited:
Your Favorite Stalker
Joined
Jul 13, 2008
Messages
395
Reaction score
115
TOPERWIN DID IT AGAAIN!!
nice!
(1st post :D)

Grr..
Arnii
 
Banned
Banned
Joined
Jan 9, 2010
Messages
1,850
Reaction score
503
Uhm abit rough coded though, its using too much coord's and it doesnt cache it which might lagg the server abit when everyone on the hotel is using it.

Thanks though :]
 
Experienced Elementalist
Joined
Oct 25, 2009
Messages
205
Reaction score
106
Im going to give it a shot now :)

Thanks
 
Newbie Spellweaver
Joined
Jun 13, 2010
Messages
43
Reaction score
1
The timer is buggy with some firework's
Here's a simple fix:

Change
Code:
                                    ThreadPool.QueueUserWorkItem(o =>
                                    {
                                        Thread.Sleep(7000); // crappy timer ;3
To
Code:
int time = 6000;

                                    switch (Item.GetBaseItem().PublicName)
                                    {
                                        case "fireworks_01":
                                            time = 3000;
                                            break;

                                        case "fireworks_07":
                                            time = 10000;
                                            break;
                                    }

                                    ThreadPool.QueueUserWorkItem(o =>
                                    {
                                        Thread.Sleep(time); // crappy timer ;3
 
Experienced Elementalist
Joined
Jan 24, 2009
Messages
226
Reaction score
166
The timer is buggy with some firework's
Here's a simple fix:

there are much more firework's,...
bcouse i doesn't logg them exactly i just toke the average seconds,
but thanks for that 2 ;p
 
Banned
Banned
Joined
May 6, 2009
Messages
531
Reaction score
165
Toper, look my erro ;S

The type or namespace name 'DataTable' could not be found (are you missing a using directive or an assembly reference?)

You can help me? Im use the Blah Emulator edited by Slaxxer D;
 
Banned
Banned
Joined
Jan 9, 2010
Messages
1,850
Reaction score
503
TopErwin why are you using Thread.Sleep?
Just use ReqUpdate(time in seconds) :eek:

---------- Post added at 12:26 PM ---------- Previous post was at 12:25 PM ----------

duck yeah! Someone else coded this from Kekomundo before this, but never theless thanks!
And that code from KekoMundo was leached from Matty13's old emulator ( december 2010 build, never released, but it was leaked by some spanish newbs ).
 
Experienced Elementalist
Joined
Jan 24, 2009
Messages
226
Reaction score
166
TopErwin why are you using Thread.Sleep?
Just use ReqUpdate(time in seconds) :eek:

---------- Post added at 12:26 PM ---------- Previous post was at 12:25 PM ----------

And that code from KekoMundo was leached from Matty13's old emulator ( december 2010 build, never released, but it was leaked by some spanish newbs ).

i use Thread.Sleep bcouse of this:
PHP:
ThreadPool.QueueUserWorkItem
 
Experienced Elementalist
Joined
Oct 28, 2009
Messages
237
Reaction score
26
Blah emulator fix

Blah emulator fix:

Search for
PHP:
using System;
in FurniInteractor.cs

Replace it by
PHP:
using System;
using System.Data;
using System.Threading;
using MySql.Data.MySqlClient;
 
Last edited:
Banned
Banned
Joined
Aug 25, 2009
Messages
431
Reaction score
190
Anyone got the SQL's for the FIREWORKS. Not the trophys ?
 
Status
Not open for further replies.
Back
Top