Author Topic: Creating an mp game  (Read 4563 times)

JackWhite20

  • Guest
Creating an mp game
« on: December 04, 2013, 04:22:06 AM »
Hey,
i want to make an multiplayer game. So i have tnet and i can connect to my server. How can i now create a Channel with name etc ? and i dont want to load an extra scene for the lobby :/

  1. TNManager.CreateChannel("Lobby", false, 12, "");

Anybody knows how ?

JackWhite20

  • Guest
Re: Creating an mp game
« Reply #1 on: December 04, 2013, 04:43:42 AM »
Ok for not loading a level i have only to put in null :)
But did anyone have a example script with server list and how to connect and create a channel right ?

How can i give the channel an name etc ? with the channelData ?

Oh and when i Build and run and start it the game instance is crashing :(

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Creating an mp game
« Reply #2 on: December 04, 2013, 05:38:02 PM »
What's crashing? Which device? Where in the code?

Channel data can have your channel name in it, and anything else you need. You set it, and you can parse it however you like. Starlink UI kit is one example of a project where you can name your own games and have them show up for other users.

JackWhite20

  • Guest
Re: Creating an mp game
« Reply #3 on: December 05, 2013, 03:37:35 AM »
Whats crashing:
The game build

Wich device:
Pc

It is crashing by:
  1.         if (GUILayout.Button("Connect"))
  2.         {
  3.             TNManager.Connect(ip, port);
  4.         }

Other questions:
How can i accsess the channelData ? Here the Server list code:
  1.     void OnChannelList(Packet response, BinaryReader reader, IPEndPoint source)
  2.     {
  3.         int count = reader.ReadInt32();
  4.         Debug.LogError("Count:" + count);
  5.         for (int i = 0; i < count; ++i)
  6.         {
  7.             int channelID = reader.ReadInt32();
  8.             int playerCount = reader.ReadInt32();
  9.             bool password = reader.ReadBoolean();
  10.             bool isPersistent = reader.ReadBoolean();
  11.             string scene = reader.ReadString();
  12.  
  13.             Debug.LogError("ChannelID:" + channelID + " PlayerCount:" + playerCount + " Passwort:" + password + " isOersistent:" + isPersistent);
  14.  
  15.             RoomInfo tr = new RoomInfo();
  16.             tr.ID = channelID;
  17.             tr.playercount = playerCount;
  18.             tr.password = password;
  19.             tr.isPersistent = isPersistent;
  20.             tr.scene = scene;
  21.             rooms.Add(tr);
  22.         }
  23.     }

So the last question is:
How can i create channels right ?
Because i am creating an channel with max 12 players, but when i refresh serverlist there are some random number for the max player and how i can get the currntplayers ? Or did i must decrease and increase it by myself eg in the channeldata when a new player joins/leaves ?

Create Channel:
  1.         if (GUILayout.Button("Create a room"))
  2.         {
  3.             TNManager.CreateChannel(null, false, 12, "");
  4.         }

Screenshot from serverlist output:

or
http://prntscr.com/28u6nc

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Creating an mp game
« Reply #4 on: December 05, 2013, 03:50:59 PM »
TNet's provided examples connect in a similar fashion. Does it crash there? Seeing as I've never seen it crash, I'd venture a guess that it's something else entirely. Worst case you may get an error message. Certainly not crash.

As for your OnChannelList question... you're reading the data wrong. Look at the description of the packet:
  1.         /// <summary>
  2.         /// List open channels on the server.
  3.         /// int32: number of channels to follow
  4.         /// For each channel:
  5.         /// int32: ID
  6.         /// ushort: Number of players
  7.         /// ushort: Player limit
  8.         /// bool: Has a password
  9.         /// bool: Is persistent
  10.         /// string: Level
  11.         /// string: Custom data
  12.         /// </summary>
You can see that number of players and player limit are 'ushort' type -- those are 16 bit unsigned integer values. You're reading them as Int32 instead. That's why you are getting odd results.

You need to use reader.ReadUInt16

JackWhite20

  • Guest
Re: Creating an mp game
« Reply #5 on: December 05, 2013, 04:11:38 PM »
Thx the serverlist works now fine :)

Yh the game crashes too when i build the example menu with example 1,2 and 3 :/
When i copy it on my laptp and run it there it works, i dont know why its crashing on my pc :(

When i want to spawn a player(by me its a cube that can be moved with w,a,s,d) i am sending an RFC with rotation and position of the spawnpoint. but now i cant control it because i am not the owner because i am disabling the move script when !tno.IsMine, how to fix this ? Did i have to make a Player variable and put that in the if statement like if(playervar.id != TNmanager.playerID) this.diabled = false ??

Oh and the Autosync laaaaaags very heavy :/

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Creating an mp game
« Reply #6 on: December 06, 2013, 04:27:58 AM »
Are you running Windows 8.0? It has major .NET performance issues. 8.1 seems to resolve them.

JackWhite20

  • Guest
Re: Creating an mp game
« Reply #7 on: December 06, 2013, 08:41:40 AM »
No on my pc and laptop i am using windows 7.

Can you halp me with this:
When i want to spawn a player(by me its a cube that can be moved with w,a,s,d) i am sending an RFC with rotation and position of the spawnpoint. but now i cant control it because i am not the owner because i am disabling the move script when !tno.IsMine, how to fix this ? Did i have to make a Player variable and put that in the if statement like if(playervar.id != TNmanager.playerID) this.diabled = false ??

Oh and the Autosync laaaaaags very hard :/

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Creating an mp game
« Reply #8 on: December 07, 2013, 12:46:27 AM »
Don't disable the script. Keep it active, just check tno.isMine and exit the Update function early if it's not what you expect.

AutoSync scripts simply send data X times per second based on the timing you specify. They have an option to send it via UDP or TCP. Did you try tweaking the options?

JackWhite20

  • Guest
Re: Creating an mp game
« Reply #9 on: December 07, 2013, 05:39:04 AM »
Where can i find the option ? I have only 4 options: Updates per Second, Saved on server, Importent and Only Owner can Sync...

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Creating an mp game
« Reply #10 on: December 07, 2013, 04:14:40 PM »
"Important" checked means it's going through TCP. Unchecked means it'll go through UDP.