Author Topic: Vehicle (Photon ---> TNet)Transfer Ownership  (Read 4337 times)

blueagardq15

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 23
    • View Profile
Vehicle (Photon ---> TNet)Transfer Ownership
« on: July 24, 2015, 07:08:01 PM »
Hi I have a premade working script for Vehicles where you can take control of a car because ownership was transfered using photon, but I switched to TNEt and now I ran into trouble as I looked through the forum looking up my problem and found atleast half-answers. Here is my code below  problem is idk how to replace "thisPhotonView.TransferOwnership(PhotonNetwork.player);" with TNet Coding

 
  1. public void OnEnter(bool enter, int viewID)
  2.                 {
  3.                         if(enter && !GetComponent<TNObject>().isMine) {
  4.                                 thisPhotonView.TransferOwnership(PhotonNetwork.player);
  5.                         }
  6.                         //Below I am trying to find the Player using his ID send in an RFC.
  7.                         view = GetComponent<TNObject>().Send(viewID);
  8.  

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Vehicle (Photon ---> TNet)Transfer Ownership
« Reply #1 on: July 25, 2015, 03:42:26 PM »
There is no need to do this at all in TNet. What would be the reason? The TNObject's owner is just whoever creates it, and if that person leaves and the object happens to be persistent it gets switched to someone else automatically.

blueagardq15

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 23
    • View Profile
Re: Vehicle (Photon ---> TNet)Transfer Ownership
« Reply #2 on: July 25, 2015, 10:47:37 PM »
The reason is because in order to sync the position of the vehicle which is serialized by autoSync, you must be the owner. So another player cannot enter the car and sync the positions when there already is an Owner. So, I am trying to find a way to have it so it can transfer ownership so that anothe rperson can take control and drive. Am I making any sense to you?

blueagardq15

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 23
    • View Profile
Re: Vehicle (Photon ---> TNet)Transfer Ownership
« Reply #3 on: July 25, 2015, 10:48:53 PM »
Ohhh I see what you mean by that. My question then is how can i change who it is synced by because I am using the AutoSync Script...

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Vehicle (Photon ---> TNet)Transfer Ownership
« Reply #4 on: July 27, 2015, 11:52:00 AM »
Don't use AutoSync. It's a convenience script, but you pay for that convenience with flexibility.

Use RFCs instead.

voncarp

  • Jr. Member
  • **
  • Thank You
  • -Given: 13
  • -Receive: 2
  • Posts: 91
    • View Profile
Re: Vehicle (Photon ---> TNet)Transfer Ownership
« Reply #5 on: July 28, 2015, 02:33:12 PM »
I change owners with vehicles as well.

Change this first in TNObject.cs:

  1. /// <summary>
  2.     /// ID of the player that owns this object.
  3.     /// </summary>
  4.  
  5.     public int ownerID
  6.     {
  7.         get
  8.         {
  9.             return mOwner;
  10.         }
  11.         set
  12.         {
  13.             if (mOwner != value)
  14.             {
  15.                 mOwner = value;
  16.                 Send("SetOwner", Target.Others, value);
  17.             }
  18.         }
  19.     }
  20.  
  21.     [RFC] void SetOwner (int val) { mOwner = val; }

Then you can use it something like this:

  1.         void SetNewCarOwner(int _newOwner) {
  2.                 tno.ownerID = _newOwner;
  3.         }

blueagardq15

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 23
    • View Profile
Re: Vehicle (Photon ---> TNet)Transfer Ownership
« Reply #6 on: July 28, 2015, 05:22:52 PM »
Thank you

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Vehicle (Photon ---> TNet)Transfer Ownership
« Reply #7 on: July 28, 2015, 05:59:30 PM »
This is not a good idea as the owner ID is stored on the server, while this RFC is client-side only.

Create a separate script with a different "owner" value instead.