cyanic's Steam Achievements Integration

cyanic

Veteran
Veteran
Joined
Nov 16, 2015
Messages
106
Reaction score
64
Primarily Uses
Quick and Easy Steamworks Achievements Integration for RPG Maker VX Ace r7
by cyanic

Introduction
This script allows you to use Steam achievements from your game. It needs no intermediary DLLs, only a recent version of the Steamworks DLL.

Features
  • Set/clear achievements
  • Get/set player stats
  • Supports average rate stats
  • Get achievement state and unlocked time
  • Enumerate achievements programmatically, get their display name and hidden status
  • Reset all stats and achievements
  • Check game ownership
  • Check if a DLC is installed

Changelog
r7 (02/25/20)
  • Updated script for Steamworks SDK 1.48.
  • Relicense under MIT License

r6 (02/25/20)
  • Updated script for Steamworks SDK 1.43.
  • Automatically retrieve stats on init.

r5 (08/08/16)
  • Added indicate_achievement_progress method.

r4 (06/16/16)
  • Updated script for Steamworks SDK 1.37.

r3.2 (03/12/16)
  • Fixed pointer return type on DLL imports.

r3.1 (11/15/15)
  • Added app is subscribed and DLC is installed methods.

r3 (11/15/15)
  • Added get methods, stats set methods.

r2 (11/15/15)
  • Tested in RPG Maker, fixed to make the script actually run.

r1 (11/14/15)
  • Initial version, written for Ruby 2.2.3.

How to Use
  • Download a recent version of the Steamworks SDK (>= 1.37), and put its steam_api.dll into the root of your project folder.
  • Add the script into the script editor.
  • In the event or wherever else you want to set an achievement, add the following code:
    Code:
    steam = SteamUserStatsLite.instance
    steam.set_achievement 'YOUR_ACH_ID_HERE'
    steam.update
    Replace 'YOUR_ACH_ID_HERE' with the achievement's API name from the Steamworks partner site.
  • If you want to set a stat, use this code:
    Code:
    steam = SteamUserStatsLite.instance
    steam.set_stat 'YOUR_STAT_ID_HERE', 100
    steam.update
    Replace 'YOUR_STAT_ID_HERE' with the stat's API name from the Steamworks partner site.
  • The #set_achievement and #set_stat methods return true when the achievement/stat has been set succesfully. If it returns false, see the FAQ for more information.

Please see documentation on GitHub.

Demo
This demo was created by Miller Berto. Create a default RPG Maker project, and extract the contents of the ZIP file into the project folder. Please replace the SteamUserStatsLite script with the latest version.

Script
The version to download depends on which version of the Steamworks SDK you want to use. Different versions of Steamworks SDK have different and sometimes incompatible ways of calling its functions, so you need the correct script to have it use the SDK correctly.
  • Steamworks SDK v1.48 and above: r7
  • Steamworks SDK v1.43 to v1.47: r6
  • Steamworks SDK v1.37 to v1.42: r5
  • Steamworks SDK v1.32 to v1.36: r3.2

License
Licensed under the MIT License, which means you can do anything with the script as long as you include the copyright notice.

FAQ
Q: #set_achievement/#set_stat returns false. What's wrong?
A: It means either you haven't set up the achievement in the Steamworks partner site or you were playtesting through RPG Maker.
Because the playtesting game inherits the Steam context from RPG Maker, your achievements won't be found. If you launch your game directly, it should work. I recommend you add a steam_appid.txt file with your app ID during development so you can just launch the EXE and Steamworks will set the right context. If you have a steam_appid.txt file present, you can also launch RPG Maker by double clicking your project file, and the app ID would be set to yours so you can test achievements through playtesting from RPG Maker.
It could also be possible that Steamworks wasn't able to initialize. Check SteamUserStatsLite#initted? to see if Steamworks was initialized successfully.

Q: #set_stat is returning false, but I've already checked that Steamworks was initialized and the stat added and published on the Steamworks partner site. What do I do now?
A: #set_stat can take both Integers and Floats. Make sure when you're passing in the value, you have it converted to the type corresponding to what you set on the Steamworks partner site.

