[XP] NAM's Achievement Logger v1.01

Started by tSwitch, April 23, 2009, 07:43:35 pm

Previous topic - Next topic

tSwitch

April 23, 2009, 07:43:35 pm Last Edit: May 14, 2009, 10:23:12 am by Elite Four NAMKCOR
NAM's Achievement Logger
Authors: NAMKCOR
Version: 1.01
Type: Utility
Key Term: Misc System



Introduction

Fairly simple script, it's a backbone for an Achievement system, much like the 360 or PS3.
NOTE: AT THIS TIME THERE IS -NO- SCENE INCLUDED, IT IS -ONLY- THE SYSTEM ITSELF.


Features


  • Plug and play
  • Saves Achievement data externally, no need to load a game to view!



Screenshots

No screenshots, since I haven't made a scene for it.


Demo

No demo yet.


Script

Spoiler: ShowHide

#===============================================================================
# Achievement Logger XP version 1.01
#-------------------------------------------------------------------------------
# Function:
#  Allows for a simple scripted Achievement system, much like
#  XBOX360 or PS3 games.
#-------------------------------------------------------------------------------
# Features :
#  - Pretty much plug and play
#  - Saves Achievements externally, so they are independent of save games
#
#  note: this is only a backbone system, there is no scene in this script.
#        a scene will be posted separately.
#-------------------------------------------------------------------------------
# Compatibility:
#  This script -should- be compatible with just about everything
#-------------------------------------------------------------------------------
# Instructions:
#   - Setup for config variables is located where the variables are.
#   
#   - To make an Achievement, simply make an item in the database, and
#     in the elements list, check the box for the element you've chosen
#     to represent Achievements with.
#     It is reccommended that the items are unusable, in order to
#     prevent glitching.
#     
# ---WARNING---
# This system will automatically create and update a file that stores the
# achievements outside the game saves.
#
# The Achievement data file is updated at FIRST runtime (i.e. if the file does
# not exist, and every time that the 'achieve()' method is called.
#
# If you modify the achievements in the database,
# It is reccommended that you delete the acheivement file before running the
# game, after having updated the achievements database.
# Keep in mind that this will clear whatever achievements might have been
# cleared.
# -------------
#   
#   - To give the player an achievement, call the function:
#     $game_achievements.achieve(ITEM_ID)
#     (script event call)
#     where ITEM_ID is the ID of the achievement you are giving the player.
#
#   - As far as other scipts go, a couple methods have been created
#     help make things neater and easier for scripters :)
#
#     $game_achievements.get_achievements
#     :: returns the entire @achievements array.
#
#     $game_achievements.achieved?(item_id)
#     :: returns true if the achievement has been earned, false if not.
#
#     $game_achievements.set_scene(scene)
#     :: use any type of variable you want, to record what scene
#        you just came from
#
#     $game_achievements.get_scene
#     :: return @scene_from
#
#-------------------------------------------------------------------------------
# Contact:
#  Should you encounter a bug or incompatibility with this script,
#  e-mail NAMKCOR at Rockman922@hotmail.com, or message at
#  http://www.rmrk.net or http://www.chaos-project.com/
#
#  This script was designed for use and distribution only on
#  The RPG Maker Resource Kit (RMRK) and Chaos Project.
#  If this script is found posted on any other website, it is STOLEN
#  and it is advised to contact NAMKCOR at the above methods.
#
#  This work is protected by the
#  Creative Commons - Attribution-NonCommercial-ShareAlike 3.0 Unported
#  ( http://creativecommons.org/licenses/by-nc-sa/3.0/ )
#
#  By using this work you agree to be bound by the aforementioned liscence
#===============================================================================

module NAMKCOR
 
  #========================================================================
  # ACHIEVEMENT_FILENAME:
  #------------------------------------------------------------------------
  # Self-explanitory, this is the file that the achievement data is
  # contained in when it saves.
  #
  # Can be named anything, with any extension, must be in SINGLE QUOTES ''
  #     'AIDS.std'
  #     'Blizzard.sex'
  #     'Rivy.bdsm'
  #     'Rockman.x'
  #
  # it really doesn't matter, it'll work, have fun with it :P
  #========================================================================
  ACHIEVEMENT_FILENAME = 'achievements.namk'
 
  #========================================================================
  # ACHIEVEMENT_ELEMENT:
  #------------------------------------------------------------------------
  # Also Self-explanitory, this is the ID of the element that represents
  # Achievements.
  #========================================================================
  ACHIEVEMENT_ELEMENT = 20
 
