Diamond Exchange won't work [PLUSEMU]

Tex18

New Member
Nov 11, 2016
5
0
Hi Devbest!
So recently I added diamond exchange to my hotel using a code found here on Devbest, but the problem is that no redeemable furni really exchanged, it won't even exchange if I use a swf named DFD_ or if I change the name in the furniture table in my database, it just shows a popup with: This exchange is worth 410 Credits and when I click on Redeem it just stays in the room and nothing happens.

The following codes did I use:
ItemUtility.cs
Code:
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;

using Plus.HabboHotel.Items;
using Plus.HabboHotel.Items.Utilities;

namespace Plus.HabboHotel.Catalog.Utilities
{
    public static class ItemUtility
    {
        public static bool CanGiftItem(CatalogItem Item)
        {
            if (!Item.Data.AllowGift || Item.IsLimited || Item.Amount > 1 || Item.Data.ItemName.ToLower().StartsWith("cf_") || Item.Data.ItemName.ToLower().StartsWith("cfc_") || Item.Data.ItemName.ToLower().StartsWith("dfd_") ||
                Item.Data.InteractionType == InteractionType.BADGE || (Item.Data.Type != 's' && Item.Data.Type != 'i') || Item.CostDiamonds > 0 ||
                Item.Data.InteractionType == InteractionType.TELEPORT || Item.Data.InteractionType == InteractionType.DEAL)
                return false;


            if (Item.Data.IsRare)
                return false;


            if (PetUtility.IsPet(Item.Data.InteractionType))
                return false;
            return true;
        }


        public static bool CanSelectAmount(CatalogItem Item)
        {
            if (Item.IsLimited || Item.Amount > 1 || Item.Data.ItemName.ToLower().StartsWith("cf_") || Item.Data.ItemName.ToLower().StartsWith("cfc_") || Item.Data.ItemName.ToLower().StartsWith("dfd_") || !Item.HaveOffer || Item.Data.InteractionType == InteractionType.BADGE || Item.Data.InteractionType == InteractionType.DEAL)
                return false;
            return true;
        }

        public static int GetSaddleId(int Saddle)
        {
            switch (Saddle)
            {
                default:
                case 9:
                    return 7100; //4221 Changed to the right BaseItem, so it can be saved.
                case 10:
                    return 4450;
            }
        }

        public static bool IsRare(Item Item)
        {
            if (Item.LimitedNo > 0)
                return true;

            if (Item.Data.IsRare)
                return true;

            return false;
        }
    }
}

And:

CreditFurniRedeemEvents.cs
Code:
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;

using Plus.HabboHotel.Rooms;
using Plus.HabboHotel.Items;
using Plus.Communication.Packets.Outgoing.Inventory.Purse;
using Plus.Communication.Packets.Outgoing.Inventory.Furni;

using Plus.Database.Interfaces;


namespace Plus.Communication.Packets.Incoming.Rooms.Furni
{
    class CreditFurniRedeemEvent : IPacketEvent
    {
        public void Parse(HabboHotel.GameClients.GameClient Session, ClientPacket Packet)
        {
            if (!Session.GetHabbo().InRoom)
                return;


            Room Room;


            if (!PlusEnvironment.GetGame().GetRoomManager().TryGetRoom(Session.GetHabbo().CurrentRoomId, out Room))
                return;


            if (!Room.CheckRights(Session, true))
                return;


            if (PlusEnvironment.GetDBConfig().DBData["exchange_enabled"] != "1")
            {
                Session.SendNotification("The hotel managers have temporarilly disabled exchanging!");
                return;
            }


            Item Exchange = Room.GetRoomItemHandler().GetItem(Packet.PopInt());
            if (Exchange == null)
                return;


            if (!Exchange.GetBaseItem().ItemName.StartsWith("CF_") && !Exchange.GetBaseItem().ItemName.StartsWith("CFC_") || !Exchange.GetBaseItem().ItemName.StartsWith("DFD_"))
                return;


            string[] Split = Exchange.GetBaseItem().ItemName.Split('_');
            int Value = int.Parse(Split[1]);


            if (Value > 0)
            {
                switch (Split[0])
                { // Checks what type of exchange furni we're dealing with
                    default:
                        {
                            Session.GetHabbo().Credits += Value;
                            Session.SendMessage(new CreditBalanceComposer(Session.GetHabbo().Credits));

                            break;
                        }
                    case "DFD": // Updates a users diamonds instead of credits.
                        {
                            Session.GetHabbo().Diamonds += Value;
                            Session.SendMessage(new HabboActivityPointNotificationComposer(Session.GetHabbo().Diamonds, 0, 5));

                            break;
                        }
                }
            }


            using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                dbClient.RunQuery("DELETE FROM `items` WHERE `id` = '" + Exchange.Id + "' LIMIT 1");
            }


