Please login or register.

Login with username, password and session length
Advanced search  

News:

Forum rules - please read before posting, it can save you a lot of time.

Pages: [1] 2  All

Author Topic: Steam plugin  (Read 9934 times)

0 Members and 1 Guest are viewing this topic.

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 39
  • Offline Offline
  • Gender: Male
  • Posts: 5666
    • View Profile
    • Dead:Code Site
Steam plugin
« on: October 19, 2013, 12:28:02 PM »

Steam plugin for WME

If you are lucky enough to have your game published on Steam, this plugin will allow you to leverage some of the Steam features, namely achievements and game stats.

Getting started

Download the plugin here: http://dead-code.org/download/wme_steam_125.zip
Source code is also available: https://bitbucket.org/MnemonicWME/wme_steam_plugin/
  • Copy wme_steam.dll (the plugin itself) and steam_api.dll (Steamworks API library) to your WME installation directory.
  • The Steam library needs to know the unique ID of your game (you will get the ID once your game is accepted to Steam). If the game is executed from the Steam client, it already knows the ID. However for testing purposes, you will need to create a text file in your WME installation directory, called steam_appid.txt. This file will contain the ID of your game.
  • Define your game's achievements and stats using the Steam partner site (notice that each achievement and stat is identified by a unique string ID).
Note: If your game is not on Steam yet and you want to test the Steam integration anyway, you can use a test game called Spacewar. Its ID is 480 and the defined achievements are listed on this site


Accessing Steam functions from WME scripts

First you need to create a SteamAPI object and store it in a global variable. Typically you will do this when the game starts, i.e. somewhere in the beginning of game.script:
Code: WME Script
  1. global g_Steam = new SteamAPI();
  2.  

To check whether the initialization was successful, check the SteamAvailable property.
Code: WME Script
  1. if (g_Steam.SteamAvailable) ...
  2.  
If the SteamAvailable property is false, something is wrong. The typical reasons are that either the Steam client is not running or you've provided an invalid game ID (see above).


Working with achievements

To unlock an achievement, call the SetAchievement method. It accepts a string ID of the achievement (the ID you assigned to your achievement when defining it) and it returns true/false, depending on the success. It is safe to call this method multiple times, if the achievement is already unlocked, subsequent unlock attempts will be ignored.
Code: WME Script
  1. g_Steam.SetAchievement("ACH_WIN_ONE_GAME");
  2.  

This is pretty much everything you will typically need. The plugin provides more functions, though:

To check whether an achievement has already been unlocked by the player, use the IsAchieved method:
Code: WME Script
  1. Game.Msg(g_Steam.IsAchieved("ACH_WIN_ONE_GAME"));
  2.  

To reset an achievement back to unlocked state, use the ClearAchievement method. You will probably only need this for testing purposes, not in the actual game:
Code: WME Script
  1. g_Steam.ClearAchievement("ACH_WIN_ONE_GAME");
  2.  

To query all achievements defined for the game, use the NumAchievements property and GetAchievementId method. The following example will print out all achievement IDs:
Code: WME Script
  1. for (var i = 0; i < g_Steam.NumAchievements; i = i + 1)
  2. {
  3.   Game.Msg(g_Steam.GetAchievementId(i));
  4. }
  5.  


Working with stats

Stats are some persistent values related to your game, stored by Steam across multiple gaming sessions. You can use them for tracking information such as the number of times the player started your game, the number of miles the player traveled in total etc. Steam can store either integer numbers or float (decimal) numbers. Just like with achievements, you define stats using the Steam partner site.

To store a stat value, use the SetStat method. It accepts either integer or float numbers. If unsure about the value of your variable, convert it explicitly using the ToFloat() or ToInt() WME functions.
Code: WME Script
  1. g_Steam.SetStat("NumGames", ToInt(10));
  2. g_Steam.SetStat("FeetTraveled", ToFloat(100.5));
  3.  

To retrieve stored stats, use either the GetStatInt or GetStatFloat method:
Code: WME Script
  1. Game.Msg(g_Steam.GetStatInt("NumGames"));
  2. Game.Msg(g_Steam.GetStatFloat("FeetTraveled"));
  3.  


Other functions

For testing purposes you may need to clear all stats and achievements. To do that, use the ResetAllStats method. It accepts a logical argument, specifying whether you want to reset just stats or also all achievements:
Code: WME Script
  1. // reset just stats
  2. g_Steam.ResetAllStats(false);
  3.  
  4. // reset both stats and achievements
  5. g_Steam.ResetAllStats(true);
  6.  


To reload the stats/achievements states from the server, use the RequestStats. Normally you shouldn't need to call this method. The plugin will call it automatically upon initialization.
Code: WME Script
  1. g_Steam.RequestStats();
  2.  

