Steam plugin for WMEIf 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 startedDownload the plugin here:
http://dead-code.org/download/wme_steam_125.zipSource 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 siteAccessing Steam functions from WME scriptsFirst 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:
global g_Steam = new SteamAPI();
To check whether the initialization was successful, check the
SteamAvailable property.
if (g_Steam.SteamAvailable) ...
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 achievementsTo 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.
g_Steam.SetAchievement("ACH_WIN_ONE_GAME");
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:
Game.
Msg(g_Steam.
IsAchieved("ACH_WIN_ONE_GAME"));
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:
g_Steam.ClearAchievement("ACH_WIN_ONE_GAME");
To query all achievements defined for the game, use the
NumAchievements property and
GetAchievementId method. The following example will print out all achievement IDs:
for (var i = 0; i < g_Steam.NumAchievements; i = i + 1)
{
Game.
Msg(g_Steam.
GetAchievementId(i
));
}
Working with statsStats 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.
g_Steam.
SetStat("NumGames",
ToInt(10));
g_Steam.
SetStat("FeetTraveled",
ToFloat(100.5));
To retrieve stored stats, use either the
GetStatInt or
GetStatFloat method:
Game.
Msg(g_Steam.
GetStatInt("NumGames"));
Game.
Msg(g_Steam.
GetStatFloat("FeetTraveled"));
Other functionsFor 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:
// reset just stats
g_Steam.ResetAllStats(false);
// reset both stats and achievements
g_Steam.ResetAllStats(true);
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.
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.
if (g_Steam.StatsAvailable) ...
You can query the game ID using the
AppId property:
Game.
Msg("Current game ID is: " + g_Steam.
AppId);