The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

I need to add a trade system in my game so that two players can be in a room and trade their cards. But I've searched everywhere and I can't find a simple way to do it, I've just seen a lot of 3D LAN tutorials...

What I would like :

  • both players have a button to join the trade room

  • server max peers = 2 so if a third player plays and two players are already in that trade room, he won't see a "go to trade room" button

  • when a trade is done the server shuts down and everyone can see the "go to trade room" button again

in Engine by (178 points)

Have u figured it out? I have a same problem.

1 Answer

+2 votes

You can use the high-level multiplayer API of Godot, which is explained here:
I would suggest you get familiar with this first.

This will require one of your players to host the trade room, and the other to use the IP address to connect. But you can also make a separate trade server and have both players enter the IP of that server.

If you don't want them to enter any IP address, then you will have to either hardcode it and make sure the server always run under the same IP, or have an intermediate server (using HTTP for example) which provides the list of available trade servers.

In the case of not entering any IP in a LAN context, you could use network discovery to search for trade servers in your local network (aka an instance of your game that opened a trade peer). I don't know how that works in detail, but it was mentionned here:

by (29,360 points)

Thx for your answer. I need to use a LAN system and the first player pressing the connect button would create the trade room. But I've two problems :
How can I check if a server is already running so the second player can join it ?
And is there a way to close the server when a trade is done ?

You know if a server runs if it responds to your connection/discovery broadcast. You can never assume a server is always running (even if it should ideally).

Closing a server when the trade is gone is relative. I'd say, your clients have to leave it first, because if the server closes first your clients won't be gracefully kicked out (depends how you code this, though). Also, if you use a dedicated server or that, it could still be running all the time and handle trades by "sessions". It's up to you to decide which flow you want.

I'm new to networking in Godot as well, so I mostly know theory, sorry if I can't share actual code^^

So what are the codes to :
- check if a server is running
- leave the server


(sry I'm lost with network stuff :))

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.