Sign In Register

How can we help you today?

Start a new topic
Answered

Bots

Hi, I need a bot for my matchmaking so that a player can enter a match without waiting for a long time. I figured this out already but now I'm clueless on how can my bot send its own requests. I need it to send scores to the leaderboards. 

And do you have any tips on creating bots? because what I did now was to put my bot auth on my matchnotfound message.

Thanks 
 


Best Answer

You can do this using a maual drop-in/drop-out match.
In order to do this, the player and the bot need to enter matchmaking, and then you get the bot to join the match.
The player and the bot will then get the matchfoundmessage


 

// find match as me //
var matchReq1 = new SparkRequests.MatchmakingRequest()
matchReq1.matchShortCode = "level_a";
matchReq1.matchGroup = "player1_friends";
matchReq1.skill = 0;
matchReq1.Send();
// // find match as dummy //
var matchReq1 = new SparkRequests.MatchmakingRequest()
matchReq1.matchShortCode = "level_a";
matchReq1.skill = 0;
matchReq1.SendAs("588072be23791d04bdab1313");
// search pending matches as dummy //
var request = new SparkRequests.FindPendingMatchesRequest();
request.matchShortCode = "level_a";
request.maxMatchesToFind = 1;
var response = request.SendAs("588072be23791d04bdab1313");
var pendingMatchId = response.pendingMatches[0].id; 
// join dummy into player1 match //
var joinReq = new SparkRequests.JoinPendingMatchRequest();
joinReq.pendingMatchId = pendingMatchId;
joinReq.matchShortCode = "level_a";
joinReq.SendAs("588072be23791d04bdab1313");

 


1 person has this question

Hi Erika,


You don't need to authenticate bot players. You can send and execute requests as players in Cloud Code so you could do this with a bot. Check the example below, it is an AccountDetailsRequest sent as another player. The response will contain the details of the player it has been sent as.

 

//the playerID variable will be the id of the bot player
var request = new SparkRequests.AccountDetailsRequest();
var response = request.SendAs(playerID);

//you can also use ExecuteAs(playerID). This will send the event as the given player and execute any Cloud code attached to the event

 

Try that and let us know if you have any further questions.


Thanks,

Liam



I ended up using ExecuteAs().

 

var botresponse = botrequest.ExecuteAs(botid);

  

As for not authenticating my bots. I can't do that since my bots participate in matchmaking. I tried using pendingmatch but I don't know why my pendingmatch can't be a matchinstance even If I added two players (min players for my match). So what I did was to send a matchmaking request for both my bot and user in the matchnotfound message.


1 person likes this
Answer

You can do this using a maual drop-in/drop-out match.
In order to do this, the player and the bot need to enter matchmaking, and then you get the bot to join the match.
The player and the bot will then get the matchfoundmessage


 

// find match as me //
var matchReq1 = new SparkRequests.MatchmakingRequest()
matchReq1.matchShortCode = "level_a";
matchReq1.matchGroup = "player1_friends";
matchReq1.skill = 0;
matchReq1.Send();
// // find match as dummy //
var matchReq1 = new SparkRequests.MatchmakingRequest()
matchReq1.matchShortCode = "level_a";
matchReq1.skill = 0;
matchReq1.SendAs("588072be23791d04bdab1313");
// search pending matches as dummy //
var request = new SparkRequests.FindPendingMatchesRequest();
request.matchShortCode = "level_a";
request.maxMatchesToFind = 1;
var response = request.SendAs("588072be23791d04bdab1313");
var pendingMatchId = response.pendingMatches[0].id; 
// join dummy into player1 match //
var joinReq = new SparkRequests.JoinPendingMatchRequest();
joinReq.pendingMatchId = pendingMatchId;
joinReq.matchShortCode = "level_a";
joinReq.SendAs("588072be23791d04bdab1313");

 

Login to post a comment