The RPG Maker Resource Kit

RMRK RPG Maker Creation => XP => XP Scripts Database => Topic started by: game_guy on April 20, 2009, 02:37:30 PM

Title: [XP] Achievements Script
Post by: game_guy on April 20, 2009, 02:37:30 PM
Achievements Script
Authors: game_guy
Version: 2.22
Type: A Goals Type Script
Key Term: Misc System

Introduction

A full blown achievement system. Keep track of events your players pull off and make them feel like they've really achieved something. Easy to setup, plenty of options to configure it the way you want.

Features

I'm gonna leave the old list here so you can see the comparison.
Quote from: Old Features
  • Use Achievements in your game!
  • Simple Plug and Play (besides setting up achievements)
  • Achievements Easy to Setup!
  • GamerScore is displayed.
  • You can change what the Score is named
  • Score is stored in a variable and you choose the number.
  • Theres an option to turn on the Print so it prints what achievement you unlocked.
New ones

Screenshots

Spoiler for:
(https://rmrk.net/proxy.php?request=http%3A%2F%2Fdecisive-media.net%2Fgameguy%2Faward0.png&hash=c7aa595483ebba87209a2512a94de5caacd199aa)
Spoiler for:
(https://rmrk.net/proxy.php?request=http%3A%2F%2Fdecisive-media.net%2Fgameguy%2Faward1.png&hash=c813ce6a2ffe8e18268e4e53e37d6072acd924fe)
Spoiler for:
(https://rmrk.net/proxy.php?request=http%3A%2F%2Fdecisive-media.net%2Fgameguy%2Faward2.png&hash=7fcb7fcaa00fb08d083e5a80f06d563e9606b37c)
Spoiler for:
(https://rmrk.net/proxy.php?request=http%3A%2F%2Fdecisive-media.net%2Fgameguy%2Faward3.png&hash=93a217e770c2a74d17f5c8249bdaf2f0f5377190)
Spoiler for:
(https://rmrk.net/proxy.php?request=http%3A%2F%2Fdecisive-media.net%2Fgameguy%2Faward4.png&hash=be02b0f060a311c24fce5cb4068ee38011fa8b3e)
Spoiler for:
(https://rmrk.net/proxy.php?request=http%3A%2F%2Fdecisive-media.net%2Fgameguy%2Faward5.png&hash=8935f7f918c7a53b60957843ba16d83d5fd6fe07)
Spoiler for:
(https://rmrk.net/proxy.php?request=http%3A%2F%2Fdecisive-media.net%2Fgameguy%2Faward6.png&hash=45377e454f20153a94fccfd1fdf18d8cd8b859f5)
Spoiler for:
(https://rmrk.net/proxy.php?request=http%3A%2F%2Fdecisive-media.net%2Fgameguy%2Faward7.png&hash=674e99e78f5f4bccb0b058cc1b648ff58319868a)

Demo

Demo v2.0 (Outdated and Possibly Bugged) (http://decisive-media.net/gameguy/Achievements.exe)

Script

Spoiler for:
Code: [Select]
#===============================================================================
# Achievements
# Version 2.22
# Author game_guy
#-------------------------------------------------------------------------------
# Intro:
# A full blown achievement system. Keep track of events your players pull off
# and make them feel like they've really achieved something. Easy to setup,
# plenty of options to configure it the way you want.
#
# Features:
# -Image/Text Achievement Notification
# -Show all achievements or only ones you unlocked
# -Change text font, size, and color
# -Option to keep track of score
# -Modify notification position
# -Modify text position if using an image
# -Modify popup time
# -Play sound when you unlock an achievement
# -Set return scene, scene you go to when exiting achievements menu
# -Custom queue system allowing you to display multiple achievements at a time
# -Much more compatible
# -Quickly open up achievements without interupting the current scene
# -Block scenes from the Quick Open
# -See if user has a specific achievement
# -See how many achievements the player has
# -Custom Icon Size Support
#
# Instructions:
# -Go down to Begin Config and edit all of your options there.
# -Instructions for creating achievements are also in the Config.
# -To gain an achievement, use Awards.gain(award_id)
# -Award id is set when creating awards.
# -To see if a user has an award use Awards.has?(award_id)
# -To see how many the player has use Awards.count
# -To open up the real achievements scene use
#  $scene = Scene_Achievements.new
#
# Compatibility:
# -Not tested with SDK.
# -Should work with everything.
# -May corrupt old save games.
#
# Credits:
# -game_guy ~ For creating it.
# -jragyn00 ~ For the new layout.
# -GAX72 ~ For test achievement image.
#===============================================================================
module Awards
#===============================================================
# Begin Config
#===============================================================
  #----------------------------------------------------------------------------
  # If true, it'll show all unlocked and locked achievements, else it'll just
  # show unlocked achievements
  #----------------------------------------------------------------------------
  Show_All      = true
  #----------------------------------------------------------------------------
  # If Show_All is on, all locked icons will be displayed with the below
  # icon
  #----------------------------------------------------------------------------
  Locked_Icon   = "locked"
  #----------------------------------------------------------------------------
  # This replaces the achievments description if Show_All is on and the
  # achievement is marked as hidden.
  #----------------------------------------------------------------------------
  Hidden_Info   = "This achievement is hidden. Unlock it to find out more."
  #----------------------------------------------------------------------------
  # The scene you go to when you exit the achievements menu
  #----------------------------------------------------------------------------
  Return_Scene  = Scene_Menu
  #----------------------------------------------------------------------------
  # If set to an Input key, it will open up a quick view window to view all
  # achievements, can be opened up from anywhere, and doesn't interupt the
  # current scene. Set to nil to turn it off.
  #----------------------------------------------------------------------------
  Quick_Access  = Input::A
  #----------------------------------------------------------------------------
  # Add scenes here that you want quick access blocked on. Example,
  # Scene_Title, wouldn't want users to view achievements there. Kinda odd.
  #----------------------------------------------------------------------------
  Block_Scenes  = [Scene_Title, Scene_Gameover, Scene_File]
  #----------------------------------------------------------------------------
  # Keep track of score?
  #----------------------------------------------------------------------------
  Track_Score   = true
  #----------------------------------------------------------------------------
  # Text for "Score"
  #----------------------------------------------------------------------------
  Score_Text    = "Points"
  #----------------------------------------------------------------------------
  # Variable to store the score in. (hehe)
  #----------------------------------------------------------------------------
  Variable_Id   = 5
  #----------------------------------------------------------------------------
  # Font name
  # Place your font in string tags "font_here"
  # Or leave it as is to leave the default font.
  #----------------------------------------------------------------------------
  Text_Font     = Font.default_name
  #----------------------------------------------------------------------------
  # Font color : Color.new(red, green, blue)
  #----------------------------------------------------------------------------
  Text_Color    = Color.new(255, 255, 255)
  #----------------------------------------------------------------------------
  # Font size
  #----------------------------------------------------------------------------
  Text_Size     = 24
  #----------------------------------------------------------------------------
  # Where will the award show up on the screen. [X, Y]
  #----------------------------------------------------------------------------
  Award_Place   = [16, 16]
  #----------------------------------------------------------------------------
  # Use background image behind text?
  #----------------------------------------------------------------------------
  Use_Image     = true
  #----------------------------------------------------------------------------
  # File used to display behind the text.
  #----------------------------------------------------------------------------
  Image_File    = "award_background"
  #----------------------------------------------------------------------------
  # Offset for text drawn over the image. [X, Y]
  #----------------------------------------------------------------------------
  Image_Offset  = [72, 0]
  #----------------------------------------------------------------------------
  # Draw icon on notification image?
  #----------------------------------------------------------------------------
  Draw_Icon     = true
  #----------------------------------------------------------------------------
  # Offset for icon drawn over the image. [X, Y]
  #----------------------------------------------------------------------------
  Icon_Offset   = [20, 20]
  #----------------------------------------------------------------------------
  # Custom icon size. If you change these values, you'll have to change
  # Icon_Row and Icon_QuickRow. [WIDTH, HEIGHT]
  #----------------------------------------------------------------------------
  Icon_Size     = [24, 24]
  #----------------------------------------------------------------------------
  # How many icons are displayed in one column (across).
  #----------------------------------------------------------------------------
  Icon_Column   = 10
  #----------------------------------------------------------------------------
  # How many icons are in one column (across) in the Quick View scene.
  #----------------------------------------------------------------------------
  Icon_QColumn  = 8
  #----------------------------------------------------------------------------
  # Time the "Unlocked Achievement" pop up stays on screen in frames.
  #----------------------------------------------------------------------------
  Popup_Time    = 60
  #----------------------------------------------------------------------------
  # Sound played when an achievement pops up. ["sound", volume, pitch]
  #----------------------------------------------------------------------------
  Popup_Sound   = ["114-Remedy02", 100, 0]
  Award = []
  #----------------------------------------------------------------------------
  # To add a new award, add a new line:
  # Award[id] = ["name", "description", "icon", score_amount, hidden]
  # score_amount must be set even if Track_Score is off
  # hidden must be set even if Show_All is off
  # If you use Show_All and you want the description of achievements to be
  # hidden, set hidden to true. If its false, it'll tell the name and
  # description.
  #----------------------------------------------------------------------------
  Award[0] = ["New Game", "Start a new game!", "037-Item06", 10, false]
  Award[1] = ["Award 1", "Talk to guy 1.", "046-Skill03", 10, true]
  Award[2] = ["Award 2", "Talk to guy 1.", "046-Skill03", 10, false]
  Award[3] = ["500 Damage", "Deal 500 damage in one attack.", "004-Weapon04", 5, false]
  Award[4] = ["Am I rich?", "Have 1,000,000 gold at one time.", "035-Item04", 10, false]
  Award[5] = ["Window Shopper", "Spend 1,000,000 gold.", "032-Item01", 10, false]
  Award[6] = ["Longer Description", "OMGAR this has a longer description but carries on to the next line. I'm so sexy.", "033-Item02", 0, false]
  Award[7] = ["Log Jumper", "Jump over the log.", "048-Skill05", 5, false]
  Award[8] = ["Super Log Jumper", "Jump over the log 5 times", "048-Skill05", 25, false]
  Award[9] = ["I am hidden!", "Learn about hidden achievements.", "034-Item03", 10, true]
  Award[10] = ["GRRR!!!", "Brave enough to talk to a lion!", "019-Accessory04", 5, false]
  Award[11] = ["Invisible", "Found and talked to invisible person.", "049-Skill06", 50, false]
  Award[12] = ["Swiftly!", "Learn about the Quick Scene!", "020-Accessory05", 100, false]
#===============================================================
# End Config
#===============================================================
  def self.gain(id)
    return if $game_system.awards.include?(id)
    if Awards::Award[id] != nil
      $game_system.gain_award(id)
    end
  end
  def self.has?(id)
    return $game_system.awards.include?(id)
  end
  def self.count
    return $game_system.awards.size
  end
end

$gg_achievements = 2.2
#===============================================================================
# Sprite_Award
#-------------------------------------------------------------------------------
# Draws unlocked achievement.
#===============================================================================
class Sprite_Award < Sprite
  def initialize(award)
    super(nil)
    @award = award
    self.bitmap = Bitmap.new(1, 1)
    self.bitmap.font.size = Awards::Text_Size
    @text_width = self.bitmap.text_size(@award[0]).width + 8
    @text_height = self.bitmap.text_size(@award[0]).height
    self.bitmap.dispose
    if Awards::Use_Image
      @pic = RPG::Cache.picture(Awards::Image_File)
      @pic_width = @pic.width > @text_width ? @pic.width : @text_width
      @pic_height = @pic.height > @text_height ? @pic.height : @text_height
      self.bitmap = Bitmap.new(@pic_width, @pic_height)
      if Awards::Draw_Icon
        @icon = RPG::Cache.icon(@award[2])
      end
    else
      self.bitmap = Bitmap.new(@text_width, @text_height)
    end
    self.bitmap.font.color = Awards::Text_Color
    self.bitmap.font.name = Awards::Text_Font
    self.bitmap.font.size = Awards::Text_Size
    self.z = 20000
    self.x = Awards::Award_Place[0]
    self.y = Awards::Award_Place[1]
    refresh
  end
  def refresh
    self.bitmap.clear
    x = 0
    y = 0
    if @pic != nil
      self.bitmap.blt(0, 0, @pic, Rect.new(0, 0, @pic.width, @pic.height))
      x = Awards::Image_Offset[0]
      y = Awards::Image_Offset[1]
      if @icon != nil
        icon_off = Awards::Icon_Offset
        self.bitmap.blt(icon_off[0], icon_off[1], @icon, Rect.new(0, 0,
            Awards::Icon_Size[0], Awards::Icon_Size[1]))
      end
    end
    text = @award[0]
    if @text_width + x > self.bitmap.width
      text = self.bitmap.slice_text(@award[0], self.bitmap.width - x)
      text.each_index {|i|
        self.bitmap.draw_text(x, y + i * @text_height + 4,
            @text_width, @text_height, text[i])}
    else
      self.bitmap.draw_text(x, y, @text_width, @text_height, text)
    end
  end
  def dispose
    super
    if self.bitmap != nil
      self.bitmap.dispose
    end
  end
end
#===============================================================================
# Graphics
#-------------------------------------------------------------------------------
# **added method to control and draw all queued achievements.
#===============================================================================
module Graphics
  class << self
    alias gg_upd_awards_queue_lat update
  end
  def self.update
    @frame = 0 if @frame == nil
    if $game_system.queue.size > 0 && @frame < 1
      award = Awards::Award[$game_system.queue[0]]
      if award != nil
        @sprite = Sprite_Award.new(award)
        @frame = Awards::Popup_Time
        Audio.se_play("Audio/SE/#{Awards::Popup_Sound[0]}",
          Awards::Popup_Sound[1], Awards::Popup_Sound[2])
      end
    end
    if @frame > 0
      @frame -= 1
      if @frame < 1
        @sprite.dispose
        $game_system.queue.shift
      end
    end
    gg_upd_awards_queue_lat
  end
end
#===============================================================================
# Game_System
#-------------------------------------------------------------------------------
# **modded to keep track of queued and obtained achievements.
#===============================================================================
class Game_System
  attr_accessor :awards
  attr_accessor :queue
  alias gg_init_awards_sys_lat initialize
  def initialize
    @awards = []
    @queue = []
    gg_init_awards_sys_lat
  end
  def gain_award(id)
    return if @awards.include?(id) || Awards::Award[id] == nil
    if Awards::Track_Score
      $game_variables[Awards::Variable_Id] += Awards::Award[id][3]
    end
    @awards.push(id)
    @queue.push(id)
  end
end
#===============================================================================
# Bitmap
#===============================================================================
class Bitmap
  
  def slice_text(text, width)
    words = text.split(' ')
    return words if words.size == 1
    result, current_text = [], words.shift
    words.each_index {|i|
        if self.text_size("#{current_text} #{words[i]}").width > width
          result.push(current_text)
          current_text = words[i]
        else
          current_text = "#{current_text} #{words[i]}"
        end
        result.push(current_text) if i >= words.size - 1}
    return result
  end
  
end

#===============================================================================
# Window_QuickHelp
#===============================================================================
class Window_QuickHelp < Window_Base
  def initialize
    super(64, 32, 512, 160)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.z = 10000
  end
  def set_award(award)
    @award = award
    refresh
  end
  def refresh
    self.contents.clear
    self.contents.draw_text(0, 0, 512 / 2, 32, @award[0][0])
    if Awards::Track_Score
      text = "#{@award[0][3]} #{Awards::Score_Text}"
      self.contents.draw_text(0, 0, 512 - 32, 32, text, 2)
      text = "Total #{Awards::Score_Text}: #{$game_variables[Awards::Variable_Id]}"
      self.contents.draw_text(0, 32, 512 - 32, 32, text, 2)
    end
    text = self.contents.slice_text(@award[0][1], 512 - 32)
    if @award[0][4] && !$game_system.awards.include?(@award[1])
      text = self.contents.slice_text(Awards::Hidden_Info, 512 - 32)
    end
    text.each_index {|i|
      self.contents.draw_text(0, 64 + i * 32, 512 - 32, 32, text[i])}
  end
end
#===============================================================================
# Window_QuickAwards
#===============================================================================
class Window_QuickAwards < Window_Selectable
  def initialize
    super(64, 128 + 64, 512, 320 - 64)
    @column_max = Awards::Icon_QColumn
    self.z = 10000
    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
    @data = []
    $game_system.awards.each {|i|
      @data.push([Awards::Award[i], i])}
    if Awards::Show_All
      @data = []
      @locked = []
      @unlocked = []
      Awards::Award.each_index {|i|
        if Awards::Award[i] != nil
          if $game_system.awards.include?(i)
            @unlocked.push([Awards::Award[i], i])
          else
            @locked.push([Awards::Award[i], i])
          end
        end}
      @unlocked.each {|i| @data.push(i)}
      @locked.each {|i| @data.push(i)}
    end
    @item_max = @data.size
    if @item_max > 0
      self.contents = Bitmap.new(width - 32, row_max * Awards::Icon_Size[1])
      for i in 0...@item_max
        draw_item(i)
      end
    end
  end
  def draw_item(index)
    item = @data[index]
    width = Awards::Icon_Size[0] < 32 ? 32 : Awards::Icon_Size[0]
    height = Awards::Icon_Size[1] < 32 ? 32 : Awards::Icon_Size[1]
    x = 4 + index % @column_max * (width + 32)
    y = index / @column_max * (height + 4)
    rect = Rect.new(x, y, self.width / @column_max - 32, height)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    if $game_system.awards.include?(item[1])
      bitmap = RPG::Cache.icon(item[0][2])
    else
      bitmap = RPG::Cache.icon(Awards::Locked_Icon)
    end
    self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, Awards::Icon_Size[0],
        Awards::Icon_Size[1]))
  end
  def update_help
    @help_window.set_award(self.item)
  end
  def update_cursor_rect
    if @index < 0
      self.cursor_rect.empty
      return
    end
    row = @index / @column_max
    if row < self.top_row
      self.top_row = row
    end
    if row > self.top_row + (self.page_row_max - 1)
      self.top_row = row - (self.page_row_max - 1)
    end
    cursor_width = Awards::Icon_Size[0] < 32 ? 32 : Awards::Icon_Size[0]
    cursor_height = Awards::Icon_Size[1] < 32 ? 32 : Awards::Icon_Size[1]
    x = @index % @column_max * (cursor_width + 32)
    y = @index / @column_max * (Awards::Icon_Size[1] + 4) - self.oy
    self.cursor_rect.set(x, y, cursor_width, cursor_height + 4)
  end
end
#===============================================================================
# QScene_Awards
#===============================================================================
class QScene_Awards
  def initialize
    @awards = Window_QuickAwards.new
    @help = Window_QuickHelp.new
    @awards.help_window = @help
    loop do
      Graphics.update
      Input.update_old
      update
      if Input.trigger?(Input::B)
        $game_system.se_play($data_system.cancel_se)
        break
      end
    end
    @awards.dispose
    @help.dispose
  end
  def update
    @awards.update
    @help.update
  end
end
#===============================================================================
# Input
#===============================================================================
module Input
  class << self
    alias gg_init_quick_awards_lat update
  end
  def self.update_old
    gg_init_quick_awards_lat
  end
  def self.check_blocked
    Awards::Block_Scenes.each {|s|
      return true if $scene.is_a?(s)}
    return false
  end
  def self.update
    if Awards::Quick_Access != nil && Input.trigger?(Awards::Quick_Access) &&
          @scene == nil && !self.check_blocked
      $game_system.se_play($data_system.decision_se)
      @scene = QScene_Awards.new
      @scene = nil
    end
    gg_init_quick_awards_lat
  end
end

#===============================================================================
# Window_Award
#===============================================================================
class Window_Award < Window_Base
  def initialize
    super(0, 320, 640, 160)
    self.contents = Bitmap.new(width - 32, height - 32)
  end
  def set_award(award)
    @award = award
    refresh
  end
  def refresh
    self.contents.clear
    self.contents.draw_text(0, 0, 640 / 2, 32, @award[0][0])
    if Awards::Track_Score
      text = "#{@award[0][3]} #{Awards::Score_Text}"
      self.contents.draw_text(0, 0, 640 - 32, 32, text, 2)
      text = "Total #{Awards::Score_Text}: #{$game_variables[Awards::Variable_Id]}"
      self.contents.draw_text(0, 32, 640 - 32, 32, text, 2)
    end
    text = self.contents.slice_text(@award[0][1], 640 - 32)
    if @award[0][4] && !$game_system.awards.include?(@award[1])
      text = self.contents.slice_text(Awards::Hidden_Info, 640 - 32)
    end
    text.each_index {|i|
      self.contents.draw_text(0, 64 + i * 32, 640 - 32, 32, text[i])}
  end
end
#===============================================================================
# Window_Awards
#===============================================================================
class Window_Awards < Window_Selectable
  def initialize
    super(0, 0, 640, 320)
    @column_max = Awards::Icon_Column
    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
    @data = []
    $game_system.awards.each {|i|
      @data.push([Awards::Award[i], i])}
    if Awards::Show_All
      @data = []
      @locked = []
      @unlocked = []
      Awards::Award.each_index {|i|
        if Awards::Award[i] != nil
          if $game_system.awards.include?(i)
            @unlocked.push([Awards::Award[i], i])
          else
            @locked.push([Awards::Award[i], i])
          end
        end}
      @unlocked.each {|i| @data.push(i)}
      @locked.each {|i| @data.push(i)}
    end
    @item_max = @data.size
    if @item_max > 0
      height = Awards::Icon_Size[1] < 32 ? 32 : Awards::Icon_Size[1]
      self.contents = Bitmap.new(width - 32, row_max * height)
      for i in 0...@item_max
        draw_item(i)
      end
    end
  end
  def draw_item(index)
    item = @data[index]
    width = Awards::Icon_Size[0] < 32 ? 32 : Awards::Icon_Size[0]
    height = Awards::Icon_Size[1] < 32 ? 32 : Awards::Icon_Size[1]
    x = 4 + index % @column_max * (width + 32)
    y = index / @column_max * (height + 4)
    rect = Rect.new(x, y, self.width / @column_max - 32, Awards::Icon_Size[1])
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    if $game_system.awards.include?(item[1])
      bitmap = RPG::Cache.icon(item[0][2])
    else
      bitmap = RPG::Cache.icon(Awards::Locked_Icon)
    end
    self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, Awards::Icon_Size[0],
      Awards::Icon_Size[1]))
  end
  def update_help
    @help_window.set_award(self.item)
  end
  def update_cursor_rect
    if @index < 0
      self.cursor_rect.empty
      return
    end
    row = @index / @column_max
    if row < self.top_row
      self.top_row = row
    end
    if row > self.top_row + (self.page_row_max - 1)
      self.top_row = row - (self.page_row_max - 1)
    end
    cursor_width = Awards::Icon_Size[0] < 32 ? 32 : Awards::Icon_Size[0]
    cursor_height = Awards::Icon_Size[1] < 32 ? 32 : Awards::Icon_Size[1]
    x = @index % @column_max * (cursor_width + 32)
    y = @index / @column_max * (cursor_height + 4) - self.oy
    self.cursor_rect.set(x, y, cursor_width, cursor_height)
  end
end
#===============================================================================
# Scene_Achievements
#===============================================================================
class Scene_Achievements
  def main
    @help = Window_Award.new
    @awards = Window_Awards.new
    @awards.help_window = @help
    Graphics.transition
    loop do
      Graphics.update
      Input.update
      update
      if $scene != self
        break
      end
    end
    Graphics.freeze
    @help.dispose
    @awards.dispose
  end
  def update
    @awards.update
    @help.update
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      $scene = Awards::Return_Scene.new
      return
    end
  end
end

Snippets & Stuff

Damage Achievement Mod
This gives the player an achievement when an actor deals X amount of damage. Place below Achievements script. Allows for multiple achievements.
Spoiler for:
Code: [Select]
#===============================================================================
# X Damage Achievement Mod
# Author game_guy
#-------------------------------------------------------------------------------
# Info:
# Small snippet to give the player an achievement when one attack deals X
# damage. It only works with any attack except items..
#
# Instructions:
# Edit list of awards below.
#
# Place below the achievements script.
#===============================================================================
AWARDS = []
# Add new lines here
# Type in
# Awards[number] = [award_id, amount_of_damage]
AWARDS[0] = [3, 500]
AWARDS{1] = [15, 1000]
if $gg_achievements == nil || $gg_achievements < 2.0
  raise 'Damage Achievement Mod requires game_guy\'s Achievements v2.0 or higher'
end
class Game_Battler
  alias gg_init_damage_award_lat attack_effect
  def attack_effect(attacker)
    if attacker.is_a?(Game_Actor)
      old_hp = self.hp
      result = gg_init_damage_award_lat(attacker)
      if result
        damage = self.damage.is_a?(String) ? 0 : self.damage
        AWARDS.each {|i|
          if damage > i[1]
            Awards.gain(i[1])
          end}
      end
      return result
    else
      return gg_init_damage_award_lat(attacker)
    end
  end
  alias gg_init_damage_skill_award_lat skill_effect
  def skill_effect(user, skill)
    if user.is_a?(Game_Actor)
      old_hp = self.hp
      result = gg_init_damage_skill_award_lat(user, skill)
      if result
        damage = self.damage.is_a?(String) ? 0 : self.damage
        AWARDS.each {|i|
          if damage > i[1]
            Awards.gain(i[1])
          end}
      end
      return result
    else
      return gg_init_damage_skill_award_lat(user, skill)
    end
  end
end

Instructions

All in the script.

Compatibility

-Not tested with SDK.
-Should work with everything.
-May corrupt old save games.

Credits and Thanks


Author's Notes

Enjoy! Post any bugs if you find any!
Title: Re: [XP] Achievements Script
Post by: Railium on April 21, 2009, 10:08:58 PM
Looks pretty nice. I'll test it out.
Title: Re: [XP] Achievements Script
Post by: Crab Buster on April 28, 2009, 11:26:23 AM
Cool! I have often thought about an achievements script EXACTLY like this.
Gonna check it out later for sure!
Title: Re: [XP] Achievements Script
Post by: Rune on April 28, 2009, 04:36:43 PM
Very nice, Rune likes. I remember making something similar to this in the past, however I don't remember whether I released it or not. However yours looks a lot more user friendly and stuffz. Nice one, I might use this if I ever decide to make my own games again.
Title: Re: [XP] Achievements Script
Post by: game_guy on May 02, 2009, 01:14:27 AM
Thanks for the replies guys :D I really mean it. I start to worry when I get no comments but when I do I feel like scriping something again.
Title: Re: [XP] Achievements Script
Post by: Crab Buster on May 09, 2009, 09:59:28 PM
Just got round to trying this out and I think its great. But I have a question... Do you need the battle add-on script that is in the demo, in order for it to work?
Title: Re: [XP] Achievements Script
Post by: game_guy on May 10, 2009, 06:13:33 AM
No thats just to show an achievement setup test. Win 10 battles and you get an achievement. That isnt needed.
Title: Re: [XP] Achievements Script
Post by: leavitt420 on July 14, 2009, 02:09:52 AM
quick question about it though, because i may be doing something wrong.  is there a way to save the name of the achievement (item) when the player saves the game and loads again?  i was playtesting, and saw that the gamerpoints stayed, but the name of the achievement disappeared.
Title: Re: [XP] Achievements Script
Post by: leavitt420 on July 19, 2009, 08:21:57 PM
Actually, more of an update, I've found that there's the error:

Script 'Scene_Achievements' line 155: NoMethodError occured.
undefined method 'item_number' for nil:NilClass.

line 155 says, starts with:

      if $achieve.item_number(i) > 0
        @data.push($data_items)
      end

I consider myself proficient enough to fool around with some of the lines to see if i could fix it, but i don't know what the problem is.  the achievement works fine through the first gameplay, but when the game is saved, and reloaded after exit, the error occurs when i try to view the achievements.  any thoughts?
Title: Re: [XP] Achievements Script
Post by: game_guy on July 23, 2009, 08:27:50 PM
Fixed
Title: Re: [XP] Achievements Script
Post by: Mr_Wiggles on December 01, 2009, 09:00:48 AM
would it be possible to alert the player of an achivent with out disturbing game play?
like in a help window or somthing and edit the sound effects of an achivement
Title: Re: [XP] Achievements Script
Post by: game_guy on December 02, 2009, 02:22:10 AM
I'm updating this script so it draws text instead and I'm making it alot more compatible
Title: Re: [XP] Achievements Script
Post by: Canadyan on January 21, 2010, 06:15:45 PM
Any idea on how soon we could expect your new version of this script? I love the idea of this, but sadly, one my other scripts seems to be conflicting with it.
Title: Re: [XP] Achievements Script
Post by: game_guy on January 29, 2010, 11:51:58 PM
In about a week or two. I'll be busy for awhile.
Title: Re: [XP] Achievements Script
Post by: Rogey on April 10, 2010, 12:15:59 AM
Slight necrobump, but GG, you think you can integrate a rewards system into the achievements? For example, kill 100 snakes and you get a Snake Eater achievement(lol) and a weapon that deals critical damage to snake creatures.

Numbers are nice and all, but I think that also getting rewards based off your gameplay is more satisfying.
Title: Re: [XP] Achievements Script
Post by: Mr_Wiggles on April 10, 2010, 05:38:07 AM
uh, you can do that your self. you have to use this "   $achieve.gain_item(item_id)" to give the player the achievement. so when you give that achievement just give a prize with it.
Title: Re: [XP] Achievements Script
Post by: Rogey on April 10, 2010, 11:06:50 PM
uh, you can do that your self. you have to use this "   $achieve.gain_item(item_id)" to give the player the achievement. so when you give that achievement just give a prize with it.

Makes sense. Still waiting for GG for an update though.
Title: Re: [XP] Achievements Script
Post by: game_guy on April 13, 2010, 03:52:40 AM
Again, being lazy/script requests/no time.

Expect an update in the next month. At most I promise. (Hopefully)
I'm a very lazy scripter and I hate remaking scripts but if I have to I will. Just gimme some time. :D
Title: Re: [XP] Achievements Script
Post by: ?????? on April 17, 2010, 06:36:21 PM
IT'S LOOKING GOOD...  :D THIS SCRIPT IS... (HMM  ^-^)... GREAT AND COOL...  ;D
Title: Re: [XP] Achievements Script
Post by: Sonickid132 on April 25, 2010, 06:14:43 PM
heres an error i keep getting when i try to look at the achievements:

Script 'Achievements' line 155: NoMethodError occured
undefined method 'item_number' for nil:NilClass

Here are lines 153 to 158:

# Add item
    for i in 1...$data_items.size
      if $achieve.item_number(i) > 0
        @data.push($data_items)
      end
    end

This only happens when i load a saved game. it works fine when its a new game.
I tried changing it a litttle but i got the same error, im not sure what the problem is.  ??? 
is it possible to fix this?
Title: Re: [XP] Achievements Script
Post by: modern algebra on April 25, 2010, 06:19:39 PM
Press CTRL+H in the script editor.

Search for $achievements and replace with $achieve

It probably still won't work with games created before you did this fix, but it should let you save and load any new games you create after the fix.
Title: Re: [XP] Achievements Script
Post by: Sonickid132 on April 25, 2010, 07:16:00 PM
I did it but i still got the same error.
Just to be sure theres only one $achievements right?
Title: Re: [XP] Achievements Script
Post by: modern algebra on April 25, 2010, 08:16:56 PM
there should be at least 2
Title: Re: [XP] Achievements Script
Post by: recon2009 on May 19, 2010, 10:55:40 AM
Great script! but I have a quick question: In the achievements scene, can be shown a picture different from achievement to achievement instead of that black area? For example I have 2 achievements: the first because I helped an old lady to pick up some apples and the second where I found a great sword. Now, when I look at the achievements_scene, when I select the first achievement an image to appear in the right with an apple for example and when I select the second achievement, the picture with the apple disappears and another one appears but with a sword, and if I don't have any achievement, the black picture should be transparent... sorry about my bad English if it is...
Title: Re: [XP] Achievements Script
Post by: Silence on July 29, 2010, 05:37:52 PM
Actually, more of an update, I've found that there's the error:

Script 'Scene_Achievements' line 155: NoMethodError occured.
undefined method 'item_number' for nil:NilClass.

line 155 says, starts with:

      if $achieve.item_number(i) > 0
        @data.push($data_items)
      end

I consider myself proficient enough to fool around with some of the lines to see if i could fix it, but i don't know what the problem is.  the achievement works fine through the first gameplay, but when the game is saved, and reloaded after exit, the error occurs when i try to view the achievements.  any thoughts?

Your in the exact same position as me, It's completely fine through the first period of gameplay. but then once i saved, reloaded and trying to view/get achievements, It comes up with that exact message. I'v tried fooling around with it myself but to no success. I'v downloaded this recently so if you say it has been fixed then it hasnt. If you know the problem can you please tell me how to solve this? Thanks :)
Title: Re: [XP] Achievements Script
Post by: game_guy on July 30, 2010, 04:55:40 AM
Well the script is about 80% done. It'll fix everything <3
Title: Re: [XP] Achievements Script
Post by: Silence on September 08, 2010, 05:52:52 PM
Well the script is about 80% done. It'll fix everything <3

Hehe, hope you can cos i really want this script, its awesum sauce x) :blizj:
Title: Re: [XP] Achievements Script
Post by: Luminescence on March 08, 2011, 12:43:18 PM
This script still doesn't work. Line 156, same error as the person had before.

Anyone find a fix for it?
Title: Re: [XP] Achievements Script
Post by: crow5757 on April 17, 2011, 08:39:56 PM
Peeps, i have a problem with copying and pasting this script. When i select all it seems that when i paste it ALL goes on one line in the script. Any help?
Title: Re: [XP] Achievements Script
Post by: pacdiggity on April 18, 2011, 05:45:12 AM
You're using internet explorer, use chrome, firefox or safari (eww). IE doesn't copy it properly.
Title: Re: [XP] Achievements Script
Post by: game_guy on May 21, 2011, 01:24:35 AM
Finally decided to remake this. Yes, everyones been waiting. I've decided to implement some features and whatnot. If you have any lemme know.

Planned:
-Achievement Categories
-Use Background Image for Pop Up Achievements
-Change Color of Text
-Change Font of Text
-New Layout
-Better Compatibility
-Must Setup all Achievements in Script, No More Items
-In-Game Sorting Options

Its getting scripted as we speak.

You're using internet explorer, use chrome, firefox or safari (eww). IE doesn't copy it properly.

Or opera <3
Title: Re: [XP] Achievements Script
Post by: game_guy on May 22, 2011, 06:45:36 PM
Updates to 2.0. So much better then before. Please check it out and the new demo and everything. :) Love you guys <3
Title: Re: [XP] Achievements Script
Post by: pacdiggity on May 22, 2011, 08:37:32 PM
Oh my bowie, g_g that looks great!
I MUST NOW PURCHASE XP.
Title: Re: [XP] Achievements Script
Post by: Zero86Sk on June 24, 2011, 03:28:55 PM
Hi 1st of all, love your script, am planing to use it in an upcommng rpg (will ofcourse credit you)

I wanted to ask cause i had problems with this
i wanted to use 48x48 icons instead of 24x24

i managed to change the popup window
Code: [Select]
self.bitmap.blt(icon_off[0], icon_off[1], @icon, Rect.new(0, 0, 24, 24))
to
Code: [Select]
self.bitmap.blt(icon_off[0], icon_off[1], @icon, Rect.new(0, 0, 48, 48))

bare in mind im just figuring stuff about scripting.

By toying with your script i also now arranged the icon etc how i wanted it

but i can figure it out in the Awards window
the selectable text and icons are cut, and i messed with it to no awail
i dont know what section to edit

Window_QuickAwards or Window_Awards,
Selectabe etc

and i managed to put QuickAwards to my menu, dont know if Awards is different.

Could you explain a few thing for me.

Would be greatufll if you would help me set icons to 48x48. Thanks.
Title: Re: [XP] Achievements Script
Post by: game_guy on June 24, 2011, 04:00:19 PM
Try this, I made the modifications hopefully it works couldn't really test it. Just place this below my script.
Code: [Select]
class Window_Awards < Window_Selectable
  def initialize
    super(0, 0, 640, 320)
    @column_max = 5
    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
    @data = []
    $game_system.awards.each {|i|
      @data.push([Awards::Award[i], i])}
    if Awards::Show_All
      @data = []
      @locked = []
      @unlocked = []
      Awards::Award.each_index {|i|
        if Awards::Award[i] != nil
          if $game_system.awards.include?(i)
            @unlocked.push([Awards::Award[i], i])
          else
            @locked.push([Awards::Award[i], i])
          end
        end}
      @unlocked.each {|i| @data.push(i)}
      @locked.each {|i| @data.push(i)}
    end
    @item_max = @data.size
    if @item_max > 0
      self.contents = Bitmap.new(width - 32, row_max * 48)
      for i in 0...@item_max
        draw_item(i)
      end
    end
  end
  def draw_item(index)
    item = @data[index]
    x = 4 + index % @column_max * (128)
    y = index / @column_max * 48
    rect = Rect.new(x, y, self.width / @column_max - 32, 48)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    if $game_system.awards.include?(item[1])
      bitmap = RPG::Cache.icon(item[0][2])
    else
      bitmap = RPG::Cache.icon(Awards::Locked_Icon)
    end
    self.contents.blt(x, y, bitmap, Rect.new(0, 0, 48, 48))
  end
  def update_help
    @help_window.set_award(self.item)
  end
  def update_cursor_rect
    if @index < 0
      self.cursor_rect.empty
      return
    end
    row = @index / @column_max
    if row < self.top_row
      self.top_row = row
    end
    if row > self.top_row + (self.page_row_max - 1)
      self.top_row = row - (self.page_row_max - 1)
    end
    cursor_width = 48
    x = @index % @column_max * (128)
    y = @index / @column_max * 48 - self.oy
    self.cursor_rect.set(x, y, cursor_width, 48)
  end
end

It should work.
Title: Re: [XP] Achievements Script
Post by: Zero86Sk on June 24, 2011, 05:23:09 PM
Thanks but for some reason i cant get into the Awards menu
@Scene = QScene_Awards.new
works but i dont know what to use for the other one
Title: Re: [XP] Achievements Script
Post by: Zero86Sk on June 24, 2011, 07:47:42 PM
EDIT: Yeah i got it o how i want it to look but the damn thing wont scroll
it just stays there
is there a parameter i could use for it to scroll (if you have more than 48 achievements)

and the 2nd problem is the images wont appear fully if i have less achievements

from what i figured out after hours of playing with it
I am actually learning the scripting code thanks to this btw.

Here is the edited code:

Code: [Select]
#===============================================================================
# Window_QuickAwards
#===============================================================================
class Window_QuickAwards < Window_Selectable
  def initialize
#    super(64, 128 + 64, 512, 320 - 64)
    super(64, 192, 512, 273)
    @column_max = 9
    self.z = 500
    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
    @data = []
    $game_system.awards.each {|i|
      @data.push([Awards::Award[i], i])}
    if Awards::Show_All
      @data = []
      @locked = []
      @unlocked = []
      Awards::Award.each_index {|i|
        if Awards::Award[i] != nil
          if $game_system.awards.include?(i)
            @unlocked.push([Awards::Award[i], i])
          else
            @locked.push([Awards::Award[i], i])
          end
        end}
      @unlocked.each {|i| @data.push(i)}
      @locked.each {|i| @data.push(i)}
    end
    @item_max = @data.size
    if @item_max > 0
      self.contents = Bitmap.new(width - 48, row_max * 96)
      for i in 0...@item_max
        draw_item(i)
      end
    end
  end
  def draw_item(index)
    item = @data[index]
    x = 2 + index % @column_max * (52)
    y = index / @column_max * 52
    rect = Rect.new(x, y, self.width / @column_max - 32, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    if $game_system.awards.include?(item[1])
      bitmap = RPG::Cache.icon(item[0][2])
    else
      bitmap = RPG::Cache.icon(Awards::Locked_Icon)
    end
    self.contents.blt(x, y + 2, bitmap, Rect.new(0, 0, 48, 48))
  end
  def update_help
    @help_window.set_award(self.item)
  end
  def update_cursor_rect
    if @index < 0
      self.cursor_rect.empty
      return
    end
    row = @index / @column_max
    if row < self.top_row
      self.top_row = row
    end
    if row > self.top_row + (self.page_row_max - 1)
      self.top_row = row - (self.page_row_max - 1)
    end
    cursor_width = 52
    x = @index % @column_max * (cursor_width + 0)
    y = @index / @column_max * 52 - self.oy
    self.cursor_rect.set(x, y, cursor_width, 52)
  end
end

also these appear to do nothing pretty much

    rect = Rect.new(x, y, self.width / @column_max - 32, 32)
    self.contents = Bitmap.new(width - 48, row_max * 96) (row_max has something to do with if its below a certain number the pictures dont appear

but awesome script

i use QScene_Awards as i mention so this is the part that changes for me

heres a pic to better understand what i mean
(https://rmrk.net/proxy.php?request=http%3A%2F%2Fimg269.imageshack.us%2Fimg269%2F8022%2Frpgachievwontscroll.png&hash=35bd4a3ed98814d0f59a28b6f7a08bf654b2a458)
Title: Re: [XP] Achievements Script
Post by: game_guy on June 24, 2011, 11:03:07 PM
Oh sorry, use $scene = Scene_Achievements.new for the other one. Look what I did with the Window_Awards. The only difference between QuickAwards and Awards window is the size.
Title: Re: [XP] Achievements Script
Post by: Zero86Sk on June 24, 2011, 11:27:32 PM
Yeah that works, but i still cant scroll if i have too manny achievements, it jsut dosnt scroll and overlaps the select screen
Title: Re: [XP] Achievements Script
Post by: game_guy on June 24, 2011, 11:35:05 PM
I'll go in and edit the quick awards myself so it'll work. And again use
Code: [Select]
$scene = Scene_Achievements.new
to get to the main scene. The quick awards scene isn't mean to be accessed through a script.
Title: Re: [XP] Achievements Script
Post by: Zero86Sk on June 25, 2011, 08:09:21 PM
I got it to work nicely woth
$scene = Scene_Achievements.new

but it still wont scroll down if you have more achievements (about 70

am trying to pinpoint why it dosnt work

it starts scrolling after a certain size (over 100 achievements)
but rest are still hidden down you cant see them

my scripting knowlage is limited cause i got RPG Maker XP a week ago
but if i could improve and help with the script like fix bugs like this than id be happy too

Used the code you sent me (thanks) and than could figure out the measures (not fully but most)
this is how it looks after i changed it

Code: [Select]
#===============================================================================
# Window_Awards
#===============================================================================
class Window_Awards < Window_Selectable
  def initialize
    super(0, 0, 640, 320)
    @column_max = 11
    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
    @data = []
    $game_system.awards.each {|i|
      @data.push([Awards::Award[i], i])}
    if Awards::Show_All
      @data = []
      @locked = []
      @unlocked = []
      Awards::Award.each_index {|i|
        if Awards::Award[i] != nil
          if $game_system.awards.include?(i)
            @unlocked.push([Awards::Award[i], i])
          else
            @locked.push([Awards::Award[i], i])
          end
        end}
      @unlocked.each {|i| @data.push(i)}
      @locked.each {|i| @data.push(i)}
    end
    @item_max = @data.size
    if @item_max > 0
      self.contents = Bitmap.new(width - 48, row_max * 64)
      for i in 0...@item_max
        draw_item(i)
      end
    end
  end
  def draw_item(index)
    item = @data[index]
    x = 2 + index % @column_max * (52)
    y = index / @column_max * 52
    rect = Rect.new(x, y, self.width / @column_max - 32, 48)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    if $game_system.awards.include?(item[1])
      bitmap = RPG::Cache.icon(item[0][2])
    else
      bitmap = RPG::Cache.icon(Awards::Locked_Icon)
    end
    self.contents.blt(x, y + 2, bitmap, Rect.new(0, 0, 48, 48))
  end
  def update_help
    @help_window.set_award(self.item)
  end
  def update_cursor_rect
    if @index < 0
      self.cursor_rect.empty
      return
    end
    row = @index / @column_max
    if row < self.top_row
      self.top_row = row
    end
    if row > self.top_row + (self.page_row_max - 1)
      self.top_row = row - (self.page_row_max - 1)
    end
    cursor_width = 52
    x = @index % @column_max * (cursor_width + 0)
    y = @index / @column_max * 52 - self.oy
    self.cursor_rect.set(x, y, cursor_width, 52)
  end
end

this way 54 achievements are visible one 1 screen but it wont scroll down if you have 63 and more
it just moves the cursor down
Title: Re: [XP] Achievements Script
Post by: game_guy on June 25, 2011, 08:34:25 PM
Gimme a day or two and I'll fidget with it. In fact I might just update the script to allow any size icon.
Title: Re: [XP] Achievements Script
Post by: game_guy on July 05, 2011, 02:10:49 PM
Updated to 2.2. Added custom icon size support.
Title: Re: [XP] Achievements Script
Post by: Zero86Sk on July 06, 2011, 08:54:14 PM
Hi thats cool
tried it out
when i go access the menu i get

uninitialized contend Awards::Icon_Row
and
uninitialized contend Awards::Icon_QuickRow

I took the script and just changed the icon size and values for rows as you described
dosnt work for me even if unedited

the popup works but i just cant access the emnu
Title: Re: [XP] Achievements Script
Post by: game_guy on July 08, 2011, 07:13:09 AM
Fixed. :D
Title: Re: [XP] Achievements Script
Post by: game_guy on July 09, 2011, 12:51:23 AM
Updated to 2.22. Fixed syntax error.
Title: Re: [XP] Achievements Script
Post by: Mr_Wiggles on September 02, 2011, 01:35:43 AM
Really enjoy the new lay out and flow, been using this for my game, also i made a slight mod to it that allows for the achievements to be saved out side of the standard save files so no matter what save file you use or new game you work towards the complete achievement list.

I just think this is a nifty feature if your looking for some suggestions on new features you can add this.
Title: Re: [XP] Achievements Script
Post by: game_guy on September 03, 2011, 04:42:53 AM
Its possible. I'll add it as an optional feature later on.
Title: Re: [XP] Achievements Script
Post by: Mr_Wiggles on October 10, 2011, 10:44:02 PM
late response: Cool, that way it will be like a gamer profile.
Title: Re: [XP] Achievements Script
Post by: lekiller on February 04, 2012, 01:49:33 PM
BUMP
This script is extremely useful. I'm using it for memos... Yeah, you heard right, memos... Like in game Resident Evil III, where you collect files (books, pictures, etc...). There is only one thing missing...

When I select one achievement, I want when I press f.e. ENTER new window appears with my user defined text (and pictures) and I can scroll through this big window (left and right, like page listing)...

It would be great.

Sorry for my awful english :D
Title: Re: [XP] Achievements Script
Post by: game_guy on February 22, 2012, 04:42:25 AM
That would be an entirely new script and its not something I'm going to be incorporating into this script, sorry.