Author Topic: Seperate Players?  (Read 4261 times)

lynohd

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 21
    • View Profile
Seperate Players?
« on: May 23, 2016, 04:49:30 PM »
Hi, Im new to TNet and Ive just got my server up.
Before TNet I used Photon and there to seperate local player to a online player all i had to do was photonview.ismine? Disable or enable components accordingly

how would go about getting the same results here? or is there any better ways? I dont fully understand how to do it on TNET
im using the standalone server

cmifwdll

  • Global Moderator
  • Sr. Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 149
  • Posts: 285
  • TNet Alchemist
    • View Profile
Re: Seperate Players?
« Reply #1 on: May 23, 2016, 05:41:49 PM »
Every networked object should have a TNObject component attached, and any script utilizing it should inherit from TNBehaviour (not MonoBehaviour). From there, simply use the tno.isMine property. Note that TNBehaviour itself derives from MonoBehaviour, so anything you need from MonoBehaviour will still be there.

I'd suggest checking out the tutorials:
http://www.tasharen.com/forum/index.php?topic=13953.0
And the video Aren made:
https://www.youtube.com/watch?v=7oBhEwAHU5w

Seems TNet3 comes packaged with documentation in the form of pdf files as well, so check those out too.

lynohd

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 21
    • View Profile
Re: Seperate Players?
« Reply #2 on: May 24, 2016, 04:23:06 AM »
okay thanks, i kinda understand a little bit now but im still a bit confused by all this, very different workflow than what im used to

so I have to make 2 different scripts for EVERYTHING on my player? like

1 base class for Character Controller, 1 for Player Script, 1 for Weapon script

and then make another script to for all of them?

im sorry for being stupid, this is really hard for me to understand

EDIT:

Say I have a fully complete and working First Person Controller with weapons and everything, would I have to remake EVERYTHING to make it work over the network?
or can i just build ontop of what i already have?

I dont fully understand.

cmifwdll

  • Global Moderator
  • Sr. Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 149
  • Posts: 285
  • TNet Alchemist
    • View Profile
Re: Seperate Players?
« Reply #3 on: May 24, 2016, 01:07:28 PM »
so I have to make 2 different scripts for EVERYTHING on my player?

Nope.

Say I have a fully complete and working First Person Controller with weapons and everything, would I have to remake EVERYTHING to make it work over the network?
or can i just build ontop of what i already have?

At the top of the FirstPersonController.cs file you should see:
public class FirstPersonController : MonoBehaviour
Simply change this to:
public class FirstPersonController : TNBehaviour
and now it's recognized and compatible with TNet.

The tutorials and documentation should clear things up and give you a good starting point. There's also a wealth of information on this forum, so don't be afraid of the search button :)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Seperate Players?
« Reply #4 on: May 24, 2016, 04:01:37 PM »
Technically you don't even need to derive from TNBehaviour. It's just a convenience script that simplifies things like RFC registration (it's done automatically) and tno.isMine calls. If you don't inherit from TNBehaviour you can still do stuff like:
  1. GetComponent<TNObject>().isMine
exactly the same way you'd do it before with Photon, which I am assuming was:
  1. GetComponent<PhotonView>().isMine
Network view = TNObject. TN is "Tasharen Network" so it's literally "Tasharen Network Object". Makes more sense than a "view" in my opinion.

lynohd

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 21
    • View Profile
Re: Seperate Players?
« Reply #5 on: May 25, 2016, 02:50:22 AM »
Thanks alot to both of you, starting to understand it a bit more now :-).

theres still some things that I dont fully understand yet though. like,
how do i spawn instantiate/spawn stuff on the server like loot or cars for example, that the SERVER (standalone server) OWNS?
but that other players can pickup or enter and kinda "own" untill they finished using it and giving it back too the server?


and where do i find the servers name IN unity?
I have tried this;
Debug.log(TNServerInstance.serverName);
but this wasnt exactly right

EDIT:
few more questions,
for some reason I get EXTREMELY high ping on my server for no reason. I can stand completely still and not do anything and the ping skyrockets up in the 300-400s, and the server is hosted on a VPS.

and when i had a new server to listen too the standalone lobby thingie the console keeps getting spammed "added server" untill i stop that server. you happen to know how to fix this?


sorry for all the nooby questions, this is all new for me
« Last Edit: May 25, 2016, 05:15:33 AM by lynohd »

cmifwdll

  • Global Moderator
  • Sr. Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 149
  • Posts: 285
  • TNet Alchemist
    • View Profile
Re: Seperate Players?
« Reply #6 on: May 25, 2016, 12:25:44 PM »
So, because TNet has to work with everything the server is very "dumb" by default. It has no knowledge of Unity, what's going on in the game, or where objects are in the game. It doesn't even know what game objects are. The server functions as a relay. It receives a packet from a player and sends it to (an)other player(s). So if you want the server to control loot spawning and all that, you'll need to build onto the server. It's a complicated process, but thanks to TNet being very extensible it's made a lot easier. Still, it requires in-depth knowledge of networking, Unity, and TNet as a whole. However, if you're okay with settling for something much easier but less server-sided, you can have the host of the channel control loot spawning. For that it's as simple as checking TNManager.isHosting. So your loot spawn function might look like:
  1. void SpawnLoot()
  2. {
  3.     if (!TNManager.isHosting)
  4.         return;
  5.     TNManager.Instantiate(params go here);
  6. }
  7.  

Moving on, the server name is available when retrieving it from the lobby server. It's contained in the ServerList.Entry class. Seems you can access it from TNLobbyClient.knownServers as well. You could also set the name of the server in the channel data, or the serverOptions, or send it as a custom packet. Possibilities are limitless.
TNServerInstance shouldn't even be available if you're connecting as a client to a remote server. If you're trying to get the name of the server AS the server, then TNServerInstance.serverName should work, otherwise you can access it directly through an instance of GameServer.name.

The high ping sounds like an issue with your VPS host. Try opening up command prompt (or terminal) and pinging your VPS. If it's high then complain to your host. Note that distance effects ping.

I don't know about the lobby server issue - that string doesn't even exist in TNet2 (I haven't upgraded to TNet3 yet :() - so Aren or someone else will have to answer that one for you :)

lynohd

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 21
    • View Profile
Re: Seperate Players?
« Reply #7 on: May 25, 2016, 12:38:57 PM »
Thank you very much for clearing that up.starting to get the hang of this now :)
My VPS is hosted in the netherlands and im from europe so i shouldnt really get that high ping, but i contacted customer support and told them about it.

Thanks alot for all of your guyses help, I appreciate it alot.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Seperate Players?
« Reply #8 on: May 26, 2016, 12:57:22 PM »
The repeated "added server" happens when you are using UDP lobby / server discovery. Otherwise the lobby server's entries are only updated when the number of players changes.

In regards to ping, make sure you aren't flooding the network with packets. If you are sending packets in every Update() for example, it will effectively make your network batch your frequent packets into infrequently sent large packets instead. You should send packets infrequently. There is no need to send anything more than a few times per second at most, and in many cases you can get away with once every seconds even. Car example that comes with TNet lets you adjust the send values via sliders so you can test the effect of each on your network.