            Session.SendMessage(new FurniListUpdateComposer());
            Room.GetRoomItemHandler().RemoveFurniture(null, Exchange.Id, false);
            Session.GetHabbo().GetInventoryComponent().RemoveItem(Exchange.Id);
        }
    }
}

I tried it with a normal diamond exchange swf file named: CFC_belcrbar_500 and a renamed DFD_belcrbar_500 and both had the same problem in plusEMU

Thank you very very much for helping me out,

Tex18
 
Last edited:

JayC

Always Learning
Aug 8, 2013
5,493
1,398
Code:
switch (Split[0])
                { // Checks what type of exchange furni we're dealing with
                    default:
                        {
                            Session.GetHabbo().Credits += Value;
                            Session.SendMessage(new CreditBalanceComposer(Session.GetHabbo().Credits));

                            break;
                        }
                    case "DFD": // Updates a users diamonds instead of credits.
                        {
                            Session.GetHabbo().Diamonds += Value;
                            Session.SendMessage(new HabboActivityPointNotificationComposer(Session.GetHabbo().Diamonds, 0, 5));

                            break;
                        }
                }

C# is short circuit evaluation meaning that when it comes to something that is true, it will run it. Your default statement needs to appear last in the switch. Reason being is exactly because of the short circuit evaluation. When the program executes and it runs that switch statement its going to say oh default, everything goes in default and I can run that. It will run the default.

THE ONLY EXCEPTION TO THIS ABOVE STATEMENT IS THIS:
(I think this is true, I have never personally tried this with C#)
if you want something to execute REGARDLESS of what the case is you can put your default statement first but do not BREAK! Meaning that it will execute the default statement and then go through the cases and find the one that best matches.

Personally I would change it so that the case statement did not use default for credits, it would use default as a return. That way if somehow someone scripted to redeem furni it wouldn't give them credits or throw a bug :)

ALSO with switch statements instead of break you can say
goto '{case number}';
that will make that case execute :) Makes jumping around a case statement really nice.

Best of Luck!
 

Tex18

New Member
Nov 11, 2016
5
0
Code:
switch (Split[0])
                { // Checks what type of exchange furni we're dealing with
                    default:
                        {
                            Session.GetHabbo().Credits += Value;
                            Session.SendMessage(new CreditBalanceComposer(Session.GetHabbo().Credits));

                            break;
                        }
                    case "DFD": // Updates a users diamonds instead of credits.
                        {
                            Session.GetHabbo().Diamonds += Value;
                            Session.SendMessage(new HabboActivityPointNotificationComposer(Session.GetHabbo().Diamonds, 0, 5));

                            break;
                        }
                }

C# is short circuit evaluation meaning that when it comes to something that is true, it will run it. Your default statement needs to appear last in the switch. Reason being is exactly because of the short circuit evaluation. When the program executes and it runs that switch statement its going to say oh default, everything goes in default and I can run that. It will run the default.

THE ONLY EXCEPTION TO THIS ABOVE STATEMENT IS THIS:
(I think this is true, I have never personally tried this with C#)
if you want something to execute REGARDLESS of what the case is you can put your default statement first but do not BREAK! Meaning that it will execute the default statement and then go through the cases and find the one that best matches.

Personally I would change it so that the case statement did not use default for credits, it would use default as a return. That way if somehow someone scripted to redeem furni it wouldn't give them credits or throw a bug :)

ALSO with switch statements instead of break you can say
goto '{case number}';
that will make that case execute :) Makes jumping around a case statement really nice.

Best of Luck!
Hi thank you very much! It works now :)
 

Users who are viewing this thread

Top