Jump to content
  • 0

Opening a Specific Crafting Table in Code


Lunam

Question

So I've been messing around with the code, trying to get a crafting button to work in the game menu(with the friends, guild, character, etc. buttons)

 

I have the button and the code is mostly right, but I cant seem to figure out how to call a specific crafting table because the Carfting Window doesn't have a '.show' function. This is the code I have for my ToggleCraftingWindow:

 

public void ToggleCraftingWindow()
        {
            if (mCraftingWindow.IsVisible())
            {
                mCraftingWindow.Hide();
            }
            else
            {
                HideWindows();
                Globals.ActiveCraftingTable = CraftingTableBase.FromList(0);
                mCraftingWindow.Update();
            }
        }

 

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0
1 hour ago, Cheshire said:

You'd likely want to send the server a request to open a specific crafting table as part of it is handled from the server I believe.

How do I do that? It wont let me import or use Intersect.Server.Entities.Player.cs to call the OpenCraftingTable public bool, which is what I'm assuming I need

Link to comment
Share on other sites

  • 0

You'll have to send a packet to the server when the button is pressed (much like some menus send a request for data to the server) requesting a specific crafting table (or just tell the server to open the menu) then on the packet handler server-side call the method that opens a crafting menu (like the event system does) and call your specific one or the one requested (depending on which route you go)

 

You can't just tell the server to open a client file or method. You have to send packets back and forth.. but considering most of the required networking is already implemented you'll likely only need to add one custom request packet.

Link to comment
Share on other sites

  • 0

Man, this seems way over my head but I'm trying. Everything I know about coding is self-taught, and I am still learning so I appreciate the patience. I have 0 experience with server-side applications or networking in general. No Idea what a packet is, but I think Im getting closer. The server side seems to already have a CraftingTable packet handler, but Im not sure if it has a packet sender. There is a SendCraftItem packet, but Im not sure its the same thing as a Crafting Table packet or whatever. And then theres the guid, which I also dont understand other than some odd form of identification. I cant seem to set the guid to the table i want to open(or if I can even do that at all) But here is where Im at now(uncomplete and uncompiled):

 

public void ToggleCraftingWindow()
        {
            if (mCraftingWindow.IsVisible())
            {
                mCraftingWindow.Hide();
            }
            else
            {
                HideWindows();
                Guid id = "";   //No idea how to set the GUID to the crafting table i want to open, as it doesnt take an integer or a string(for table name)
                mCraftId = id;
                PacketSender.SendCraftItem(mCraftId);
            }
        }

 

Link to comment
Share on other sites

  • 0

That method is for starting a craft and requires the menu to already be open. It asks for a crafting recipe Id, not a crafting menu.

 

What (I believe?) you should do, is look at how Packetsenders on the client work, and create a new packet to send to the server (ie RequestOpenCraftingMenu) that the server accepts and handles in its respective PacketHandler class. This basically tells the server "Hey, I want to open a menu! Send me the required information!"

 

From there, you tell the server to send a message through its respective PacketSender to open a crafting menu for the specified player. That method should already exist and is used by the event system on the server side to send information across.

The Guid you want to send over is found by right clicking the crafting menu in the editor, it'll copy the Id. You'll have to parse that into a Guid on the server to send it over though.

 

There's a more detailed instruction I could give, but I'm not at my computer right now so it's a bit challenging to do so.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...