Josh Posted October 15, 2015 Share Posted October 15, 2015 I am adding Steam leaderboard functionality to help make your games for the Halloween game tournament more fun. It will let you display the top ten scores of your game among all players, with the user's name, score, and avatar displayed onscreen. Here's a quick rundown of the API: Get the leaderboard object. Use the name parameter to create multiple leaderboards for different parameters. Type can be 1 for numeric, 2 for seconds: Leaderboard* Steamworks::GetLeaderboard(std::string name="Hiscore", const int type = 1) This gives you everything you need to display the leaderboard entries. Entries are numbered 0 to CountEntries()-1: int Leaderboard::CountEntries() uint64_t Leaderboard::GetEntryUserID(const int index) int Leaderboard::GetEntryScore(const int index) Use this to set the player's hiscore. (It will automatically keep the highest score they achieve.) bool Leaderboard::SetScore(const int score) You can get the user name and avatar from the Steam ID: std::string Steamworks::GetUserName(const uint64_t userid) Texture* Steamworks::GetUserAvatar(const uint64_t userid) This will be available later today on the beta branch and in game launcher. 9 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
YouGroove Posted October 15, 2015 Share Posted October 15, 2015 c++ Quote Stop toying and make games Link to comment Share on other sites More sharing options...
Josh Posted October 15, 2015 Author Share Posted October 15, 2015 Lua also. 2 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
reepblue Posted October 15, 2015 Share Posted October 15, 2015 Very cool, I'm curious to see how this will work when it's implemented. Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
Thirsty Panther Posted October 15, 2015 Share Posted October 15, 2015 Great idea. Will give players another reason to keep player your game. Quote Link to comment Share on other sites More sharing options...
Rick Posted October 15, 2015 Share Posted October 15, 2015 How does SetScore() know what player to set that score for? Quote Link to comment Share on other sites More sharing options...
Josh Posted October 15, 2015 Author Share Posted October 15, 2015 It can only set the score for the player signed into the account. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Josh Posted October 15, 2015 Author Share Posted October 15, 2015 Here it is in action: Add this at the top of main.lua: import("Scripts/HiScores.lua") And save this file as "HiScores.lua": storedavatars={} function SetScore(score) if leaderboard==nil then leaderboard = Steamworks:GetLeaderboard() end if leaderboard==nil then return false end result=leaderboard:SetScore(score) leaderboard:Release() leaderboard = nil return result end function ShowHiScores(context) if leaderboard==nil then leaderboard = Steamworks:GetLeaderboard() end if leaderboard==nil then return false end local n local x=300 local y=300 local w=600 local fh = context:GetFont():GetHeight() local rowheight=68 local rowspacing=2 local h = (rowheight+rowspacing)*leaderboard:CountEntries()+20 x = (context:GetWidth()-w)/2 y = (context:GetHeight()-h)/2 context:SetBlendMode(Blend.Alpha) context:SetColor(0,0,0,0.5) context:DrawRect(x,y-20,w,20) context:SetColor(1,1,1,1) context:DrawText("Name",x+80,y-20+2) context:DrawText("Score",x+300,y-20+2) for n=0,leaderboard:CountEntries()-1 do local score = leaderboard:GetEntryScore(n) local steamid = leaderboard:GetEntryUserID(n) local s = type(steamid) local name = Steamworks:GetUserName(steamid) if storedavatars[steamid]==nil then storedavatars[steamid] = Steamworks:GetUserAvatar(steamid) end context:SetColor(0,0,0,0.5) context:DrawRect(x,y,w,rowheight) context:SetColor(1,1,1,1) if storedavatars[steamid] then context:DrawImage(storedavatars[steamid],x+2,y+2,64,64) else context:DrawRect(x+2,y+2,64,64) end context:DrawText(name,x+80,y+(rowheight-fh)/2) context:DrawText(score,x+300,y+(rowheight-fh)/2) y=y+rowheight+rowspacing end return true end To set the hiscore: SetScore(101) To display the hiscores table: --Show hiscores table ShowHiScores(context) --Refresh the screen context:Sync(true) Upload will be up shortly, Windows only at the moment. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Josh Posted October 15, 2015 Author Share Posted October 15, 2015 It's up now on beta branch, only available for Lua presently. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
shadmar Posted October 15, 2015 Share Posted October 15, 2015 Very cool! Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB Link to comment Share on other sites More sharing options...
shadmar Posted October 15, 2015 Share Posted October 15, 2015 "../Scripts/HiScores.lua" : 15 : attempt to call method 'GetLeaderboard' (a nil value) I have updated the project. Edit: just some shader billboard files was updated. Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB Link to comment Share on other sites More sharing options...
reepblue Posted October 15, 2015 Share Posted October 15, 2015 Yeah, the exe's did not update. They are still dated from the last update. Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
Josh Posted October 15, 2015 Author Share Posted October 15, 2015 Fixed, the build didn't update for some reason. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
shadmar Posted October 15, 2015 Share Posted October 15, 2015 Works, however can we have unique scores for our game? EDIT: Ah pass args to GetLeaderboard helps. Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB Link to comment Share on other sites More sharing options...
Rick Posted October 15, 2015 Share Posted October 15, 2015 How many scoreboards do we get? This looks like it could possibly be a way to save some game data for our game player games too Saying this because we need to be able to save data somewhere for gameplayer games. 1 for numeric, 2 for seconds 2 for seconds? What does that mean? How is a second not numeric? Quote Link to comment Share on other sites More sharing options...
Josh Posted October 15, 2015 Author Share Posted October 15, 2015 Seconds = time. AFAIK this only affects how it is displayed in the community hub. You can set a name for your leaderboard and create as many as you want. I would not use this for settings because it probably doesn't work in offline mode. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
reepblue Posted October 16, 2015 Share Posted October 16, 2015 I hope the Game Launcher gets updated soon. I'm currently uploading a new build of Rolly with this. Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
Admin Posted October 16, 2015 Share Posted October 16, 2015 It should work. Can't wait to try this. Quote Link to comment Share on other sites More sharing options...
reepblue Posted October 16, 2015 Share Posted October 16, 2015 I confirmed that Leader boards (and some reason font packaging) does not seem to be working. More info here. Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
Admin Posted October 16, 2015 Share Posted October 16, 2015 The beta branch is updated on Windows so that all fonts are always included now. 1 Quote Link to comment Share on other sites More sharing options...
drarem Posted October 19, 2015 Share Posted October 19, 2015 Two quick questions: 1) when i first did a 'SetScore' and viewed, it showed 'anonymous and some weird long number instead of 999. I restarted the game and it showed my id and the correct score. 2) Can it also store stats, not just a single score? Thanks. Quote Link to comment Share on other sites More sharing options...
Rick Posted October 19, 2015 Share Posted October 19, 2015 You should be able to store whatever you want, but you'd have to "bastardize" the system to do that. In other words if you wanted to store how many enemies the player killed you have to make a separate leaderboard for that. I was thinking of something like that where my leaderboard names would be game.stat like: "MyGame.Score" "MyGame.EnemyKills" "MyGame.CoinsCollected" Quote Link to comment Share on other sites More sharing options...
shadmar Posted October 19, 2015 Share Posted October 19, 2015 But you can only set an upwards value, So SetCore(100) followed by SetCore(99) will always show 100. Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB Link to comment Share on other sites More sharing options...
drarem Posted October 19, 2015 Share Posted October 19, 2015 Can that be fixed in the future, if a stat drops.. if a custom string could be saved instead of numeric data, that could be one way around it. Quote Link to comment Share on other sites More sharing options...
Rick Posted October 19, 2015 Share Posted October 19, 2015 I believe this is Steam stuff not LE stuff here. Leadwerks is just exposing the Steam API to do this. You'd have to talk to Steam and I doubt they would change this process Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.