Q: I'm getting a RuntimeError telling me something about GetProcAddress.
A: You need to use at least Steamworks SDK 1.37 for this script to work. Download a newer version of the SDK.

Q: My game crashes when I try to call a Steamworks function. I'm using Steam DRM.
A: There is a compatibility problem with Steam DRM. So don't use it. Not as if it'll actually protect your game. It only gives you an illusion of safety, while in practice is practically useless for protection.

Q: I'm using r3.x, should I upgrade?
A: r4 is functionally the same as r3.2. If you do not need to use the latest Steamworks SDK, you do not need to (and probably should not) upgrade.

Credit and Thanks

Author's Notes
I'm actually a complete RPG Maker noob. I wrote this yesterday on pure Ruby 2.2.3, and only got a copy of RPG Maker VX Ace this morning to test and fix problems.
 
Last edited:

Millerberto2

Good Sire
Veteran
Joined
Nov 10, 2014
Messages
35
Reaction score
12
First Language
Portuguese
Primarily Uses
RMVXA
Great, seems like the post is finally live.. What you are doing is great, cyanic! Now everyone can easily get steam achievements in their games..

Ohh.. and this script works. Tried it with my game.
 
Last edited by a moderator:

Cloud_FFVII

Veteran
Veteran
Joined
Dec 31, 2015
Messages
31
Reaction score
1
First Language
Spanish
Primarily Uses
Hello!, Sorry for necro this...but, not when I obtain an achievement the game just crash...I think they changed the steam API...could it be that? I tried to update the new steamapi.dll but it's not working :c


Problem signature:Problem Event Name: APPCRASHApplication Name: Game.exeApplication Name: 3.0.0.1Application Timestamo: 4e8d3142Fault Module Name: steam_api.DLLFault Module Version: 3.4.27.90Fault Module Timestamp: 5627de96Exception Code: c0000005Exception Offset: 000014dbOS Version: 6.1.7601.2.1.0.256.1Locale ID: 3082Additional Information 1: 0a9eAdditional Information 2: 0a9e372d3b4ad19135b953a78882e789Additional Information 3: 0a9eAdditional Information 4: 0a9e372d3b4ad19135b953a78882e789
 

cyanic

Veteran
Veteran
Joined
Nov 16, 2015
Messages
106
Reaction score
64
Primarily Uses
Hello!, Sorry for necro this...but, not when I obtain an achievement the game just crash...I think they changed the steam API...could it be that? I tried to update the new steamapi.dll but it's not working :c
Could you post how you're calling the script and what Steamworks SDK version you're using?
 

Cloud_FFVII

Veteran
Veteran
Joined
Dec 31, 2015
Messages
31
Reaction score
1
First Language
Spanish
Primarily Uses
Could you post how you're calling the script and what Steamworks SDK version you're using?

Hello, thanks for answering, let me copy the exact script I was using until some days ago.
 


steam = SteamUserStatsLite.instance
steam.set_achievement 'NEW_ACHIEVEMENT_2_0'
steam.update




Where: 'NEW_ACHIEVEMENT_2_0' is the name of my 2nd achievement on Steamworks...


This worked fine, but now it's not working, I was using SDK 1.35, but they updated it some weeks ago, now is 1.36. I tried to download the new SDK and update the steam_api.dll but it's still crashing...If I play the game without steam open (the source files on my PC), it won't crash, so it only happens when Steam is open,and when obtaining any new achievement. :(


Thanks in advance for any help,
 

Millerberto2

Good Sire
Veteran
Joined
Nov 10, 2014
Messages
35
Reaction score
12
First Language
Portuguese
Primarily Uses
RMVXA
Hello, thanks for answering, let me copy the exact script I was using until some days ago.




steam = SteamUserStatsLite.instance
steam.set_achievement 'NEW_ACHIEVEMENT_2_0'
steam.update




Where: 'NEW_ACHIEVEMENT_2_0' is the name of my 2nd achievement on Steamworks...


