Quick and Easy Steamworks Achievements Integration for RPG Maker VX Ace r4
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
Spoilerr4 (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:
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:
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
Visit GitHub for the latest version. If you're using Steamworks SDK 1.32 to 1.36, please use this version.
License
You are free to use this script in any project without charge. A mention in the credits would be appreciated.
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.
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
- Created by cyanic
- Thanks to Miller Berto for letting me use his game as the testing grounds for this script.
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.