Author Topic: [SOLVED] Tnet + HUDText  (Read 2844 times)

CastorHolyday

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 20
    • View Profile
[SOLVED] Tnet + HUDText
« on: January 12, 2014, 01:04:46 PM »
Hello, one simple question, pretty much deep though :

Suppose I have a server 3 players are connected A, B, C.

A hits B : B sees the damages because A called a function inside B to reduce his health.

What if I want that player A (the attacker) to see the damages he did to B using HUDText over B's player head.

What if I want the player C (the Spectator) to also see the damages generated by A attacking B.

Where & When should I call the tno.Send, and what arguments should be passed.

Thank you all for your responses.

[SOLVED]
« Last Edit: January 14, 2014, 11:29:15 AM by CastorHolyday »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tnet + HUDText
« Reply #1 on: January 12, 2014, 06:06:17 PM »
It's up to you to whom you send your RFC and what happens within. If you don't want certain people to see the damage, the easiest thing to do would be to have a condition check inside your RFC that validates the need. For example by passing the team ID to your RFC:

tno.Send("ApplyDamage", Target.All, damage, myTeamID);

Inside ApplyDamage check to see if the "myTeamID" is the same team, or if the player is a spectator, and if so, do a HUDText.Add.

CastorHolyday

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 20
    • View Profile
Re: [SOLVED] Tnet + HUDText
« Reply #2 on: January 12, 2014, 07:22:44 PM »
Aren ! regardless of your programming talent, and game design geniusness, you have a great gift at teaching too, even if you may ignore it, you can make complexe stuff look simple. Gimme a bro hug buddy :D

Thanks much respect  ;)

CastorHolyday

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 20
    • View Profile
Re: [SOLVED] Tnet + HUDText
« Reply #3 on: January 13, 2014, 02:33:07 PM »
EDIT : actually I'm still having some issues !

Hello,

I'm using a Progressebar UISlider object to display health of players, created from prefabs "player" in HUD, everything works fine.

But if I have more than 2 players in the same "room", still everything works okay in term of displays, but recently I discovered 2 issues :

One : if a player leave the game (alt+f4), the UIFollowTarget will throw Transform null reference, because the HUD is still existing and so is the healthbar.

More details : How to handle disconnections of players knowing that i'm currently using this function to remove the HUD Object that was responsible of displaying NGUI stuff of the disconnected player and that I don’t need anymore since the player has left, so the Body of the player is automatically removed while the HUD remains in the UIRoot and keeps sending errors of null reference in the console because UIFollowTarget can’t find its target anymore here is my function :

OnNetworkPlayerLeave(Player p)
{
              Debug.Log("Player Disconnected");
   tno.Send("OnDeath", Target.All, HUDParent, healthBarRef); //Line 123
}

Line 123 : sending the HUD as a GameObject & HealthBar as a UISlider component just in case I want to use it but this rfc call triggers a error :

So why I can't send a specific GameObject to all other clients so they remove it from their screen.

The way I understood it, it should work, unless it has somthing to do with custom packets.

Or there is a better way to handle this situation.

Basically I want the HUD to disappear with the Prefab player that the player controls when he is connected, and that is magically deleted if he leaves, but the work is not completely done, I want it to delete the HUD too.
I didn't explained it well, but when player B leave the game his HUD remains in the screen including his healthbar with no target to follow just floating around where the player B were lastly before he disconnects.

Two : Sync Problem : if player A is connected, Player B is not connected yet, player A got hit and had his HP droped down to 40%, player B once connected after this has happened will see player A 100% HP, what I'm doing rightnow is using a rfc call each time player A hp are decreasing : tno.Send("HitPlayer", Target.AllSaved, Dmg);
and it applies dmg to the target that should be hit, in screen A I can see the real value say 35% of the UISlider.value, but in Screen B the player that connected in “delay” I see that it has 100% hp

How to sync healthbar values that are GameObjects inside of UIRoot using HUDText asset which have on them UIFollowTarget & UISlider, I'm sending RFC(S), each time the healthbar value decreases to Target.AllSaved what am I doing wrong ?

Just some guide lines, I'm still learning about TNet all I have is a basic idea of how Networking works.

Best wishes and thanks for your time.
« Last Edit: January 14, 2014, 11:29:31 AM by CastorHolyday »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: [UNSOLVED] Tnet + HUDText
« Reply #4 on: January 13, 2014, 06:28:33 PM »
You shouldn't send TNO calls from OnNetworkPlayerLeave, because every player already gets this notification, so there is no need to send an extra sync'd message. You are safe to Destroy() the object in OnNetworkPlayerLeave.

CastorHolyday

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 20
    • View Profile
Re: [SOLVED] Tnet + HUDText
« Reply #5 on: January 14, 2014, 11:31:45 AM »
I Fixed it thanks for the advice.
The second problem I had was due to a Null reference I had to check to see if it points to a null object, before trying, I read in a post of yours that when a exeption is thrown in most cases it's a null ref !

If anyone is having the same issue MP me I may help. :)

Have a nice day.