Skip to content

Commit

Permalink
Added user_stats_find_or_create_leaderboard()
Browse files Browse the repository at this point in the history
  • Loading branch information
britzl committed Mar 20, 2024
1 parent 284105d commit 8eebf80
Show file tree
Hide file tree
Showing 7 changed files with 250 additions and 10 deletions.
99 changes: 96 additions & 3 deletions api.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,30 @@
"summary": "Requests all the rows for friends of the current user",
"usage": null
},
{
"description": "",
"field": true,
"field_type": "ELeaderboardSortMethodAscending",
"has_params": false,
"has_returns": false,
"name": "ELeaderboardSortMethodAscending",
"params": [],
"returns": [],
"summary": "Top-score is lowest number",
"usage": null
},
{
"description": "",
"field": true,
"field_type": "ELeaderboardSortMethodNone",
"has_params": false,
"has_returns": false,
"name": "ELeaderboardSortMethodNone",
"params": [],
"returns": [],
"summary": "Top-score is highest number",
"usage": null
},
{
"description": "",
"field": true,
Expand All @@ -123,6 +147,42 @@
"summary": "Leaderboard will always replace score with specified",
"usage": null
},
{
"description": "",
"field": true,
"field_type": "ELeaderboardDisplayTypeNumeric",
"has_params": false,
"has_returns": false,
"name": "ELeaderboardDisplayTypeNumeric",
"params": [],
"returns": [],
"summary": "Simple numerical score",
"usage": null
},
{
"description": "",
"field": true,
"field_type": "ELeaderboardDisplayTypeTimeSeconds",
"has_params": false,
"has_returns": false,
"name": "ELeaderboardDisplayTypeTimeSeconds",
"params": [],
"returns": [],
"summary": "The score represents a time, in seconds",
"usage": null
},
{
"description": "",
"field": true,
"field_type": "ELeaderboardDisplayTypeTimeMilliSeconds",
"has_params": false,
"has_returns": false,
"name": "ELeaderboardDisplayTypeTimeMilliSeconds",
"params": [],
"returns": [],
"summary": "The score represents a time, in milliseconds",
"usage": null
},
{
"description": "",
"field": true,
Expand Down Expand Up @@ -1034,6 +1094,39 @@
"summary": "Returns the percentage of users who have achieved the specified achievement.",
"usage": null
},
{
"description": "This call is asynchronous, with the result returned in a listener callback with event set to LeaderboardFindResult_t.",
"has_params": true,
"has_returns": true,
"name": "user_stats_find_or_create_leaderboard",
"params": [
{
"description": "The name of the leaderboard to find or create.",
"name": "leaderboard_name",
"type": "string"
},
{
"description": "The sort order of the new leaderboard if it's created.",
"name": "eLeaderboardSortMethod",
"type": "ELeaderboardSortMethod"
},
{
"description": "The display type (used by the Steam Community web site) of the new leaderboard if it's created.",
"name": "eLeaderboardDisplayType",
"type": "ELeaderboardDisplayType"
}
],
"params_string": "leaderboard_name,eLeaderboardSortMethod,eLeaderboardDisplayType",
"returns": [
{
"description": "",
"name": "handle",
"type": "string"
}
],
"summary": "Gets a leaderboard by name, it will create it if it's not yet created.",
"usage": null
},
{
"description": "This call is asynchronous, with the result returned in a listener callback with event set to LeaderboardScoresDownloaded_t. LeaderboardScoresDownloaded_t will contain a handle to pull the results from GetDownloadedLeaderboardEntries(). You can ask for more entries than exist, and it will return as many as do exist. * k_ELeaderboardDataRequestGlobal requests rows in the leaderboard from the full table, with nRangeStart & nRangeEnd in the range [1, TotalEntries] * k_ELeaderboardDataRequestGlobalAroundUser requests rows around the current user, nRangeStart being negate e.g. DownloadLeaderboardEntries( hLeaderboard, k_ELeaderboardDataRequestGlobalAroundUser, -3, 3 ) will return 7 rows, 3 before the user, 3 after * k_ELeaderboardDataRequestFriends requests all the rows for friends of the current user",
"has_params": true,
Expand Down Expand Up @@ -1079,8 +1172,8 @@
"name": "user_stats_get_downloaded_leaderboard_entry",
"params": [
{
"description": "Leaderboard handle",
"name": "leaderboard",
"description": "Leaderboard entries handle",
"name": "hSteamLeaderboardEntries",
"type": "string"
},
{
Expand All @@ -1089,7 +1182,7 @@
"type": "number"
}
],
"params_string": "leaderboard,index",
"params_string": "hSteamLeaderboardEntries,index",
"returns": [
{
"description": "",
Expand Down
42 changes: 40 additions & 2 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ Requests all the rows for friends of the current user



### ELeaderboardSortMethodAscending [`ELeaderboardSortMethodAscending`]
Top-score is lowest number



### ELeaderboardSortMethodNone [`ELeaderboardSortMethodNone`]
Top-score is highest number



### ELeaderboardUploadScoreMethodKeepBest [`ELeaderboardUploadScoreMethodKeepBest`]
Leaderboard will keep user's best score

Expand All @@ -69,6 +79,21 @@ Leaderboard will always replace score with specified



### ELeaderboardDisplayTypeNumeric [`ELeaderboardDisplayTypeNumeric`]
Simple numerical score



### ELeaderboardDisplayTypeTimeSeconds [`ELeaderboardDisplayTypeTimeSeconds`]
The score represents a time, in seconds



### ELeaderboardDisplayTypeTimeMilliSeconds [`ELeaderboardDisplayTypeTimeMilliSeconds`]
The score represents a time, in milliseconds



### EOverlayToStoreFlag_None [`EOverlayToStoreFlag_None`]
Passed as parameter to the store

Expand Down Expand Up @@ -509,6 +534,19 @@ RETURNS
* `percent` [`Number`] -


### user_stats_find_or_create_leaderboard(leaderboard_name,eLeaderboardSortMethod,eLeaderboardDisplayType)
Gets a leaderboard by name, it will create it if it's not yet created. This call is asynchronous, with the result returned in a listener callback with event set to LeaderboardFindResult_t.


PARAMS
* `leaderboard_name` [`string`] - The name of the leaderboard to find or create.
* `eLeaderboardSortMethod` [`ELeaderboardSortMethod`] - The sort order of the new leaderboard if it's created.
* `eLeaderboardDisplayType` [`ELeaderboardDisplayType`] - The display type (used by the Steam Community web site) of the new leaderboard if it's created.

RETURNS
* `handle` [`string`] -


### user_stats_download_leaderboard_entries(leaderboard,request,start,end)
Asks the Steam back-end for a set of rows in the leaderboard. This call is asynchronous, with the result returned in a listener callback with event set to LeaderboardScoresDownloaded_t. LeaderboardScoresDownloaded_t will contain a handle to pull the results from GetDownloadedLeaderboardEntries(). You can ask for more entries than exist, and it will return as many as do exist. * k_ELeaderboardDataRequestGlobal requests rows in the leaderboard from the full table, with nRangeStart & nRangeEnd in the range [1, TotalEntries] * k_ELeaderboardDataRequestGlobalAroundUser requests rows around the current user, nRangeStart being negate e.g. DownloadLeaderboardEntries( hLeaderboard, k_ELeaderboardDataRequestGlobalAroundUser, -3, 3 ) will return 7 rows, 3 before the user, 3 after * k_ELeaderboardDataRequestFriends requests all the rows for friends of the current user

Expand All @@ -523,12 +561,12 @@ RETURNS
* `handle` [`string`] -


### user_stats_get_downloaded_leaderboard_entry(leaderboard,index)
### user_stats_get_downloaded_leaderboard_entry(hSteamLeaderboardEntries,index)
Returns data about a single leaderboard entry


PARAMS
* `leaderboard` [`string`] - Leaderboard handle
* `hSteamLeaderboardEntries` [`string`] - Leaderboard entries handle
* `index` [`number`] - Which entry to get

RETURNS
Expand Down
13 changes: 10 additions & 3 deletions examples/user_stats/user_stats.gui_script
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ function init(self)
elseif e == "GlobalStatsReceived_t" then
msg.post("#", "refresh_global_stats", t)
elseif e == "LeaderboardFindResult_t" then
if not t.m_bLeaderboardFound then
print("Unable to find leaderboard")
return
end
local new_score = math.random(1, 100000)
steam.user_stats_upload_leaderboard_score(t.m_hSteamLeaderboard, steam.ELeaderboardUploadScoreMethodForceUpdate, new_score)
steam.user_stats_download_leaderboard_entries(t.m_hSteamLeaderboard, steam.ELeaderboardDataRequestGlobal, 1, 10)
elseif e == "LeaderboardScoresDownloaded_t" then
msg.post("#", "refresh_leaderboard", t)
Expand All @@ -34,9 +40,7 @@ function init(self)
steam.user_stats_request_current_stats()
steam.user_stats_request_global_stats(7)
steam.user_stats_find_leaderboard("Feet Traveled")

local new_score = math.random(1, 100000)
steam.user_stats_upload_leaderboard_score("Feet Traveled", steam.ELeaderboardUploadScoreMethodForceUpdate, new_score)
--steam.user_stats_find_or_create_leaderboard("Meters Traveled", steam.ELeaderboardSortMethodAscending, steam.ELeaderboardDisplayTypeNumeric)
end

function final(self)
Expand Down Expand Up @@ -129,6 +133,9 @@ function on_message(self, message_id, message, sender)
local name = steam.friends_get_friend_persona_name(details.m_steamIDUser)
local s = ("#%d %s - %d"):format(details.m_nGlobalRank, name, details.m_nScore)
table.insert(entries, s)
else
print("Unable to get leaderboard entry")
pprint(message.m_hSteamLeaderboardEntries)
end
end
local text = LEADERBOARD:format(name, table.concat(entries, "\n"))
Expand Down
42 changes: 40 additions & 2 deletions steam/api/steam.script_api
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@
type: number
desc: Requests all the rows for friends of the current user

- name: ELeaderboardSortMethodAscending
type: number
desc: Top-score is lowest number

- name: ELeaderboardSortMethodNone
type: number
desc: Top-score is highest number

- name: ELeaderboardUploadScoreMethodKeepBest
type: number
desc: Leaderboard will keep user's best score
Expand All @@ -50,6 +58,18 @@
type: number
desc: Leaderboard will always replace score with specified

- name: ELeaderboardDisplayTypeNumeric
type: number
desc: Simple numerical score

- name: ELeaderboardDisplayTypeTimeSeconds
type: number
desc: The score represents a time, in seconds

- name: ELeaderboardDisplayTypeTimeMilliSeconds
type: number
desc: The score represents a time, in milliseconds

- name: EOverlayToStoreFlag_None
type: number
desc: Passed as parameter to the store
Expand Down Expand Up @@ -468,6 +488,24 @@
type: Number


- name: user_stats_find_or_create_leaderboard
type: function
desc: Gets a leaderboard by name, it will create it if it's not yet created. This call is asynchronous, with the result returned in a listener callback with event set to LeaderboardFindResult_t.
parameters:
- name: leaderboard_name
type: string
desc: The name of the leaderboard to find or create.
- name: eLeaderboardSortMethod
type: ELeaderboardSortMethod
desc: The sort order of the new leaderboard if it's created.
- name: eLeaderboardDisplayType
type: ELeaderboardDisplayType
desc: The display type (used by the Steam Community web site) of the new leaderboard if it's created.
returns:
- name: handle
type: string


- name: user_stats_download_leaderboard_entries
type: function
desc: Asks the Steam back-end for a set of rows in the leaderboard. This call is asynchronous, with the result returned in a listener callback with event set to LeaderboardScoresDownloaded_t. LeaderboardScoresDownloaded_t will contain a handle to pull the results from GetDownloadedLeaderboardEntries(). You can ask for more entries than exist, and it will return as many as do exist. * k_ELeaderboardDataRequestGlobal requests rows in the leaderboard from the full table, with nRangeStart & nRangeEnd in the range [1, TotalEntries] * k_ELeaderboardDataRequestGlobalAroundUser requests rows around the current user, nRangeStart being negate e.g. DownloadLeaderboardEntries( hLeaderboard, k_ELeaderboardDataRequestGlobalAroundUser, -3, 3 ) will return 7 rows, 3 before the user, 3 after * k_ELeaderboardDataRequestFriends requests all the rows for friends of the current user
Expand All @@ -493,9 +531,9 @@
type: function
desc: Returns data about a single leaderboard entry
parameters:
- name: leaderboard
- name: hSteamLeaderboardEntries
type: string
desc: Leaderboard handle
desc: Leaderboard entries handle
- name: index
type: number
desc: Which entry to get
Expand Down
39 changes: 39 additions & 0 deletions steam/src/steam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ static const luaL_reg Module_methods[] = {

// USERSTATS - leaderboard
{ "user_stats_find_leaderboard", SteamUserStats_FindLeaderboard },
{ "user_stats_find_or_create_leaderboard", SteamUserStats_FindOrCreateLeaderboard },
{ "user_stats_get_leaderboard_name", SteamUserStats_GetLeaderboardName },
{ "user_stats_download_leaderboard_entries", SteamUserStats_DownloadLeaderboardEntries },
{ "user_stats_get_downloaded_leaderboard_entry", SteamUserStats_GetDownloadedLeaderboardEntry },
Expand Down Expand Up @@ -261,6 +262,23 @@ static void LuaInit(lua_State* L)
SETCONSTANT(ELeaderboardDataRequestUsers, k_ELeaderboardDataRequestUsers);


//
// ELeaderboardSortMethod
//
/**
* @field ELeaderboardSortMethodNone
*/
SETCONSTANT(ELeaderboardSortMethodNone, k_ELeaderboardSortMethodNone);
/** top-score is lowest number
* @field ELeaderboardSortMethodAscending
*/
SETCONSTANT(ELeaderboardSortMethodAscending, k_ELeaderboardSortMethodAscending);
/** top-score is highest number
* @field ELeaderboardSortMethodNone
*/
SETCONSTANT(ELeaderboardSortMethodDescending, k_ELeaderboardSortMethodDescending);


//
// ELeaderboardUploadScoreMethod
//
Expand All @@ -278,6 +296,27 @@ static void LuaInit(lua_State* L)
SETCONSTANT(ELeaderboardUploadScoreMethodForceUpdate, k_ELeaderboardUploadScoreMethodForceUpdate);


//
// ELeaderboardDisplayType
//
/**
* @field ELeaderboardDisplayTypeNone
*/
SETCONSTANT(ELeaderboardDisplayTypeNone, k_ELeaderboardDisplayTypeNone);
/** Simple numerical score
* @field ELeaderboardDisplayTypeNumeric
*/
SETCONSTANT(ELeaderboardDisplayTypeNumeric, k_ELeaderboardDisplayTypeNumeric);
/** The score represents a time, in seconds
* @field ELeaderboardDisplayTypeTimeSeconds
*/
SETCONSTANT(ELeaderboardDisplayTypeTimeSeconds, k_ELeaderboardDisplayTypeTimeSeconds);
/** The score represents a time, in milliseconds
* @field ELeaderboardDisplayTypeTimeMilliSeconds
*/
SETCONSTANT(ELeaderboardDisplayTypeTimeMilliSeconds, k_ELeaderboardDisplayTypeTimeMilliSeconds);


//
// EOverlayToStoreFlag
//
Expand Down
Loading

0 comments on commit 8eebf80

Please sign in to comment.