Author Topic: Can I make LeaderBoard, use only tNet server?  (Read 2205 times)

Elmo loves cookies

  • Jr. Member
  • **
  • Thank You
  • -Given: 60
  • -Receive: 1
  • Posts: 62
    • View Profile
Can I make LeaderBoard, use only tNet server?
« on: February 08, 2017, 07:24:31 AM »
it is possible to make LeaderBoard without other service(gamesparks.net and others)?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Can I make LeaderBoard, use only tNet server?
« Reply #1 on: February 08, 2017, 08:58:57 AM »
Sure, why not?
  1. [System.Serializable] public class Score
  2. {
  3.     public string name;
  4.     public uint score;
  5. }
  6.  
  7. public List<Score> scoreboard = new List<Score>();
  8.  
  9. public void SetScore (uint value)
  10. {
  11.     tno.Send("OnSetScore", tno.owner, TNManager.playerName, value);
  12. }
  13.  
  14. [RFC]
  15. protected void OnSetScore (string name, uint value)
  16. {
  17.     for (int i = 0; i < scoreboard.size; ++i)
  18.     {
  19.         var pair = scoreboard[i];
  20.  
  21.         if (pair.name == name)
  22.         {
  23.             pair.value = value;
  24.             tno.Send("OnSyncScore", Target.OthersSaved, scoreboard);
  25.             return;
  26.         }
  27.     }
  28.  
  29.     var sc = new Score();
  30.     sc.name = name;
  31.     sc.value = value;
  32.     scoreboard.Add(sc);
  33.     tno.Send("OnSyncScore", Target.OthersSaved, scoreboard);
  34. }
  35.  
  36. [RFC]
  37. protected void OnSyncScore (List<Score> scores) { scoreboard = scores; }

Elmo loves cookies

  • Jr. Member
  • **
  • Thank You
  • -Given: 60
  • -Receive: 1
  • Posts: 62
    • View Profile
Re: Can I make LeaderBoard, use only tNet server?
« Reply #2 on: February 08, 2017, 10:48:33 AM »
can I save scoreboard on server for everyOne? - want to make global leaderBoard

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Can I make LeaderBoard, use only tNet server?
« Reply #3 on: February 13, 2017, 11:38:26 AM »
Yes -- that code will work for that too. Just join a common server-wide channel first, and make sure that the object with that RFC attached is instantiated in that global channel.

For example in Sightseer for me, all players join a "global" channel. It's used for sever-wide chat and other things. Remember, TNet supports multiple concurrent channels. You aren't limited to just one.