Sign In Register

How can we help you today?

Start a new topic
Answered

Starter pack of items for new users

Hi!


My question is quite simple but I'm not sure in how to achieve it. I want to give a set of items (store items) to new players, similar to the starting currency values.


I have an event that gives a player those items. Right now, after login in, I check in the client if the player is new, and if it is, I call the event. Would it be possible to trigger this event somehow from GameSparks, without calling the event explicitly form the client? 


Or if there is a better way to achieve this that I don't know, I would appreciate the hint.


Best Answer

 Hey Mario,

The method Dustin suggested is a good way of achieving this, however i'd recommend you do this in RegistrationRequest cloud-code, as this will only get called when the player is first registered. In case you have the registration request providing authentication as well (as it does both) you can check to see if the player is new first. Check out the code-sample below. We suggest this as a way to create a list of player details you can use to loop through to find a specific player. You can adapt this to gift the new player some goods.



 

 

var currentPlayer = Spark.runtimeCollection("playerList").findOne({ "userName" : Spark.getData().userName, "password" : Spark.getData().password});

if(currentPlayer === null) // the player does now exist, so lets register them
{
    var newPlayerForm = {
    
    "userName" : Spark.getData().userName,
    "displayName" : Spark.getData().displayName,
    "password" : Spark.getData().password,
    "isOnLine" : false,

    "playerID" : Spark.getPlayer().getPlayerId()
    
    };
	
	// add some virtual goods //
	Spark.getPlayer().addVGood("your item", quantity);

    Spark.runtimeCollection("playerList").insert(newPlayerForm);
}
else 
{

}

Hope that helps,
-Sean

 

 


I am a new GS user as well but here is an  idea that may work.

In your Cloud Code, System, Player Connected Event, check for a particular piece of Player Data that only exists after the first login.

If it doesnt exist, call your Custom Event that adds items for your new player and then sets the Player Data(SparkPlayer.setprivatedata) to let you know it isn't a new player anymore.

Or you could even use the achievement system I would imagine to record an achievement for the first time they login and use that as your flag to check for in the  Player Connected System Event.


 

Answer

 Hey Mario,

The method Dustin suggested is a good way of achieving this, however i'd recommend you do this in RegistrationRequest cloud-code, as this will only get called when the player is first registered. In case you have the registration request providing authentication as well (as it does both) you can check to see if the player is new first. Check out the code-sample below. We suggest this as a way to create a list of player details you can use to loop through to find a specific player. You can adapt this to gift the new player some goods.



 

 

var currentPlayer = Spark.runtimeCollection("playerList").findOne({ "userName" : Spark.getData().userName, "password" : Spark.getData().password});

if(currentPlayer === null) // the player does now exist, so lets register them
{
    var newPlayerForm = {
    
    "userName" : Spark.getData().userName,
    "displayName" : Spark.getData().displayName,
    "password" : Spark.getData().password,
    "isOnLine" : false,

    "playerID" : Spark.getPlayer().getPlayerId()
    
    };
	
	// add some virtual goods //
	Spark.getPlayer().addVGood("your item", quantity);

    Spark.runtimeCollection("playerList").insert(newPlayerForm);
}
else 
{

}

Hope that helps,
-Sean

 

 

Login to post a comment