cyanic's Steam Achievements Integration

Discussion in 'RGSS3 Scripts (RMVX Ace)' started by cyanic, Nov 16, 2015.

  1. cyanic

    cyanic Veteran Veteran

    Messages:
    105
    Likes Received:
    62
    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
    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
    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. 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: Oct 9, 2017
    #1
    hyde9318, FoppyOmega, Chaos17 and 7 others like this.
  2. Millerberto2

    Millerberto2 Good Sire Veteran

    Messages:
    35
    Likes Received:
    12
    Location:
    Brazil, São Paulo
    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: Nov 16, 2015
    #2
  3. Cloud_FFVII

    Cloud_FFVII Veteran Veteran

    Messages:
    31
    Likes Received:
    1
    First Language:
    Spanish
    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
     
    #3
  4. cyanic

    cyanic Veteran Veteran

    Messages:
    105
    Likes Received:
    62
    Could you post how you're calling the script and what Steamworks SDK version you're using?
     
    #4
  5. Cloud_FFVII

    Cloud_FFVII Veteran Veteran

    Messages:
    31
    Likes Received:
    1
    First Language:
    Spanish

    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,
     
    #5
  6. Millerberto2

    Millerberto2 Good Sire Veteran

    Messages:
    35
    Likes Received:
    12
    Location:
    Brazil, São Paulo
    First Language:
    Portuguese
    Primarily Uses:
    RMVXA


    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:


    [​IMG]
     
    Last edited: Oct 9, 2017
    #6
  7. Cloud_FFVII

    Cloud_FFVII Veteran Veteran

    Messages:
    31
    Likes Received:
    1
    First Language:
    Spanish


    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 :(
     
    #7
  8. cyanic

    cyanic Veteran Veteran

    Messages:
    105
    Likes Received:
    62
    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.
     
    #8
    EternalShadow likes this.
  9. Val

    Val Veteran Veteran

    Messages:
    275
    Likes Received:
    162
    First Language:
    Français
    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 :)
     
    #9
  10. Cloud_FFVII

    Cloud_FFVII Veteran Veteran

    Messages:
    31
    Likes Received:
    1
    First Language:
    Spanish


    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: Mar 13, 2016
    #10
  11. CloudTheWolf

    CloudTheWolf Warper Member

    Messages:
    3
    Likes Received:
    0
    First Language:
    English


    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?
     
    #11
  12. cyanic

    cyanic Veteran Veteran

    Messages:
    105
    Likes Received:
    62
    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.

    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.

    Could you try the r3.2 script linked a few posts up?
     
    #12
    Val likes this.
  13. Val

    Val Veteran Veteran

    Messages:
    275
    Likes Received:
    162
    First Language:
    Français
    Thx Cyanic I will look into it if I'm able to understand how it work ;)
     
    #13
  14. IsFutureBright

    IsFutureBright Lightning Bolt Action Veteran

    Messages:
    120
    Likes Received:
    11
    Location:
    Brazil
    First Language:
    Portuguese
    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
     
    #14
  15. Millerberto2

    Millerberto2 Good Sire Veteran

    Messages:
    35
    Likes Received:
    12
    Location:
    Brazil, São Paulo
    First Language:
    Portuguese
    Primarily Uses:
    RMVXA
    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.


    :)
     
    #15
  16. IsFutureBright

    IsFutureBright Lightning Bolt Action Veteran

    Messages:
    120
    Likes Received:
    11
    Location:
    Brazil
    First Language:
    Portuguese
    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]
     
    #16
  17. cyanic

    cyanic Veteran Veteran

    Messages:
    105
    Likes Received:
    62


    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)
     
    #17
  18. CloudTheWolf

    CloudTheWolf Warper Member

    Messages:
    3
    Likes Received:
    0
    First Language:
    English


    That seems to have fixed it =D 
     
    #18
  19. IsFutureBright

    IsFutureBright Lightning Bolt Action Veteran

    Messages:
    120
    Likes Received:
    11
    Location:
    Brazil
    First Language:
    Portuguese
    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
     
    #19
  20. cyanic

    cyanic Veteran Veteran

    Messages:
    105
    Likes Received:
    62
    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).
     
    #20

Share This Page