Author Topic: Syncing Health Problem  (Read 2176 times)

WolfTechGames

  • Newbie
  • *
  • Thank You
  • -Given: 6
  • -Receive: 4
  • Posts: 35
    • View Profile
Syncing Health Problem
« on: October 21, 2015, 09:14:07 PM »
I am currently trying to sync the health of the monster in my game but as both users attack the monster, the monster health receives the flip flop effect where the hp jumps since the other players has a different value.

  1.     IEnumerator callSyncHP()
  2.         {
  3.                 if (lastHP != stats.Health) {
  4.                         tno.Send ("syncHP", TNet.Target.AllSaved, stats.Health);
  5.                         lastHP = stats.Health;
  6.                 }
  7.                 yield return new WaitForSeconds (0.2f);
  8.                 StartCoroutine (callSyncHP ());
  9.         }
  10.  
  11.         [RFC]
  12.         void syncHP(int hp)
  13.         {
  14.                 stats.Health = hp;
  15.         }
  16.  

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Syncing Health Problem
« Reply #1 on: October 24, 2015, 05:04:45 AM »
All health changing requests need to go through the owner.
  1. public void DamageMe (float dmg)
  2. {
  3.     if (tno.isMine) OnDamage(dmg);
  4.     else tno.Send("OnDamage", tno.ownerID, dmg);
  5. }
  6.  
  7. [RFC] protected void OnDamage (float dmg)
  8. {
  9.     stats.Health -= dmg;
  10.     tno.Send("OnHealth", Target.OthersSaved, stats.Health);
  11. }
  12.  
  13. [RFC] protected void OnHealth (float hp)
  14. {
  15.     stats.Health = hp;
  16. }

WolfTechGames

  • Newbie
  • *
  • Thank You
  • -Given: 6
  • -Receive: 4
  • Posts: 35
    • View Profile
Re: Syncing Health Problem
« Reply #2 on: October 24, 2015, 06:11:03 PM »
All health changing requests need to go through the owner.

Thank you very much! :D Amazing Support!