Tasharen Entertainment Forum

Support => TNet 3 Support => Topic started by: Elmo loves cookies on May 27, 2016, 01:32:19 PM

Title: Tnet 3.0 How work [RFC] for specific player?
Post by: Elmo loves cookies on May 27, 2016, 01:32:19 PM
I don`t understand how its work, I write like this:

  1. void OnTriggerEnter2D(Collider2D mOther)
  2.     {
  3.         if (tno.isMine)
  4.         {
  5.             if (mOther.tag == "Player")
  6.             {
  7.                 TNObject otherTNO = mOther.GetComponent<TNObject>();
  8.                 Debug.Log("HisID: " + otherTNO.ownerID); //thats work fine!!!
  9.                 if (otherTNO == null)
  10.                     return;
  11.  
  12.                 tno.Send("Kill", Target.All, otherTNO.ownerID);
  13.             }
  14.         }
  15.        
  16.     }

There [RFC] function:

  1. [RFC]
  2.     public void Kill(int id)
  3.     {
  4.         Debug.Log(id + "andMyID: " + tno.ownerID);
  5.         if (id == tno.ownerID)
  6.         {
  7.             // THATS ALL DONT WORK, but "tno.ownerID" and "id" - is right!!!
  8.             Debug.Log("killing me");
  9.             GameController.instance.Death++;
  10.             tno.DestroySelf();
  11.         }
  12.     }

please help:)
Title: Re: Tnet 3.0 How work [RFC] for specific player?
Post by: ArenMook on May 27, 2016, 10:07:03 PM
Why is the target Target.All? You want to send this event to a specific player, so do just that:
  1. tno.Send("Kill", otherTNO.owner);
This will call the RFC "Kill" on the player that owns the object, who should then actually destroy the object via tno.DestroySelf().
Title: Re: Tnet 3.0 How work [RFC] for specific player?
Post by: Elmo loves cookies on May 28, 2016, 05:52:22 AM
hm, thats dont work:(

  1. void OnTriggerEnter2D(Collider2D mOther)
  2.     {
  3.         if (tno.isMine)
  4.         {
  5.             if (mOther.tag == "Player")
  6.             {
  7.                 TNObject otherTNO = mOther.GetComponent<TNObject>();
  8.                 if (otherTNO == null)
  9.                     return;
  10.  
  11.                 tno.Send("Kill", otherTNO.owner);
  12.             }
  13.         }
  14.        
  15.     }

  1. [RFC]
  2.     public void Kill()
  3.     {
  4.         tno.DestroySelf();
  5.     }

That`s Destroy Player who send RFC, but I need Destroy other Player in Trigger
Title: Re: Tnet 3.0 How work [RFC] for specific player?
Post by: Elmo loves cookies on May 28, 2016, 07:03:15 AM
thats work like that:

  1. void OnTriggerEnter2D(Collider2D mOther)
  2.     {
  3.         if (tno.isMine)
  4.         {
  5.             if (mOther.tag == "Player")
  6.             {
  7.                 TNObject otherTNO = mOther.GetComponentInParent<TNObject>();
  8.                 if (otherTNO == null)
  9.                     return;
  10.  
  11.                 otherTNO.Send("Kill", Target.All);
  12.             }
  13.         }
  14.            
  15.     }

  1. [RFC]
  2.     protected void Kill()
  3.     {
  4.        
  5.         tno.DestroySelf();
  6.        
  7.     }

correctly it is, or this can give me some bugs in future?
Title: Re: Tnet 3.0 How work [RFC] for specific player?
Post by: ArenMook on May 29, 2016, 11:32:03 AM
When you send a packet to everyone, and each player calls DestroySelf(), these packets go directly to the server. So if you have 100 players, that means 100 destroy calls of the same object. This is why in my code the call goes to a specific player.

