playMaker

Author Topic: Google Play Service Get Rank From Leaderboard  (Read 3929 times)

Xenocalypse

  • Playmaker Newbie
  • *
  • Posts: 13
Google Play Service Get Rank From Leaderboard
« on: November 17, 2016, 10:13:22 AM »
Hello, and thx in advance for this great Plugin.

I only use Playmaker and Stans Android native Actions, to make my games.

Now i would like to show the current Rank of the Player in the Leaderboard.
There is an Action in Stans asset Called AN_getScore. But there Support don´t want to implement to get the current rank, only Score. As i have no idea from coding, i still know there is this function and i saw it in many games.

Here is the GetScore Action, and my question...could this be modified to get rank instead of Score.

namespace HutongGames.PlayMaker.Actions {
   
   [ActionCategory("Android Native - PlayService")]
   public class AN_GetScore : FsmStateAction {
      
      public FsmString leaderboardId;
      public FsmInt score;
      public GPBoardTimeSpan timeSpan;
      public GPCollectionType collection;
      
      
      public override void OnEnter() {
         if(GooglePlayManager.IsLeaderboardsDataLoaded) {
            GetScores();
         } else {
            GooglePlayManager.ActionLeaderboardsLoaded += ActionLeaderboardsLoaded;
         }
         
      }

      private void ActionLeaderboardsLoaded (GooglePlayResult obj) {
         GetScores() ;
      }


      public void GetScores() {
         GPLeaderBoard board =  GooglePlayManager.Instance.GetLeaderBoard(leaderboardId.Value);
         score.Value  = 0;
         if(board != null) {
            score.Value = (int) board.GetCurrentPlayerScore(timeSpan, collection).LongScore;
         }

         Finish();
      }
      
   }
}


I´m very very thankful to have Playmaker, and it´s a pleasure to work with,
so many thx for your work done.

If there is any other way to achieve that. I´m Listening

Regards Xeno

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Google Play Service Get Rank From Leaderboard
« Reply #1 on: November 18, 2016, 02:20:14 AM »
Hi,

 The first thing to do is to find a script that shows how it's done, then you can port it in an PlayMaker actions.

Does stan assets comes with demos? if you have a demos that shows rank, then we're good to go.

Bye,

 Jean
 

Xenocalypse

  • Playmaker Newbie
  • *
  • Posts: 13
Re: Google Play Service Get Rank From Leaderboard
« Reply #2 on: November 18, 2016, 08:27:39 AM »
First Thank you So much for your reply.

Yeah i found an Example for that. It´s a Custom Leaderboard.
I just need an Action Putting the rank out in a String.
But i Attached the corresponding Scripts,too.

But the Interisting Script should be PlayserviceCustomLBExample.cs.

I cant tell you how thankful i´am for your time.

Edit: I don´t need the whole Leaderboard or rank from different players.
Just the current Rank of the Player logged in, like in the Action i posted before,
just rank, and not Score.


« Last Edit: November 18, 2016, 08:32:42 AM by Xenocalypse »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Google Play Service Get Rank From Leaderboard
« Reply #3 on: November 21, 2016, 02:53:16 AM »
Hi,

 these scripts do not deal with rank per say.

 what you need to ask for is how to get a ran for a given player. If I have a code sample doing just that, then I can help you translate it into an action.

one way would be to get all scores and find out the rnak by finding your player in the list of scores and the index of your player is the rank.

If Stan's validate this as the only way to get the rank for the player, then that'll be it and we can move into doing this.

 Bye,

 Jean

Xenocalypse

  • Playmaker Newbie
  • *
  • Posts: 13
Re: Google Play Service Get Rank From Leaderboard
« Reply #4 on: November 21, 2016, 05:05:27 AM »
Hey, thanks for your Help.

Good things first, i figured it out, wich is really funny because it´s very easy...

For those who want to do the same, Just take the Get Scores Action i posted first,
Give it another Action Name, and than

last Code:
            score.Value = (int) board.GetCurrentPlayerScore(timeSpan, collection).LongScore;

Change to:

score.Value = (int) board.GetCurrentPlayerScore(timeSpan, collection).Rank;

Yes it´s just one Word.

So it will show you your rank outside the Google Leaderboard, tuff there is still a problem,
If The leaderboard is Active, it don´t Update. Whatever i do´.

The only way the the Statspage i create update the Rank, is open my Leaderboard in Game, Choose the Specific Leaderboard wich Scores Changed, If i close the Leaderboard than and go Back to the Statistic Scene, it Update the Rank for that Leaderboard.

Cheers so far

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Google Play Service Get Rank From Leaderboard
« Reply #5 on: November 21, 2016, 05:17:14 AM »
Hi,

 Excellent!

bye,

 Jean