To check whether the stat/achievement info is available, use the StatsAvailable property. Stat info is downloaded from Steam asynchronously, meaning that there may be a slight delay between plugin initialization and stats becoming available. Until this property is true, all other calls to methods dealing with stats and achievements are ignored.
Code: WME Script
  1. if (g_Steam.StatsAvailable) ...
  2.  

You can query the game ID using the AppId property:
Code: WME Script
  1. Game.Msg("Current game ID is: " + g_Steam.AppId);
  2.  
« Last Edit: October 19, 2013, 12:31:01 PM by Mnemonic »
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 39
  • Offline Offline
  • Gender: Male
  • Posts: 5666
    • View Profile
    • Dead:Code Site
Re: Steam plugin
« Reply #1 on: October 19, 2013, 12:43:15 PM »

What if my game is already on Steam and I want to add achievements?

Ok, it's a little tricky, because even if you add the plugin initialization to game.script, when the player loads an old saved game with old game.script, the plugin won't get initialized.

You will need to find a way to "inject" the plugin initialization to an existing game. To do that, I recommend finding some script that isn't running all the time, but it's likely to get executed eventually. For example, is there a scene in your game where the player keeps returning to? Patch the script of this scene and add some code to initialize the plugin:

Code: WME Script
  1. global g_Steam;
  2.  
  3. // if the variable is empty, it means the player is running an old game.script
  4. // so we'll just initialize the plugin now
  5. if (g_Steam == null)
  6. {
  7.   g_Steam = new SteamAPI();
  8.  
  9.   // you may also want to unlock some achievements the player may have missed so far
  10.   if (someGameVariable) g_Steam.SetAchievement("SomeAchievement");
  11. }
  12.  
  13.  
  14.  

However, since the g_Steam variable may or may not be initialized (depending on whether the player visited the "injection" scene yet), you need to be careful when calling any method:

Code: WME Script
  1. // always make sure the plugin is initalized before calling SetAchievement
  2. if (g_Steam != null)
  3. {
  4.   g_Steam.SetAchievement("SomeAchievement");
  5. }
  6.  
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Azrael

  • Regular poster
  • ***
  • Karma: 9
  • Offline Offline
  • Gender: Male
  • Posts: 155
    • View Profile
    • Mad Orange
Re: Steam plugin
« Reply #2 on: October 19, 2013, 02:17:35 PM »

Thanks a lot  :)
Logged

hubertMichael

  • Regular poster
  • ***
  • Karma: 3
  • Offline Offline
  • Posts: 155
    • View Profile
    • Shadow Of Nebula - our point'n click adventure game
Re: Steam plugin
« Reply #3 on: October 20, 2013, 10:27:45 PM »

WOW :D You are great :D Thank you :D
Logged
Shadow Of Nebula fan page:

https://www.facebook.com/shadowofnebula

metamorphium

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 12
  • Offline Offline
  • Gender: Male
  • Posts: 1511
  • Vampires!
    • View Profile
    • CBE  software s.r.o.
Re: Steam plugin
« Reply #4 on: October 21, 2013, 08:26:34 AM »

Thank you! This couldn't have come in a better time. :)
Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet

Azrael

  • Regular poster
  • ***
  • Karma: 9
  • Offline Offline
  • Gender: Male
  • Posts: 155
    • View Profile
    • Mad Orange
Re: Steam plugin
« Reply #5 on: October 31, 2013, 10:00:51 AM »

I'm having some problems with the plugin, it seem to work perfectly for a while (completely random) and then simply stop working.

I've checked the scripts and seem to be ok. I've done many test and everything seem to be working but achievements will not me setted on steam. I inserted also F5 as reset button for achievements and stats and at the beginning it works, but when achievement stop to be set also this don't work anymore.

For example:
Code: WME Script
  1. #include "scripts\base.inc"
  2. global g_Steam;
  3.  
  4. ////////////////////////////////////////////////////////////////////////////////
  5. on "observe"
  6.         {
  7.         Game.Interactive = false;
  8.        
  9.         actor.TurnTo(this);
  10.         actor.TalkUp("/sysengXXXX/Text");
  11.        
  12.         //Steam Achievement
  13.         if (g_Steam != null)
  14.                 {
  15.                 g_Steam.SetAchievement("ACH_MALTESE_FALCON");
  16.                 Game.LOG("Achievement Set.");
  17.                 }
  18.         else Game.LOG("Steam not working!");
  19.        
  20.         Game.Msg("New version loaded"); //To be sure that the news script was loaded
  21.        
  22.         if (g_Steam.SteamAvailable) Game.LOG("Steamworks available!");
  23.         else Game.LOG("Steamworks not available");
  24.        
  25.         Game.Interactive = true;
  26.         }
  27.  
  28. on "take"
  29.         {
  30.         Game.Interactive = false;
  31.        
  32.         actor.TurnTo(this);
  33.         actor.TalkUp("/sysengXXXX/Text");
  34.        
  35.         Game.Interactive = true;
  36.         }
  37.  

