StatsAndAchievements.Client
Like what your seeing?
Support us as a GitHub Sponsor and get instant access to all our assets, exclusive tools and assets, escalated support and issue tracking and our gratitude. These articles are made possible by our GitHub Sponsors ... become a sponsor today!
Introduction
All features available to 1 are present in the other with some minor exceptions. The only notable difference is that Server related calls required you to provide the CSteamID of the user to be adjusted and will only work when that user is authenticated to the Steam Game Server that calls the method.
What can it do?
Set and reset Steam Stats and Achievements. Most of the features of the StatsAndAchievments interface can be accessed through its related objects.
Related Objects
Events
EventUserStatsReceived
Called when the latest stats and achievements for a specific user (including the local user) have been received from the server.
You would add a listener on this event such as:
Assuming a handler in the form of
Then you would register the event such as:
When you no longer need this handler you should remove it for example when the behaviour using it is destroyed
EventUserStatsUnloaded
Callback indicating that a user's stats have been unloaded.
Assuming a handler in the form of
Then you would register the event such as:
When you no longer need this handler you should remove it for example when the behaviour using it is destroyed
EventUserStatsStored
Callback indicating that a user's stats have been stored.
Assuming a handler in the form of
Then you would register the event such as:
When you no longer need this handler you should remove it for example when the behaviour using it is destroyed
EventUserAchievementStored
Callback indicating that a user's achievements have been stored.
Assuming a handler in the form of
Then you would register the event such as:
When you no longer need this handler you should remove it for example when the behaviour using it is destroyed
Methods
ClearAchievement
Resets the achievement unlock state.
GetAchievement
or
or
Gets the achievement status and date the achievement was unlocked if at all. This can be done for the local player or for a specific player by providing the player's ID
GetAchievementAchievedPercent
Returns the percentage of users who have unlocked the specified achievement
GetAchievementDisplayAttribute
Get general attributes for an achievement. Currently provides Name, Description and Hidden status
GetAchievementIcon
Gets the icon for an achievement
The callback would take the form of
GetAchievementName
Get the API Name for an achievement index between 0 and GetNumAchievements
GetAchievementNames
Get a list of all achievement names registered to the app
GetGlobalStat
or
Gets the lifetime total for an aggregated stat.
You must call RequestGlobalStats before you try to read them.
GetMostAchievedAchievements
Gets a collection of the "most achieved achievements" this is a collection sorted by the statistically most achieved achievements for the game globally. The first entry will be the most achieved achievement globally with the last entry being the least.
The callback for this should take the following form
GetMostAchievedAchievementInfo
Gets the info on the next most achieved achievement for the game.
You must have called RequestGlobalAchievementPercentages and it needs to return successfully via its callback prior to calling this.
previousIndex Iterator returned from the previous call to this method or from GetMostAchievedAchievementInfo
achievementApiName will be populated with the achievement name
percent will be populated with the percentage of people that have achieved this
achieved true if the current user has this achievement unlocked
GetNumAchievements
Get the number of achievements defined in the App Admin panel of the Steamworks web site.
GetNumberOfCurrentPlayers
Asynchronously retrieves the total number of players currently playing the current game. Both online and in offline mode.
The callback would take the form of
GetStat
or
or
or
Gets the current value of the stat, optionally you can provide a user for whom you would like to get the stat of.
IndicateAchievementProgress
Shows the user a pop-up notification with the current progress of an achievement.
Calling this function will NOT set the progress or unlock the achievement, the game must do that manually by calling SetStat!
RequestCurrentStats
Asynchronously request the user's current stats and achievements from the server.
You must always call this first to get the initial status of stats and achievements. Only after the resulting callback comes back can you start calling the rest of the stats and achievement functions for the current user.
When we initialize the Steam API for you via our Steamworks Behaviour will will call this for you. You shouldn't ever need to call this your self.
RequestGlobalAchievementPercentages
Asynchronously fetch the data for the percentage of players who have received each achievement for the current game globally.
RequestGlobalStats
Asynchronously fetches global stats data, which is available for stats marked as "aggregated" in the App Admin panel of the Steamworks website.
The callback for this method should take the form
RequestUserStats
Asynchronously downloads stats and achievements for the specified user from the server.
To keep from using too much memory, an least recently used cache (LRU) is maintained and other user's stats will occasionally be unloaded. When this happens a UserStatsUnloaded_t callback is sent. After receiving this callback the user's stats will be unavailable until this function is called again.
The callback for this method should take the form
ResetAllStats
Resets all stats, if you pass true
in on the achievementToo parameter then it will also reset all achievements.
SetAchievement
Unlocks the achievement identified
SetStat
or
Sets / updates the value of a given stat for the current user.
statApiName The
API Name
of the stat. Must not be longer than k_cchStatNameMax.data The new value of the stat. This must be an absolute value. it will not increment or decrement for you!
StoreStats
Send the changed stats and achievements data to the server for permanent storage.
If this fails then nothing is sent to the server. It's advisable to keep trying until the call is successful. This call can be rate limited. Call frequency should be on the order of minutes, rather than seconds. You should only be calling this during major state changes such as the end of a round, the map changing, or the user leaving a server. This call is required to display the achievement unlock notification dialog though, so if you have called SetAchievement then it's advisable to call this soon after that.
UpdateAvgRateStat
Updates an AVGRATE stat with new values.
statApiName The 'API Name' of the stat. Must not be longer than k_cchStatNameMax.
countThisSession The value accumulation since the last call to this function.
sessionLength The amount of time in seconds since the last call to this function.
How To
Clear Achievements and Stats
You can clear achievements either by using the interface
or by using the Achievement Object directly
Resetting a stat is as simple as setting its value, see the Int Stat and Float Stat object for details
You can optionally reset all stats and achievements
Set a Stat or Achievement
Its generally simplest to use the artifact object directly so the Achievement Object, Int Stat or Float Stat. You can also set them through the interface
Last updated