The RPG Maker Resource Kit

RMRK RPG Maker Creation => XP => XP Scripts Database => Topic started by: tSwitch on April 23, 2009, 11:59:03 PM

Title: [XP] NAM's Achievement Logger v1.01
Post by: tSwitch on April 23, 2009, 11:59:03 PM
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


Screenshots

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

Demo

No demo yet.

Script

Spoiler for:
Code: [Select]
#===============================================================================
# Achievement Logger XP version 1.00
#-------------------------------------------------------------------------------
# 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

Instructions

Instructions are in the comments section of the script.

Compatibility

No known compatibility issues.

Credits and Thanks


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.

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 lisence
Title: Re: [XP] NAM's Achievement Logger v1.00
Post by: Grafikal on April 24, 2009, 01:24:04 AM
ooo, sexy.
Title: Re: [XP] NAM's Achievement Logger v1.00
Post by: tSwitch on April 24, 2009, 04:16:52 AM
yeah it's pretty much the same function as the one game_guy posted, except mine saves the info externally so you have a lot more freedom with it.