Your game can have multiple achievements for players to unlock.
Each achievement can have a different score. The score is usually between 5 and 100, which is really something you need to choose based on the achievement. Generally, give low values to easy-to-achieve things and a high value to hard-to-achieve things. Have many low value, and few high value.
When a player unlocks the achievement, the score is added to their global score.
You have full control over choosing the score but the total combined for your game cannot exceed 1000.
The icon is automatically resized to 128x128. It will generally be rendered quite small, next to the name of the achievement, so should be treated more like an icon than a picture.
When your achievement unlock mode is set to "Stat" it will automatically be unlocked for you. All you need to do is make sure the stat is set up properly.
An example of a stat based achievement would be the "100 coins".
You would do Stat.Increment( "coins", 1 )
in your code every time you collected a coin, then you can set your achievement to this..
Property | Value | Explanation |
---|---|---|
Target Stat | "coin" | |
Aggregation | Sum | |
Min Value | 0 | |
Max Value | 100 | |
Show Progress | true |
If the stat is set to manual, then you can unlock it in your code like this:
Sandbox.Services.Achievements.Unlock( "statname" );
You can get the list of achievements at any time in your game
foreach ( var a in Sandbox.Services.Achievements.All )
{
// do something
}
Or from outside the game, you can access it via the API
https://services.facepunch.com/sbox/achievement/list?package=facepunch.testbed