end

#===============================================================================
# DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING
#===============================================================================

class Game_Achievements
 
  def initialize
    @achievements = []
    @achieved = []
    @scene_from
    setup_achievements
  end
 
  def set_scene(scene)
    @scene_from = scene
  end

  def get_scene
    return @scene_from
  end
 
  def achieved?(item_id)
    return @achieved.include?(item_id)
  end
 
  def get_achievements
    return @achievements
  end
 
  def achieve(item_id)
    @achieved.push(item_id)
    save_achievements
  end
   
  def setup_achievements
    for i in 1...$data_items.size
      if $data_items[i].element_set.include?(NAMKCOR::ACHIEVEMENT_ELEMENT)
        @achievements.push($data_items[i])
      end
    end
    save_achievements
  end
 
  def save_achievements
    file = File.open(NAMKCOR::ACHIEVEMENT_FILENAME, 'w')
    Marshal.dump(self, file)
    file.close
  end
     
end

$data_items = load_data("Data/Items.rxdata")
if File.exists?(NAMKCOR::ACHIEVEMENT_FILENAME)
  file = File.open(NAMKCOR::ACHIEVEMENT_FILENAME, 'r')
  $game_achievements = Marshal.load(file)
  file.close
else
  $game_achievements = Game_Achievements.new
end


"Scene_Achievement": ShowHide


class Scene_Achievement
 
  def main
    @scene_from = $scene.class
    @help_window = Window_Help.new
    #it's achievements now,
    #so the item window loads our achievement scene
    @item_window = Window_Achievement.new
    @item_window.help_window = @help_window
    #no need for a target window, so I removed it
    Graphics.transition
    loop do
      Graphics.update
      Input.update
      update
      if $scene != self
        break
      end
    end
    Graphics.freeze
    #removed target window here too
    @help_window.dispose
    @item_window.dispose
  end
 
  def update
    #removed target window here too
    @help_window.update
    @item_window.update
    if @item_window.active
      update_item
      return
    end
  end
 
  def update_item
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      #return to the scene that you came from!
      @scene_from = $game_achievements.get_scene
      $scene = @scene_from.new
      return
    end
    #you can't use achievements, so only a cancel button is needed.
  end
 
end




"Window_Achievement": ShowHide


class Window_Achievement < Window_Selectable

  def initialize
    super(0, 64, 640, 416)
    @column_max = 2
    refresh
    self.index = 0
  end

  def item
    return @data[self.index]
  end

  def refresh
    if self.contents != nil
      self.contents.dispose
      self.contents = nil
    end
 
    #make data the list of achievement items :D
    @data = $game_achievements.get_achievements

    @item_max = @data.size
    if @item_max > 0
      self.contents = Bitmap.new(width - 32, row_max * 32)
      for i in 0...@item_max
        draw_item(i)
      end
    end
  end
 
  def draw_item(index)
    item = @data[index]
 
    #if the achievement has been achieved, it's displayed in white
    #if it's not, it's grayed out!
    if $game_achievements.achieved?(item.id)
      self.contents.font.color = normal_color
    else
      self.contents.font.color = disabled_color
    end
   
    x = 4 + index % 2 * (288 + 32)
    y = index / 2 * 32
    rect = Rect.new(x, y, self.width / @column_max - 32, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    bitmap = RPG::Cache.icon(item.icon_name)
    opacity = self.contents.font.color == normal_color ? 255 : 128
    self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
    self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
  end

  def update_help
    @help_window.set_text(self.item == nil ? "" : self.item.description)
  end
end




To use the above scene/window in your game, be sure to use the following code segment when activating the window from the title/menu/anywhere else, so that it doesn't bug, and so that when you exit the scene it returns to where you came from


$game_achievements.set_scene($scene.class)
$scene = Scene_Achievement.new


Warning: the default menu does -not- like the 'call script' command.



Instructions

Instructions are in the comments section of the script.


Compatibility

No known compatibility issues.


Credits and Thanks


  • NAMKCOR

  • Game_Guy, for motivating me to make a script for a change

  • Blizzard, for his help with loading files




Author's Notes

Contact:
Should you encounter a bug or incompatibility with this script,
e-mail NAMKCOR at Rockman922@hotmail.com, or message at
http://www.rmrk.net or http://www.chaos-project.com/

This script was designed for use and distribution only on
The RPG Maker Resource Kit (RMRK) and Chaos Project.
If this script is found posted on any other website, it is STOLEN
and it is advised to contact NAMKCOR at the above methods.

Attribution-Noncommercial-Share Alike 3.0 Unported


By using this work you agree to be bound by the aforementioned lisence


FCF3a A+ C- D H- M P+ R T W- Z- Sf RLCT a cmn+++ d++ e++ f h+++ iw+++ j+ p sf+
Follow my project: MBlok | Find me on: tSwitch.us | Twitter | Tumblr

G_G

I like it. I'm guessing this'll be easier to use than my script at least til my next update. All you gotta do is make items and add them to party. But cool *powers up*

tSwitch

April 23, 2009, 07:56:57 pm #2 Last Edit: April 24, 2009, 08:57:09 am by NAMKCOR
Quote from: game_guy on April 23, 2009, 07:55:30 pm
I like it. I'm guessing this'll be easier to use than my script at least til my next update. All you gotta do is make items and add them to party. But cool *powers up*


well, make the items, then use the script call to add them yeah.
The script does the rest :)

