Hello, everyone!

I'm a PHP programmer and I've been working with Drupal for a few weeks. I've read the quick tutorial on how to create a module and got a good idea.

My site is a gaming site, and I want to create a "Achievements" module. Those who have played on XBox, Windows Live or WoW know how it works: It's a reward that an user gains when he achieves a specific goal.

Example: Whenever a user makes 100 posts, the Achievement "Hundred Poster" is unlocked.

I want to port this feature to my Drupal website, and I need some conceptual assistance since it's my first module and the concept is pretty complicated itself, since I see an achievement as both a node and an action.

My ideas:

Achievement as a Node Type

  • An achievement needs four fields:
    • A name;
    • An icon;
    • A description on how to unlock it;
    • The type of the achievement. Achievement are splitted in two types:
      • Automatic, as described below;
      • Manual, an achievement that has to be manually unlocked for each user.
  • Each user can unlock any number of achievements.
  • The achievements unlocked by the user can be seen on his profile, as well as in every post made by the user in the forums.
  • When the node is viewed, a list showing how many users have unlocked that single achievement is shown.

Achievement as an Action

  • Each automatic achievement has a PHP code that describes the condition to unlock it.
  • Some achievements can only be unlocked after other achievements are unlocked (such as "Make 50 posts" and "Make 100 posts"). Therefore, it's possible to have a tree of achievements.
  • The achievements could be processed through Drupal's core Trigger module.
  • Whenever a achievement is unlocked, a message is shown on the page (using DOM and an JQuery/Scrip.taculo.us effect).

Well... that pretty much sums it up.

Since I'm a newbie at module development, my question is... how am I supposed to mix all of there interactions with different modules (CCK, Views, Actions and Trigger just at first sight) in one single module?

Tutorials, APIs... every kind of help is appreciated.

Thanks in advance! :)

Comments

morbus iff’s picture