This worked fine, but now it's not working, I was using SDK 1.35, but they updated it some weeks ago, now is 1.36. I tried to download the new SDK and update the steam_api.dll but it's still crashing...If I play the game without steam open (the source files on my PC), it won't crash, so it only happens when Steam is open,and when obtaining any new achievement. :(


Thanks in advance for any help,


I did some testing with "A Camp in the Woods" on Steam, and I found out that running it on 1.35 SDK works fine, but, when I tried 1.36, the RGSS Player crashed.


I use the same configuration as you do:


 
Last edited:

Cloud_FFVII

Veteran
Veteran
Joined
Dec 31, 2015
Messages
31
Reaction score
1
First Language
Spanish
Primarily Uses
I did some testing with "A Camp in the Woods" on Steam, and I found out that running it on 1.35 SDK works fine, but, when I tried 1.36, the RGSS Player crashed.


I use the same configuration as you do:





I guess it has something to do with the new 'memory improvements'.


Really? that's weird, we didn't updated the game on Steam, but still people started to report this error, that's how we discover this. Then we checked and updated the steam_api.dll to 1.36 and still crashes :(
 

cyanic

Veteran
Veteran
Joined
Nov 16, 2015
Messages
106
Reaction score
64
Primarily Uses
Try the version on the pointers-fix branch: link. I tested it on Windows 10, but nowhere else, so there may still be some problems.


Bug explanation: In the version of Ruby used in VX Ace, pointers are treated as strings. It appears that Ruby copied the return value literally as a string, so the end result is a truncated vtable at the first NULL character. Changing some return values to number should have Ruby retain the original pointer value.
 

Val

Veteran
Veteran
Joined
Oct 12, 2015
Messages
281
Reaction score
167
First Language
Français
Primarily Uses
Hello Cyanic,


I want to know is this going to work with a game made with RPG Maker MV?


thank in advance for your support :)
 

Cloud_FFVII

Veteran
Veteran
Joined
Dec 31, 2015
Messages
31
Reaction score
1
First Language
Spanish
Primarily Uses
Try the version on the pointers-fix branch: link. I tested it on Windows 10, but nowhere else, so there may still be some problems.


Bug explanation: In the version of Ruby used in VX Ace, pointers are treated as strings. It appears that Ruby copied the return value literally as a string, so the end result is a truncated vtable at the first NULL character. Changing some return values to number should have Ruby retain the original pointer value.


You are awesome sir, it's working fine now! Was because of Steam update? It's weird because it was working fine until a few weeks ago.


But now it's working excellent! Tested on Windows 8.1 / 7.



Thanks Cyanic! :)
 
Last edited by a moderator:

CloudTheWolf

Warper
Member
Joined
Sep 8, 2013
Messages
3
Reaction score
0
First Language
English
Primarily Uses

Q: My game crashes when I try to call a Steamworks function. I'm using Steam DRM.
A: There is a compatibility problem with Steam DRM. So don't use it. Not as if it'll actually protect your game. It only gives you an illusion of safety, while in practice is practically useless for protection.


When calling the steamworks function by game just crashed to desktop.


I replaced the exe with a fresh one thinking I added DRM but still get the issue. I can see that game.exe is listed in DRM on Steamworks.


Any idea on how to fix?
 

cyanic

Veteran
Veteran
Joined
Nov 16, 2015
Messages
106
Reaction score
64
Primarily Uses
Hello Cyanic,


I want to know is this going to work with a game made with RPG Maker MV?


thank in advance for your support :)
Unfortunately, it will not, because VX Ace and MV use completely different languages and engines for scripting. For MV, you're looking for a JavaScript solution. I can't seem to find the thread about it right now, but what you're looking for is probably Greenworks.

You are awesome sir, it's working fine now! Was because of Steam update? It's weird because it was working fine until a few weeks ago.


But now it's working excellent! Tested on Windows 8.1 / 7.



Thanks Cyanic! :)
It was probably broken the entire time, and just got lucky it wasn't so broken that it didn't work until the most recent Steam update.

When calling the steamworks function by game just crashed to desktop.


