question

Adrià Entreserra avatar image
Adrià Entreserra asked

How to use well cloudscript?

Hey I'm doing a game that has waves and every 10 waves there's a boss, every wave that you pass there will be more enemies. Wave 0-20, 1 enemy more for wave, wave 20-40, 3 enemies.... Of course you have virtual currency and all stuff. I know how to make it offline but I have never used cloud script, so I don't know to what extent the code has to be put on the server. I mean, It's necessary that I have to call every time to cloudscript to know how many enemies has spawned to know if I have to spawn more or I can save it in a variable on unity? I don't know how to do it well that the player can't cheat on it.

I have searched it a lot, but I haven't found anything interesting...

For now I have done that every time you killed all enemies it runs the cloud script.

if (enemiesSpawned != enemiesToSpawn)
{
	int spawnPointToSpawn = Random.Range(0, spawnPoints.Count);
	float temp = Random.Range(2, 5);
	Instantiate(Enemie, spawnPoints[spawnPointToSpawn].transform.position, spawnPoints[spawnPointToSpawn].transform.rotation);
	enemiesSpawned++;
	yield return new WaitForSeconds(waitTime);
	StartCoroutine(Spawn(temp));
}
else if(enemiesSpawned == enemiesToSpawn)
{
	DataBaseManager.DBM.NextWave();
	StartWaves();
}

Every time that all enemies has spawned I add 1 to enemiesToSpawn and I set enemiesSpawned to 0. For that I think that the player can manipulate the enemiesSpawned or the enemiesToSpawn and cheat in the game. I don't know How doing it because every time you spawn an enemy, make a cloud script call, it's so much maybe.

If you reach to 0 lives you have start the game again and all stats will be reset. For now I have made this to reset the wave stat:

handlers.ResetWave = function(args, context) 
{   
	var stat = server.GetPlayerStatistics({ PlayFabId: currentPlayerId, StatisticNam	es: "CurrentLevel" });  
 
	var result = parseInt(stat.Statistics[0].Value);
   	var request = {
	   PlayFabId: currentPlayerId,
	    Statistics: [{                 
		"StatisticName": "Wave",                
		"Value": -(result)                    
			}]                
		};   
server.UpdatePlayerStatistics(request);

};

I think that that's not the best way of doing this. I get the statistic and I update the statistic subtracting the same value.

The last thing is the enemy's script. There will be enemies that have different health and different speed. For that, every time I spawn an enemy I have to take the speed and health from the database? If an enemy has 200 HP It can be modified by the player using cheats? And the speed too?

Thanks for all and sorry for my english.

unity3dCloudScript
10 |1200

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

1 Answer

·
Seth Du avatar image
Seth Du answered

The advantage of Cloud Script is to have any verification steps you want before the players’ data is updated. Based on different game designs, there are different ways for anti-cheating.

According to your descriptions, each level will have different waves, which also have different quantities of enemy respawning in your game. A simple anti-cheat mechanism is to log players’ activities. For example, the client will send synchronization API calls to log the wave that a player has reached and the timestamp (Cloud Script function with JavaScript getTime()). For Each level, you may need to define a static table, and the data should be tested on your own (stores the least time each level will take). Assume a level has 20 waves, the client will send a sync API call every 5 waves and will quit the level immediately if the verification is failed (Remember that API is returned successfully but with a failed result in the payload).

You may also join some other gaming developer community to discuss anti-cheating methods. What I have mentioned above is a simple method and the important thing is that Cloud Script/Azure Function of PlayFab doesn’t only provide the access of server API through the client, but also can contain additional verification steps to prevent abusive uses before the data is updated.

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.

Adrià Entreserra avatar image Adrià Entreserra commented ·

Sorry I'm new with cloudscript so, how do I send a sync API call? And how does playfab database know that the wave and enemies spawned are correct?

What I understand is that every 5 waves I have to check if the client variables are the same in the database, no? And If it's not the same I quit the level.

0 Likes 0 ·
Seth Du avatar image Seth Du ♦ Adrià Entreserra commented ·

What I have mentioned is sending data as parameters of Cloud Script API call. The data is something you code to collect from the client side. The "sync API" simply means ExecuteCloudScript or ExecuteEntityCloudScript to run your customized functions.

The comparison of data doesn't require exact the same value, instead it should be under a tolerant range of the pre-measured data.

0 Likes 0 ·

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.