I've already coded something like this, but never got around to releasing it.
What's your email? I'll send it to you (mine's morbus@disobey.com).

From the README.txt:

The Achievements module is intended to emulate Xbox 360 achievements, a
system whereby gamers are awarded points for the completion of game-specific
challenges. For a Drupal site, this could mean commenting a certain number of
times, starting a forum topic, visiting the site every day of the week, or
any number of other possibilities.

There are a few conceptual differences between Achievements and User Points:

 * Unlike the points of User Points, a user never loses his achievement
   points for, say, an e-commerce purchase or other redeemable item.

 * Unlike the points of User Points, achievement points are based on
   milestones, not necessarily activity. Whereas, in User Points, a user
   may get 5 points every time he posts a node, a matching achievement
   would instead reward 100 points for posting 10 nodes (or 50, etc.)

 * Since achievements are "milestones", each one has its own leaderboard
   that lists when a user has met (or "unlocked") the goal, and their
   matching rank. A site-wide leaderboard ranks users by points they've
   achieved, but also by timestamp -- if two users share the same point
   total, the person who got there first gets the higher rank.

 * Achievements can be hidden so that a user doesn't know how to unlock
   it until he stumbles upon the discovery himself (either by meeting the
   milestone, asking another user, etc.).

 * Unlike User Points, the only achievement data stored in the database
   is the achievement's internal ID and when the user unlocked it. This
   allows you to change the achievement details (spelling, name, etc.)
   without having to issue database updates.

 * Achievements are defined via an API hook, like Drupal's menus and forms,
   and can be enabled or disabled by an admin. This allows modules to ship
   with dozens of achievements, but gives the admin the ability to shut off
   specific milestones that may not apply to his user base.

 * Achievements are not retroactively applied - you either get them after
   the Achievements module has been enabled, or you don't get them at all.
   Likewise, achievements can not be deleted (but that may change).

 * Fundamentally, a user can never go down in score. If you need to "shame"
   your users, you can create 0 point achievements like "Had 5 comments
   deleted", "Was blocked", etc. The Achievements module does not ship
   with any of these shame achievements.

The achievements are done as PHP actions... here's an example of a definition:

function achievements_comment_achievements_info() {
  return array(
    'comment-count-1' => array(
      'title'       => t('Posted your first comment'),
      'description' => t('You have successfully delurked. Welcome!'),
      'points'      => 5,
    ),
  );
}

And, the actioning code (which you'd run in a hook_comment sorta thing):

function achievements_comment_count($uid) {
  $counts = array(1, 5, 25, 100);

  foreach ($counts as $count) {
    // if even just one of our achievements is enabled, we need to count
    // comments. it'd be a bit lame, but someone could disable comment-1
    // but still want the rest of the comments (10, 100, 250, etc.).
    if (achievements_enabled('comment-count-' . $count)) {
      $counting_enabled = TRUE;
    }
  }

  if ($counting_enabled) {
    $current_count = achievements_storage_get('comment_count', $uid) + 1;
    achievements_storage_set('comment_count', $uid, $current_count);

    if (in_array($current_count, $counts)) {
      achievements_unlocked('comment-count-' . $current_count);
    }
  }
}

The code also supports "hidden" achievements (wherein the user can't see what it is until he unlocks it), as well as leaderboards (so you can track who got the achievement first and most recently). It doesn't currently support icons, but that could easily be added in (I just didn't do it because I don't have any graphical capabilities).

AeroGabriel’s picture

Wow, nice! Thanks!
My e-mail is aero@zelda.com.br.

You've tested it already?

morbus iff’s picture

Of course. I ran it on a live site for awhile, before said site was shuttered.

Will send it to ya shortly.

wolf125’s picture

Would you mind sending me that achievement code that you gave AeroGabriel. I would like to make my own achievements, but I don't have quite enough knowledge in the subject and I'd rather not end up killing my site again. Otherwise I would make my own achievements. My email is dannon.trujillo@my.netech.edu

jason_gates’s picture

mustainer’s picture

Hi!

Could you please send a copy to my email (mustainer2@gmail.com)?

Thanks,

guile2912’s picture

I would really be interested in this module too (as in its developpement as I am running a video gamming site too)
(we should really do a reall project on drupal.org for this :p )
*edit* removing email from this old post

mikee216’s picture

I am also very interested, where can I get this module?
Thanks
Best regards

Veryhappy’s picture

Would you mind sending me the code anticolicos @ gmail . Com please?
Thanks in advance

ColdSun’s picture

By any chance, could you send me a copy as well as I was actually just sitting down to start writing my own?
ColdSun[at]unitedadmins[.]com
Thanks =)

VikingJohn’s picture

Hi Guys,

Does anyone have any updates on possible module development for this achievements module?

I searched the module directory and come across this: http://drupal.org/project/achievements but there has been no further updates on a release for that module.

I stumbled across this thread and it looks like you guys have put together some code.

I am not a developer so cannot use the information posted here to build my own achievement module :( but I really need an achievement module to use on my site. It's a really nice feature that will add a lot of value in terms of encouraging user/community activity when using the site.

It would be great if you guys could get together and build this as a module for other users to download for use on their own Drupal sites.

Another nice feature to add when building this module would be to link it in with the http://drupal.org/project/userpoints module, so that when a user unlocks an achievement they will also be awarded a number of 'User Points'.

Can someone please please please develop and release this plug in for the community.

Cheers,

John

izmeez’s picture

It looks like code has been posted by Morbus_Iff to the http://drupal.org/project/achievements issue queue, but it's not clear what else is happening, is there a maintainer and plans for a release?

dsab’s picture

This sounds exactly like something I need for my website. I would like a copy of this module (send to dirtysab@gmail.com) and be a part of the development. I want to add way more behind the scene stuff for getting achievements.

xorkh1’s picture

Anyone mind sending me a copy of this module xorkh1[at]gmail[.]com.
I'm working on a site that needs this functionality. I'd be interested in working on development.

wastrilith2k’s picture

wastrilith [at] hotmail [dot] com

morbus iff’s picture

Achievements are now available for Drupal 7: http://drupal.org/project/achievements