question

duartedd avatar image
duartedd asked

Matchmaking tutorial to cloudscript

Hello

I remember seeing a matchmaker tutorial that was the playfab api method of finding a match ( i believe using a leaderboard stat) - I am looking for that tutorial - i dont want to create a room or anything but just want to find the players that rank near the specified player's rating so that it can select a best match to play against. I thought i remember i saw a good script on the playfab tutorials section or something but cant seem to locate it anymore (maybe it was replaced by the new microsoft 'preview' stuff?) but was going to use it to convert to just make a cloudscript call to check the leaderboard of the currentplayer that called the script, find a player close to him/her on the leaderboard and return some readonly character data to provide to the client.

thank you!

daniel

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

duartedd avatar image
duartedd answered

ok thanks Andy - ya maybe it was a different I ended up making something quick for now

//get ELO Rating
function GetELORating(args) { 
  var DuelELORatingStat = {
    statname: "DuelELORating",
    playerid: currentPlayerId 
  };
 return  Server.GetPlayerStatistics(DuelELORatingStat);
}


//update ELO Rating
function UpdateELORating(args) { 

var stringifiedJSON = GetELORating(currentPlayerId);

//gotta destring it to provide the value
var destringedvalue = json.somethingtodestringit(stringifiedJSON);



  var DuelELORatingStat = {
    statname: "DuelELORating",
    playerid: currentPlayerId,
   value: destringedvalue.value
  };
  Server.UpdatePlayerStatistics(DuelELORatingStat);
  return true;
}




//update Player statistic
function UpdatePlayerStat(args){
var UpdateStatisticForPlayer = {
   PlayFabId: args.playerid,
  "Statistics": [
    {
      "StatisticName": args.statname,
      "Value": args.statvalue
    }
   ]
};
server.UpdatePlayerStatistics(UpdatePlayerStatistics);
    return true;
}







//elo rating functions
function getRatingDelta(myRating, opponentRating, myGameResult) {
    if ([0, 0.5, 1].indexOf(myGameResult) === -1) {
      return null;
    }
    
    var myChanceToWin = 1 / ( 1 + Math.pow(10, (opponentRating - myRating) / 400));
   return Math.round(32 * (myGameResult - myChanceToWin));
  }


  function getNewRating(myRating, opponentRating, myGameResult) {
    return myRating + getRatingDelta(myRating, opponentRating, myGameResult);
  }

the tutorial i was thinking of was just basically like - had a skill or something not sure if it had a comparison or anything which is what i was looking for -- So here is what i ended up making and needs to fix up a bit - double quoting and trying to destringify JSON things to pull the correct statistic - What i am worried about using this method is that if each function call may impact the request limitations.

2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Andy avatar image Andy ♦♦ commented ·

Which request limit are you specifically concerned about? I can't quite follow the flow of your code above. Which functions are you planning on calling from your client? Overall, you only have a few API calls in there, so I wouldn't worry too much about call volumes. You get 15 API requests per cloud script call, and you're well below that. Any other specific concerns?

0 Likes 0 ·
duartedd avatar image duartedd commented ·

Ok great thanks! I was referring to calling the updateduel which would call other functions in the same cloudscript...like get the rating then Clare the renting with another rating that would exist in the original call..great to know I canake 15 API calls from one call. That should be plenty!

Thanks again!

0 Likes 0 ·
Andy avatar image
Andy answered

I don't recall the precise example you're referring to. We do still have this doc that walks through the whole multiplayer server flow: https://api.playfab.com/docs/tutorials/landing-tournaments/multiplayer-servers, but I don't think that's what you're after. I'll keep an eye out for other samples.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.