You can even call the Achievement scene from the title menu, so you can have Achievements like "beat the game on [easy/medium/hard] difficulty" and other fun ones :)


FCF3a A+ C- D H- M P+ R T W- Z- Sf RLCT a cmn+++ d++ e++ f h+++ iw+++ j+ p sf+
Follow my project: MBlok | Find me on: tSwitch.us | Twitter | Tumblr

Mightylink

Nice to see people finally realizing this is the future of gaming. Can't wait to see whos script turns out better.

tSwitch

Quote from: Mightylink on April 23, 2009, 08:06:46 pm
Nice to see people finally realizing this is the future of gaming. Can't wait to see whos script turns out better.


The only real difference between ours is that mine does a lot more of the work for you, and allows more freedom as far as where you can call the scene, and the kinds of achievements you can make.

lol.


FCF3a A+ C- D H- M P+ R T W- Z- Sf RLCT a cmn+++ d++ e++ f h+++ iw+++ j+ p sf+
Follow my project: MBlok | Find me on: tSwitch.us | Twitter | Tumblr

fugibo

Actually, its more like the past. Don't you remember "High Scores?"

Tazero

[OFFTOP.] So i got over my 666 post count[/ot]

*claps* nice very very nice...when you get an achievment is it possible to make an image pop up for a certain number of frames then fade out? Like it's animated we give the base image(s) then 'text' appears on the base?


If you were a fish...

Mightylink

I think you would be able to do that with an event, run whatever you like and have the extra add achivement line at the end :)

Diokatsu


tSwitch

Quote from: Mightylink on April 24, 2009, 11:42:59 pm
I think you would be able to do that with an event, run whatever you like and have the extra add achivement line at the end :)


show picture
move picture (make it show up)
wait
move picture (make it go away)
erase picture
$game_achievements.achieve(item_id)


FCF3a A+ C- D H- M P+ R T W- Z- Sf RLCT a cmn+++ d++ e++ f h+++ iw+++ j+ p sf+
Follow my project: MBlok | Find me on: tSwitch.us | Twitter | Tumblr

G_G

Lol I tested this and it only saves one achievement to the log. I made it achievements.txt for file and I opened it and it only saves teh last achievement that was achieved.

tSwitch

added v1.01 to the topic and upated it with a default window/scene achievement, plus instructions on how to call the achievements scene properly.

Quote from: Youngster Gi Gi on May 06, 2009, 08:03:04 pm
Lol I tested this and it only saves one achievement to the log. I made it achievements.txt for file and I opened it and it only saves teh last achievement that was achieved.


go play Anima, as you unlock achievements they all get saved properly.
I don't feel like explaining how it works right now, but it does, I've done exactly by my instructions how to use the system, and in Anima the achievements work flawlessly.


FCF3a A+ C- D H- M P+ R T W- Z- Sf RLCT a cmn+++ d++ e++ f h+++ iw+++ j+ p sf+
Follow my project: MBlok | Find me on: tSwitch.us | Twitter | Tumblr

BlackStatic

(call event script)

What do I put in that?

I set everything up, but it doesn't give me the achievement, possibly because i don't know what to put in that parentheses.
"A dead thing can go with the stream, but only a living thing can go against it..."

Aqua

Quote
#   - To give the player an achievement, call the function:
#     $game_achievements.achieve(ITEM_ID)
#     (script event call)
#     where ITEM_ID is the ID of the achievement you are giving the player.


Didja read the instructions???