This sometimes works, sometimes not. I've a save now right before and it doesn't work. But with the log enable it says:
Code: WME Script
  1. 09:44: Achievement Set.
  2. 09:44: Steamworks available!
None of the errors above are show.

Ah the Achievement is obviously not already set.

The Game.Msg("New version loaded"); is displayed so i know that the script is correctly loaded (i change it each time i upload something new).

global g_Steam = new SteamAPI(); is enabled at game.script, i tried also to put it on this script but with the same result.

As i said is completely random, the first time i was able to play more than 1 hour before it stop to work, the second time half an hour.

« Last Edit: October 31, 2013, 10:02:48 AM by Azrael »
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 39
  • Offline Offline
  • Gender: Male
  • Posts: 5666
    • View Profile
    • Dead:Code Site
Re: Steam plugin
« Reply #6 on: October 31, 2013, 10:40:27 AM »

Try adding the return value of SetAchievement() to the message. It should return true or false, based on success of the call.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Azrael

  • Regular poster
  • ***
  • Karma: 9
  • Offline Offline
  • Gender: Male
  • Posts: 155
    • View Profile
    • Mad Orange
Re: Steam plugin
« Reply #7 on: October 31, 2013, 11:20:19 AM »

Uhm, it say "no", so i think "false". There is some way to know why?
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 39
  • Offline Offline
  • Gender: Male
  • Posts: 5666
    • View Profile
    • Dead:Code Site
Re: Steam plugin
« Reply #8 on: October 31, 2013, 12:09:15 PM »

Try checking the Steam.StatsAvailable property. It specifies whether steam downloaded the stats and achievements info from server. The download is requested when the Steam object is created and it may take a moment until the info is ready. Until then all the other functions will fail.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Azrael

  • Regular poster
  • ***
  • Karma: 9
  • Offline Offline
  • Gender: Male
  • Posts: 155
    • View Profile
    • Mad Orange
Re: Steam plugin
« Reply #9 on: October 31, 2013, 01:41:21 PM »

Ok, StatsAvailable return "false".
But the problems that the first time it happen i was playing for a while, without closing the game i mean.
And now i've tried to wait some minutes but nothing, there is a way to force download or something else?
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 39
  • Offline Offline
  • Gender: Male
  • Posts: 5666
    • View Profile
    • Dead:Code Site
Re: Steam plugin
« Reply #10 on: October 31, 2013, 01:45:41 PM »

That's what the RequestStats() method does (see above). But it shouldn't be necessary, it's called automatically when the Steam object is created.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Azrael

  • Regular poster
  • ***
  • Karma: 9
  • Offline Offline
  • Gender: Male
  • Posts: 155
    • View Profile
    • Mad Orange
Re: Steam plugin
« Reply #11 on: October 31, 2013, 02:41:21 PM »

Ok i tried with RequestStats but with the same result, any other advice? Otherwise he sadly had to leave the game without achievements  :'(
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 39
  • Offline Offline
  • Gender: Male
  • Posts: 5666
    • View Profile
    • Dead:Code Site
Re: Steam plugin
« Reply #12 on: October 31, 2013, 03:42:23 PM »

No idea then. Beyond that point it's under steam's control, as far as I can tell.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Azrael

  • Regular poster
  • ***
  • Karma: 9
  • Offline Offline
  • Gender: Male
  • Posts: 155
    • View Profile
    • Mad Orange
Re: Steam plugin
« Reply #13 on: October 31, 2013, 07:05:34 PM »

Ok, thanks a lot anyway for the help :)
Logged

Gurkan

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 6
    • View Profile
Re: Steam plugin
« Reply #14 on: March 24, 2014, 04:27:30 PM »

Hi everyone!

We've recently been greenlit and I'm trying to figure out how to create our achievements. I've managed to connect Steam with the game as g_Steam.SteamAvailable is returning true. What doesn't seem to work is setting the actual achievement, g_Steam.SetAchievement(). I've been logging it's status with Game.LOG(g_Steam.IsAchieved()) but it always returns false no matter what. I've followed these steps and created steam_appid.txt, the .dll files etc and I'm kinda out of options. I'm using 1.9.001, if that has any significance. Here is my setup:

In game.script:

global g_Steam = new SteamAPI();

In object:

global g_Steam;

on "LookAt"
{
   GoToObject();
   if(g_Steam != null)
   {
      g_Steam.SetAchievement("achievement_2");
   }
}

on "Talk"
{
     if(g_Steam != null)
   {
      Game.LOG(g_Steam.IsAchieved("achievement_2"));
   }
}
« Last Edit: March 24, 2014, 04:30:15 PM by Gurkan »
Logged
Pages: [1] 2  All
 

Page created in 0.328 seconds with 17 queries.