<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://te4.org/w/index.php?action=history&amp;feed=atom&amp;title=T4_Modules_Howto_Guide%2FAchievements</id>
		<title>T4 Modules Howto Guide/Achievements - Revision history</title>
		<link rel="self" type="application/atom+xml" href="https://te4.org/w/index.php?action=history&amp;feed=atom&amp;title=T4_Modules_Howto_Guide%2FAchievements"/>
		<link rel="alternate" type="text/html" href="https://te4.org/w/index.php?title=T4_Modules_Howto_Guide/Achievements&amp;action=history"/>
		<updated>2026-07-14T06:47:15Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.26.2</generator>

	<entry>
		<id>https://te4.org/w/index.php?title=T4_Modules_Howto_Guide/Achievements&amp;diff=6517&amp;oldid=prev</id>
		<title>Castler: Created page with &quot;'''Work in progress.  Not yet finished or tested.'''  = Adding the World =  T-Engine uses the [http://te4.org/docs/t-engine4/1.0.0/modules/engine.interface.WorldAchievements.h...&quot;</title>
		<link rel="alternate" type="text/html" href="https://te4.org/w/index.php?title=T4_Modules_Howto_Guide/Achievements&amp;diff=6517&amp;oldid=prev"/>
				<updated>2014-01-06T03:40:22Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;&amp;#039;&amp;#039;&amp;#039;Work in progress.  Not yet finished or tested.&amp;#039;&amp;#039;&amp;#039;  = Adding the World =  T-Engine uses the [http://te4.org/docs/t-engine4/1.0.0/modules/engine.interface.WorldAchievements.h...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;'''Work in progress.  Not yet finished or tested.'''&lt;br /&gt;
&lt;br /&gt;
= Adding the World =&lt;br /&gt;
&lt;br /&gt;
T-Engine uses the [http://te4.org/docs/t-engine4/1.0.0/modules/engine.interface.WorldAchievements.html WorldAchievements] interface to track and grant achievements and stores achievements as part of the [http://te4.org/docs/t-engine4/1.0.0/modules/engine.World.html World] object.  To add these to your own module:&lt;br /&gt;
&lt;br /&gt;
Add a World.lua file in your class directory.  Sample contents (based on [http://git.net-core.org/darkgod/t-engine4/blob/master/game/modules/tome/class/World.lua ToME's]):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
require &amp;quot;engine.class&amp;quot;&lt;br /&gt;
require &amp;quot;engine.World&amp;quot;&lt;br /&gt;
require &amp;quot;engine.interface.WorldAchievements&amp;quot;&lt;br /&gt;
local Savefile = require &amp;quot;engine.Savefile&amp;quot;&lt;br /&gt;
&lt;br /&gt;
module(..., package.seeall, class.inherit(engine.World, engine.interface.WorldAchievements))&lt;br /&gt;
&lt;br /&gt;
function _M:init()&lt;br /&gt;
    engine.World.init(self)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function _M:run()&lt;br /&gt;
    self:loadAchievements()&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--- Requests the world to save&lt;br /&gt;
function _M:saveWorld(no_dialog)&lt;br /&gt;
    -- savefile_pipe is created as a global by the engine&lt;br /&gt;
    savefile_pipe:push(&amp;quot;&amp;quot;, &amp;quot;world&amp;quot;, self)&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Change load.lua to create a World object as well as a Game object.  To do so, edit the last line.  It should look something like this:&lt;br /&gt;
&lt;br /&gt;
 return { require &amp;quot;mod.class.Game&amp;quot; }&lt;br /&gt;
&lt;br /&gt;
Replace it with this:&lt;br /&gt;
&lt;br /&gt;
 return { require &amp;quot;mod.class.Game&amp;quot;, require &amp;quot;mod.class.World&amp;quot; }&lt;br /&gt;
&lt;br /&gt;
= Defining Achievements =&lt;br /&gt;
&lt;br /&gt;
Under your module's data directory, create an achievements directory.  Create as many .lua files defining achievements within this directory as you like; each .lua file should call the T-Engine [http://te4.org/docs/t-engine4/1.0.0/modules/engine.interface.WorldAchievements.html#_M:newAchievement newAchievement] function for each achievement to be created.&lt;br /&gt;
&lt;br /&gt;
Here's a sample, based on ToME itself:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
newAchievement{&lt;br /&gt;
    name = &amp;quot;Pyromancer&amp;quot;,&lt;br /&gt;
    desc = [[Unlocked Archmage class and did over one million fire damage (with any item/talent/class).]],&lt;br /&gt;
    show = &amp;quot;full&amp;quot;,&lt;br /&gt;
    mode = &amp;quot;world&amp;quot;,&lt;br /&gt;
    can_gain = function(self, who, dam)&lt;br /&gt;
        self.nb = (self.nb or 0) + dam&lt;br /&gt;
        return self.nb &amp;gt; 1000000 and profile.mod.allow_build.mage&lt;br /&gt;
    end,&lt;br /&gt;
    track = function(self) return tstring{tostring(math.floor(self.nb or 0)),&amp;quot; / 1000000&amp;quot;} end,&lt;br /&gt;
    on_gain = function(_, src, personal)&lt;br /&gt;
        game:setAllowedBuild(&amp;quot;mage_pyromancer&amp;quot;, true)&lt;br /&gt;
        local p = game.party:findMember{main=true}&lt;br /&gt;
        if p.descriptor.subclass == &amp;quot;Archmage&amp;quot;  then&lt;br /&gt;
            if p:knowTalentType(&amp;quot;spell/wildfire&amp;quot;) == nil then&lt;br /&gt;
                p:learnTalentType(&amp;quot;spell/wildfire&amp;quot;, false)&lt;br /&gt;
                p:setTalentTypeMastery(&amp;quot;spell/wildfire&amp;quot;, 1.3)&lt;br /&gt;
            end&lt;br /&gt;
        end&lt;br /&gt;
    end,&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Parameters for newAchievement:&lt;br /&gt;
&amp;lt;table class=&amp;quot;wikitable&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;Parameter&amp;lt;/th&amp;gt;&lt;br /&gt;
    &amp;lt;th&amp;gt;Description&amp;lt;/th&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;name&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;Name of the achievement&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;id&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;Internal ID of the achievement. Optional. If not provided, then name will be used, uppercased and with spaces replaced with underscores.&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;desc&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;Full description&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;image&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;Optional filename for the achievement&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;mode&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;quot;world&amp;quot;, &amp;quot;game&amp;quot;, &amp;quot;player&amp;quot;, or &amp;quot;none&amp;quot;.  Indicates whether the achievement is tracked for the persistent World object, the game object, or the current player. For example, achievements that can only be gained once ever should be world achievements, while per-character achievements should be player.&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;huge&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;If true, this achievement is a big deal and gets some extra emphasis when announced.&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;show&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;Determines how this achievement is listed in the default [http://te4.org/docs/t-engine4/1.0.0/modules/engine.dialogs.ShowAchievements.html ShowAchievements] dialog:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;false, nil, or not provided - The achievement is completely hidden. Only the &amp;quot;Achievements (#received/#total)&amp;quot; display at the top of the dialog gives any clue that it exists.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;quot;none&amp;quot; - The achievement is listed as &amp;quot;???&amp;quot;, and its description is &amp;quot;-- Unknown --&amp;quot;.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;quot;name&amp;quot; - The achievement's name is listed, but its description is &amp;quot;-- Unknown --&amp;quot;.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;quot;full&amp;quot; (or anything else) - Full details are listed, whether or not you have the achievement.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;no_chat_broadcast&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;If provided and true, then don't broadcast to the in-game chat when this achievement is gained.&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;can_gain&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;&amp;lt;p&amp;gt;Optional function, taking (data, src, ...) arguments (where ... is whatever additional arguments were passed to [http://te4.org/docs/t-engine4/1.0.0/modules/engine.interface.WorldAchievements.html#_M:gainAchievement gainAchievement] or [http://te4.org/docs/t-engine4/1.0.0/modules/engine.interface.WorldAchievements.html#_M:gainPersonalAchievement gainPersonalAchievement]), to be called to check whether the achievement can be gained.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;data is the persistent achievement data: either world.achievement_data, game.achievement_data, or player.achievement_data, depending on mode.&amp;lt;/p&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;track&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;Optional function, taking (data, src) arguments, giving progress towards the achievement (for display in the [http://te4.org/docs/t-engine4/1.0.0/modules/engine.dialogs.ShowAchievements.html ShowAchievements] dialog).  Should return a tstring.&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;on_gain&amp;lt;/td&amp;gt;&lt;br /&gt;
    &amp;lt;td&amp;gt;Optional function, taking (self, src, personal) arguments (where self is the achievement definition), to be called when an achievement is gained.&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once you're finished, add code to your load.lua to load the achievements.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
local WorldAchievements = require &amp;quot;engine.interface.WorldAchievements&amp;quot;&lt;br /&gt;
WorldAchievements:loadDefinition(&amp;quot;/data/achievements/&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Showing Achievements =&lt;br /&gt;
&lt;br /&gt;
In your Game.lua, you most likely have a call to engine.dialogs.GameMenu, where you pass in a list of menu items for the in-game main menu.  Add &amp;quot;achievements&amp;quot; to the list of items here.  Then, pressing Esc within the game will include a &amp;quot;Show Achievements&amp;quot; item where you can see the achievements you've defined and whether or not you've received them yet.&lt;br /&gt;
&lt;br /&gt;
{{Module Guides}}&lt;/div&gt;</summary>
		<author><name>Castler</name></author>	</entry>

	</feed>