[NEW] Purchase LTDs Limit

Pollak

Active Member
Oct 12, 2017
161
51
Hi! I coded this system and now I'm going to share it for everyone. :)

1- HabboHotel>Catalog>CatalogItem.cs
After OfferID, enter this code (ex: print)

Code:
        public int LTDLimit { get; set; }

You must be registered for see images attach


Now in ' public CatalogItem( ' after int OfferID, add int LTDLimit (ex: print)

You must be registered for see images attach


After ' this.OfferId = OfferId; ' add this.LTDLimit = LTDLimit; (ex: print)

You must be registered for see images attach


2- HabboHotel>Catalog>CatalogManager.cs
In the query ' SELECT `id`,`item_id`,`catalog_name`,`cost_credits`,`cost_pixels`,`cost_diamonds`,`cost_gotw`... ' after offer_id add `ltd_limit` (ex: print)

You must be registered for see images attach


Now in this._items[PageId].Add after Convert.ToInt32(Row["offer_id"]), add Convert.ToInt32(Row["ltd_limit"])

3- HabboHotel>Catalog>CatalogDeal (only if it exists)
In ItemDataList.Add(new CatalogItem( add more one , 0

4- Communication>Packets>Incoming>Catalog>PurchaseFromCatalogEvent.cs
Below that add this code
if (Item.IsLimited)
{​
C#:
                #region Limit LTDs
                if (Item.LTDLimit > 0)
                {
                    using (IQueryAdapter dbclient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
                    {
                        dbclient.SetQuery("SELECT * FROM `catalog_user_ltds` WHERE `user_id`='" + Session.GetHabbo().Id + "' AND `catalog_id`='" + Item.Id + "'");
                        DataTable table = dbclient.getTable();

                        dbclient.SetQuery("SELECT COUNT(id) as count FROM `catalog_user_ltds` WHERE `user_id`='" + Session.GetHabbo().Id + "' AND `catalog_id`='" + Item.Id + "'");
                        DataTable tablecount = dbclient.getTable();

                        foreach (DataRow rows in table.Rows)
                        {
                            int CountLtds = Convert.ToInt32(rows["count"]);

                            if (table != null)
                            {
                                if (CountLtds >= Item.LTDLimit)
                                {
                                    Session.SendMessage(new PurchaseErrorComposer(1));
                                    Session.SendNotification("Limit LTD: " + Convert.ToString(Item.LTDLimit));
                                    return;
                                }
                            }
                        }

                        foreach (DataRow row in tablecount.Rows)
                        {
                            if (tablecount != null)
                            {
                                if (Convert.ToInt32(row["count"]) == 0)
                                {
                                    dbclient.RunQuery("INSERT INTO `catalog_user_ltds` (`user_id`, `base_id`, `catalog_id`, `count`, `last_purchase`) VALUES ('" + Session.GetHabbo().Id + "', '" + Item.ItemId + "', '" + Item.Id + "', '1', '" + PlusEnvironment.GetUnixTimestamp() + "')");
                                }
                                else
                                {
                                    dbclient.RunQuery("UPDATE `catalog_user_ltds` SET `count` = `count` + 1, `last_purchase`='" + PlusEnvironment.GetUnixTimestamp() + "' WHERE `user_id`='" + Session.GetHabbo().Id + "' AND `catalog_id`='" + Item.Id + "'");
                                }
                            }
                        }
                    }
                }

                #endregion

5- Insert the table into your database.​
Code:
CREATE TABLE `catalog_user_ltds` (
    `id` INT(3) NOT NULL AUTO_INCREMENT,
    `user_id` INT(11) NOT NULL,
    `base_id` INT(11) NOT NULL,
    `catalog_id` INT(11) NOT NULL,
    `count` INT(3) NOT NULL,
    `last_purchase` DOUBLE NOT NULL DEFAULT '0',
    PRIMARY KEY (`id`),
    INDEX `catalog_id` (`catalog_id`),
    INDEX `base_id` (`base_id`)
)
COLLATE='latin1_swedish_ci'
ENGINE=InnoDB
AUTO_INCREMENT=1
;

ALTER TABLE `catalog_items`
    ADD COLUMN `ltd_limit` INT(4) NOT NULL DEFAULT '0' AFTER `offer_id`;

If you want to have a purchase limit per user for that particular item only change the value of ltd_limit to the limit quantity that the user can buy that item.
I'm sorry if I didn't explain how to add it, but if you already know how to move it will be easy to add.
If you have questions just comment! I appreciate your attention! :)

CREDITS:
Snaiker (Pollak)


 

Bran

mediocre graphics artist
Mar 13, 2017
1,726
1,530
Hi! I coded this system and now I'm going to share it for everyone. :)

1- HabboHotel>Catalog>CatalogItem.cs
After OfferID, enter this code (ex: print)

Code:
        public int LTDLimit { get; set; }

You must be registered for see images attach


Now in ' public CatalogItem( ' after int OfferID, add int LTDLimit (ex: print)

You must be registered for see images attach


After ' this.OfferId = OfferId; ' add this.LTDLimit = LTDLimit; (ex: print)

You must be registered for see images attach


2- HabboHotel>Catalog>CatalogManager.cs
In the query ' SELECT `id`,`item_id`,`catalog_name`,`cost_credits`,`cost_pixels`,`cost_diamonds`,`cost_gotw`... ' after offer_id add `ltd_limit` (ex: print)

You must be registered for see images attach


Now in this._items[PageId].Add after Convert.ToInt32(Row["offer_id"]), add Convert.ToInt32(Row["ltd_limit"])

3- HabboHotel>Catalog>CatalogDeal (only if it exists)
In ItemDataList.Add(new CatalogItem( add more one , 0

4- Communication>Packets>Incoming>Catalog>PurchaseFromCatalogEvent.cs
Below that add this code
if (Item.IsLimited)
{​
C#:
                #region Limit LTDs
                if (Item.LTDLimit > 0)
                {
                    using (IQueryAdapter dbclient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
                    {
                        dbclient.SetQuery("SELECT * FROM `catalog_user_ltds` WHERE `user_id`='" + Session.GetHabbo().Id + "' AND `catalog_id`='" + Item.Id + "'");
                        DataTable table = dbclient.getTable();

                        dbclient.SetQuery("SELECT COUNT(id) as count FROM `catalog_user_ltds` WHERE `user_id`='" + Session.GetHabbo().Id + "' AND `catalog_id`='" + Item.Id + "'");
                        DataTable tablecount = dbclient.getTable();

                        foreach (DataRow rows in table.Rows)
                        {
                            int CountLtds = Convert.ToInt32(rows["count"]);

                            if (table != null)
                            {
                                if (CountLtds >= Item.LTDLimit)
                                {
                                    Session.SendMessage(new PurchaseErrorComposer(1));
                                    Session.SendNotification("Limit LTD: " + Convert.ToString(Item.LTDLimit));
                                    return;
                                }
                            }
                        }

                        foreach (DataRow row in tablecount.Rows)
                        {
                            if (tablecount != null)
                            {
                                if (Convert.ToInt32(row["count"]) == 0)
                                {
                                    dbclient.RunQuery("INSERT INTO `catalog_user_ltds` (`user_id`, `base_id`, `catalog_id`, `count`, `last_purchase`) VALUES ('" + Session.GetHabbo().Id + "', '" + Item.ItemId + "', '" + Item.Id + "', '1', '" + PlusEnvironment.GetUnixTimestamp() + "')");
                                }
                                else
                                {
                                    dbclient.RunQuery("UPDATE `catalog_user_ltds` SET `count` = `count` + 1, `last_purchase`='" + PlusEnvironment.GetUnixTimestamp() + "' WHERE `user_id`='" + Session.GetHabbo().Id + "' AND `catalog_id`='" + Item.Id + "'");
                                }
                            }
                        }
                    }
                }

                #endregion

5- Insert the table into your database.​
Code:
CREATE TABLE `catalog_user_ltds` (
    `id` INT(3) NOT NULL AUTO_INCREMENT,
    `user_id` INT(11) NOT NULL,
    `base_id` INT(11) NOT NULL,
    `catalog_id` INT(11) NOT NULL,
    `count` INT(3) NOT NULL,
    `last_purchase` DOUBLE NOT NULL DEFAULT '0',
    PRIMARY KEY (`id`),
    INDEX `catalog_id` (`catalog_id`),
    INDEX `base_id` (`base_id`)
)
COLLATE='latin1_swedish_ci'
ENGINE=InnoDB
AUTO_INCREMENT=1
;

ALTER TABLE `catalog_items`
    ADD COLUMN `ltd_limit` INT(4) NOT NULL DEFAULT '0' AFTER `offer_id`;

If you want to have a purchase limit per user for that particular item only change the value of ltd_limit to the limit quantity that the user can buy that item.
I'm sorry if I didn't explain how to add it, but if you already know how to move it will be easy to add.
If you have questions just comment! I appreciate your attention! :)

CREDITS:
Snaiker (Pollak)


thank you so much king♥️
 

Joe

Well-Known Member
Jun 10, 2012
4,090
1,918
Thank you very much, will add this when I’m on my pc :)
Post automatically merged:

Having a small problem with adding the last bit to PlusEMU R2.

Instead of Session.GetHabbo it has to be session.GetHabbo and instead of SendMessage it's SendPacket

Not entirely sure if I've even added it in the right place, here's my screenshot, thanks.
Post automatically merged:

Here is my PurchaseFromCatalogEvent.cs
 

Attachments

  • Screenshot_1.png
    Screenshot_1.png
    38.8 KB · Views: 14
Last edited:

Maatt

Active Member
Aug 29, 2012
162
158
This is perfect, thank you!

If anyone is using R2 or having issues with their PurchaseFromCatalogEvent.cs, try the following:

  • add System.Data to your assembly references;
  • Change dbclient.getTable(); to dbclient.GetTable();
  • and finally, change Session.SendMessage(new PurchaseErrorComposer(1)); to Session.SendPacket(new PurchaseErrorComposer(1));
 

Users who are viewing this thread

Top