That said, I am not sure why you are sending an RFC there just to destroy an object. Why not just do this?
  1.     void OnTriggerEnter2D(Collider2D mOther)
  2.     {
  3.         if (tno.isMine)
  4.         {
  5.             if (mOther.tag == "Player")
  6.             {
  7.                 TNObject otherTNO = mOther.GetComponentInParent<TNObject>();
  8.                 if (otherTNO != null) otherTNO.DestroySelf();
  9.             }
  10.         }
  11.     }
Title: Re: Tnet 3.0 How work [RFC] for specific player?
Post by: Elmo loves cookies on May 29, 2016, 08:35:05 PM
just I cant use otherTNO.DestroySelf(); because there is some statistics value(kill/death)

if I use
  1. tno.Send("Kill", otherTNO.owner);
I send from my "TNObject.tno" -> to other "otherTNO.owner" command "Kill"
what I should write in [RFC] Kill?
like this?

  1. [RFC]
  2.     protected void Kill()
  3.     {
  4.         if (tno.isMine)
  5.         {
  6.             tno.DestroySelf();
  7.             GameController.instance.Death++;
  8.             GameController.instance.ChangeTo(GameController.instance.RespawnPanel);
  9.         }
  10.     }

But that`s don`t work, How I can call some command on specific "otherTNO.owner"? write example please:)
Title: Re: Tnet 3.0 How work [RFC] for specific player?
Post by: cmifwdll on May 29, 2016, 11:13:27 PM
tno.DestroySelf() will destroy the gameObject containing the TNObject component. This is also done on every other client as well (the destroy message is propagated through the network).
Since it destroys the gameObject, you're probably seeing a race condition between the destroy and those next two lines of code. Try updating your statistics before calling tno.DestroySelf().

If your problem is that your statistics aren't syncing and you'd like them to be synced, then consider using TNManager.SetPlayerData(...).
Title: Re: Tnet 3.0 How work [RFC] for specific player?
Post by: Elmo loves cookies on June 06, 2016, 11:51:40 PM
I send to otherTNO:
  1. tno.Send("Kill", otherTNO.owner);

RFC body:
  1. [RFC]
  2.     void Kill()
  3.     {
  4.         // I Need DESTROY THIS OBJECT, How I can do this? If I write here "tno.DestroySelf();" - Sender will destroy, BUT I NEED destroy other player.
  5.         // You gave me the answer before, destroy by this from sender: otherTNO.DestroySelf(); - but I Need use coroutine on other player before destroy.
  6.        
  7.         GameController.instance.ChangeTo(GameController.instance.RespawnPanel);
  8.     }
Title: Re: Tnet 3.0 How work [RFC] for specific player?
Post by: ArenMook on June 09, 2016, 02:45:00 PM
When you call DestroySelf() on an object, it is destroyed on all connected clients, not just wherever you call it.

I am confused by what you are saying as well: "Sender will destroy, BUT I NEED destroy other player." What's a "sender" vs "other player"? Objects exist on all clients. When you tno.DestroySelf() on one client, all clients will see that object disappear. It doesn't matter if client A calls it or client B does, effect will be the same. It's good practice to only do it on the client that actually owns the object, however.

You are using tno.Send("Kill", otherTNO.owner); -- what this does is calls a function called "Kill" on the otherTNO.owner. This means that whatever is inside the Kill function will be executed on the client that owns otherTNO.

The confusing part is that you seem to be trying to call a function on object A (tno) that should do something based on the owner of an object B (otherTNO). I am not sure why... Why not communicate through the object that you intend to work with (otherTNO)? Generally when you are trying to kill a game unit, you will have some kind of "Kill" function on the game unit's script itself. Calling this script should then call "tno.Send("OnKill", tno.owner, idOfPlayerThatKilledMe);" which will result in the owner calling its "OnKill" function, which can do such things as increment whatever stats you want followed by tno.DestroySelf().

  1. public void Kill (int killerID)
  2. {
  3.     tno.Send("OnKill", tno.owner, killerID);
  4. }
  1. [RFC]
  2. void OnKill (int killerID)
  3. {
  4.     Debug.Log(name + " killed by " + TNManager.GetPlayer(killerID).name);
  5.     tno.DestroySelf();
  6. }