I replaced the exe with a fresh one thinking I added DRM but still get the issue. I can see that game.exe is listed in DRM on Steamworks.


Any idea on how to fix?
Could you try the r3.2 script linked a few posts up?
 
  • Like
Reactions: Val

Val

Veteran
Veteran
Joined
Oct 12, 2015
Messages
281
Reaction score
167
First Language
Français
Primarily Uses
Thx Cyanic I will look into it if I'm able to understand how it work ;)
 

IsFutureBright

Lightning Bolt Action
Veteran
Joined
Dec 26, 2012
Messages
120
Reaction score
11
First Language
Portuguese
Primarily Uses
On the demo I saw that the app id was set on a text file, is that correct? I tried setting mine up but I keep getting the following print:Capturar.PNG


What am I doing wrong?


Thanks for the nifty script by the way :o
 

Millerberto2

Good Sire
Veteran
Joined
Nov 10, 2014
Messages
35
Reaction score
12
First Language
Portuguese
Primarily Uses
RMVXA
On the demo I saw that the app id was set on a text file, is that correct? I tried setting mine up but I keep getting the following print:View attachment 33558


What am I doing wrong?


Thanks for the nifty script by the way :o
This means you are trying to run your game through RPG Maker VX Ace. Try running it outside of RPG Maker, and it'll work fine.


:)
 

IsFutureBright

Lightning Bolt Action
Veteran
Joined
Dec 26, 2012
Messages
120
Reaction score
11
First Language
Portuguese
Primarily Uses
Hmm I'm trying to get all of the achievements available for oceanhorn (339200) to see if the code working but all I get is 0. 


steam = SteamUserStatsLite.instance

$game_variables[77] = 'num of achieves are' + steam.get_num_achievements.to_s


Then I do a message with \v[77]
 

cyanic

Veteran
Veteran
Joined
Nov 16, 2015
Messages
106
Reaction score
64
Primarily Uses
Hmm I'm trying to get all of the achievements available for oceanhorn (339200) to see if the code working but all I get is 0. 



steam = SteamUserStatsLite.instance

$game_variables[77] = 'num of achieves are' + steam.get_num_achievements.to_s


Then I do a message with \v[77]


First, make sure that you're not starting the game from within RPG Maker, because it will inherit RPG Maker's app ID (see first FAQ item). Next, make sure you own the app you're testing on, and put its app ID in steam_appid.txt. After that, try again and see what happens. If you want to see the return value of the function when it's called, you can inspect it and open a msgbox, like this:

Code:
msgbox(steam.get_num_achievements.inspect)
 

IsFutureBright

Lightning Bolt Action
Veteran
Joined
Dec 26, 2012
Messages
120
Reaction score
11
First Language
Portuguese
Primarily Uses
Okay I have two maybe dumb questions. Do I need to upload a build to a beta branch in order to the values to come? Also does the achievements need to be published?


I tried fetching a stat but it's returning as nil. I tried adding an achievement but the total I'm getting is still 0. :o
 

cyanic

Veteran
Veteran
Joined
Nov 16, 2015
Messages
106
Reaction score
64
Primarily Uses
You don't need to upload a build, but you do need to make sure the stats are configured properly, then published. If you need some live help, try chatting up Miller, since he's got it all integrated and should know how to get everything working on Steam's end (I don't have my own game, so no access to the partner panel to look things up).
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Me: "Finally finished most of my game backlog. Probably time to do some gamedev" | Steam: *offer sales*
If I recorded while I created (what I think is) a small plugin, would you be interested enough in the process to watch it?
I keep trying to explain to clients that the huddle masses behind the old K-Mart are a Fallout Reenactment group. Somehow I don't think they believe me. :LZSskeptic:
Hey people! What do you think about a core plugin? This will save some lines of code that I repeatedly use in all my plugins...
Wondering if I should make my enemies scale in my non-linear rpg. I'm leaning towards yes, but I don't want to use Yanfly's plugin...

Forum statistics

Threads
94,594
Messages
922,167
Members
124,464
Latest member
foghiszdenisz
Top