Submit Your Article


 
RPG Maker

Welcome Guest ( Log In | Register )


  Games Resources RPG Maker VX RPG Maker XP Scripts Tutorials Downloads

 
Closed TopicStart new topic
> Munkis' Achievements
munkis
post Feb 9 2012, 03:41 PM
Post #1


Woah, dude...
Group Icon

Group: Revolutionary
Posts: 197
Type: Writer
RM Skill: Intermediate




Munkis' Achievements

Version: 1.0
Author: munkis
Release Date: 02/09/2012


Exclusive Script at RPG RPG Revolution


Introduction
This is my first big script in awhile, so here goes. While I liked the OmegaX achievement tracker for being user-friendly, I didn't like the style it was presented in myself, so I made my own. Still as user-friendly, but with a cleaner interface.

Features
Easily create and manage your own achievements, and choose which ones (if any) you want to be secret.

Script
Munkis' Achievements
CODE
#-------------------------------------------------------------------------------
#  * Munkis' Achievements
#  * V 1.0
#  * Made by munkis
#    ╔══════════╗
#    ║ FEATURES ║
#    ╚══════════╝
#  * Well, it's been awhile since I scratch-coded a script, so I hope you like
#    this one.  It's a simple-to-use achievement tracker.  Configuration is
#    simple and somewhat extensive, and it also has the added bonus of allowing
#    for "secret" achievements that the player won't see until he or she gets
#    them.
#  * 95% Plug&Play; requires the use of modern_algebra's Paragraph Formatter,
#    which can be found on RMRK.net
#    ╔══════════════╗
#    ║ SCRIPT CALLS ║
#    ╚══════════════╝
#  * $scene = Munkis_Achievements.new -- Opens the Achievements screen
#  * $scene.unlock_achievement(n) -- Unlocks the achievement with index (n)
#    So to reveal the eighth achievement, you would use $scene.unlock_achievement(7)
#
#  * Special thanks to Jens of Zanicuud for all his help.
#  * V 1.0: Initial release
#-------------------------------------------------------------------------------

module MNK_Achievements

  WINDOWS = []
  TITLE = []
  BODY = []
  COMPLETED_SWITCH = []
  IS_SECRET = []
#------------------------------------------------------------------------------
#  * START Config
#------------------------------------------------------------------------------
#  * START Window Config
#------------------------------------------------------------------------------
#  * This is the window config area.  Here's a list of what everything does:
#
# 1: Achievements title text
# 2: Icon used in the Title bar (use zero for none)
# 3: Opacity of all windows
# 4: Pop-up window message
# 5: Pop-up window x
# 6: Pop-up window y
# 7: Pop-up window width
# 8: Pop-up window height
# 9: Pop-up window display time
# 10: Pop-up window pic (use "" for none)  NOTE: Putting a pic name here will
#     override 4 through 8, and the opacity of the pop-up window.  Also,
#     changing the values of 5 and 6 with a pic present will move it around in
#     the window, rather than moving the entire window.
# 11: Pop-up window SE
# 12: Secret achievement menu text
# 13: Secret achievement description text
#------------------------------------------------------------------------------
  WINDOWS[0] = "ACHIEVEMENTS"
  WINDOWS[1] = 123
  WINDOWS[2] = 255
  WINDOWS[3] = "Achievement Unlocked!"
  WINDOWS[4] = 0
  WINDOWS[5] = 0
  WINDOWS[6] = Graphics.width
  WINDOWS[7] = 55
  WINDOWS[8] = 240
  WINDOWS[9] = ""
  WINDOWS[10] = "Open1"
  WINDOWS[11] = "Secret Achievement"
  WINDOWS[12] = "This is a secret achievement.  Unlock it to learn more."
#------------------------------------------------------------------------------
#  * END Window Config
#------------------------------------------------------------------------------
#  * START Achievement Config
#------------------------------------------------------------------------------
#  * This is the quest config area.  Here's a list of what everything does:
#
# 1: Achievement title (appears in the menu if IS_SECRET[n] == false)
# 2: Achievement description (appears in the large window if IS_SECRET[n] == false)
# 3: Achievement complete switch (in-game switch ID)
# 4: Secret achievement toggle (set this to TRUE to hide the information until
#    the player unlocks the achievement)
#  * While these four elements are actually part of four seperate arrays, I
#    have them organized this way for easier editing/adding of achievements.
#    Just remember to change the index numbers in the braces.
#------------------------------------------------------------------------------
  TITLE[0] = "The Creed is Greed"
  BODY[0] = "Obtain 500 gold."
  COMPLETED_SWITCH[0] = 1
  IS_SECRET[0] = false
#------------------------------------------------------------------------------
  TITLE[1] = "Private Eye"
  BODY[1] = "Unlock a secret achievement."
  COMPLETED_SWITCH[1] = 2
  IS_SECRET[1] = true
#------------------------------------------------------------------------------
  TITLE[2] = "The Librarian"
  BODY[2] = "Find the missing book."
  COMPLETED_SWITCH[2] = 3
  IS_SECRET[2] = false
#------------------------------------------------------------------------------
#  * END Achievement Config
#------------------------------------------------------------------------------
#  * END Config
#------------------------------------------------------------------------------
  if WINDOWS[9] != ""
    WIN_X = 0
    WIN_Y = 0
    WIDTH = Graphics.width
    HEIGHT = Graphics.height
    WIN_O = 0
  else
    WIN_X = WINDOWS[4]
    WIN_Y = WINDOWS[5]
    WIDTH = WINDOWS[6]
    HEIGHT = WINDOWS[7]
    WIN_O = WINDOWS[2]
  end
end
#------------------------------------------------------------------------------
#  * This replaces the title of achievements that are secret.
#------------------------------------------------------------------------------
class Window_Command < Window_Selectable
  def draw_item(index, enabled = true)
    rect = item_rect(index)
    rect.x += 4
    rect.width -= 8
    self.contents.clear_rect(rect)
    self.contents.font.color = normal_color
    self.contents.font.color.alpha = enabled ? 255 : 128
    if $scene.is_a?(Munkis_Achievements)
      self.contents.font.size = 15
      if MNK_Achievements::IS_SECRET[index] == true and $game_switches[MNK_Achievements::COMPLETED_SWITCH[index]] == false
       self.contents.draw_paragraph(rect.x,rect.y+2,Graphics.width-228,Graphics.height-55, MNK_Achievements::WINDOWS[11])
      else
       self.contents.draw_paragraph(rect.x,rect.y+2,Graphics.width-228,Graphics.height-55, @commands[index])
      end
    else
      self.contents.font.size = 20
      self.contents.draw_text(rect, @commands[index])
    end
  end
end
#------------------------------------------------------------------------------
#  * This draws the Title bar.
#------------------------------------------------------------------------------
class Window_Achievements_Title_Bar < Window_Base
  def initialize
    super(0, 0, Graphics.width, WLH + 32)
    self.opacity = MNK_Achievements::WINDOWS[2]
    x = 0
    if MNK_Achievements::WINDOWS[1] != 0
      draw_icon (MNK_Achievements::WINDOWS[1], x, 0)
      x += Graphics.width-55
      draw_icon (MNK_Achievements::WINDOWS[1], x, 0)
      x = 24
    end
    contents.draw_text(0, 0, contents.width, WLH, MNK_Achievements::WINDOWS[0], 1)
  end
end
#------------------------------------------------------------------------------
#  * This draws the Status bar.
#------------------------------------------------------------------------------
class Window_Achievements_Status_Bar < Window_Base
  def initialize
    super(195, 55, Graphics.width-195, 55)
    self.opacity = MNK_Achievements::WINDOWS[2]
  end
  def refresh(window_contents)
    self.contents.clear
    self.contents.draw_text (0, 0, Graphics.width-195, WLH, "Status:")
    if $game_switches[MNK_Achievements::COMPLETED_SWITCH[window_contents]] == false
      self.contents.font.color = knockout_color
      self.contents.draw_text (64, 1, Graphics.width-195, WLH, "LOCKED")
      self.contents.font.color = normal_color
    else
      self.contents.font.color = power_up_color
      self.contents.draw_text (64, 1, Graphics.width-195, WLH, "UNLOCKED")
      self.contents.font.color = normal_color
    end
  end
end
#------------------------------------------------------------------------------
#  * This draws the Description window.
#------------------------------------------------------------------------------
class Window_Achievements_Description < Window_Base
  def initialize
    super(195, 109, Graphics.width-195, Graphics.height-109)
    self.opacity = MNK_Achievements::WINDOWS[2]
  end
  def refresh(window_contents)
    self.contents.clear
    if MNK_Achievements::IS_SECRET[window_contents] == false or $game_switches[MNK_Achievements::COMPLETED_SWITCH[window_contents]] == true
      self.contents.draw_paragraph (0, 0, Graphics.width-228, Graphics.height-110, MNK_Achievements::BODY[window_contents])
    else
      self.contents.draw_paragraph (0, 0, Graphics.width-228, Graphics.height-110, MNK_Achievements::WINDOWS[12])
    end
  end
end
#------------------------------------------------------------------------------
#  * This draws the Achievements list window.
#------------------------------------------------------------------------------
class Munkis_Achievements < Scene_Base
  def start
    create_menu_background
    create_command_window
    @titlebar = Window_Achievements_Title_Bar.new
    @statusbar = Window_Achievements_Status_Bar.new()
    @describe = Window_Achievements_Description.new()
  end
  #----------------------------------------------------------------------------
  # * Post-Start Processing
  #----------------------------------------------------------------------------
  def post_start
    super
    open_command_window
  end
  #----------------------------------------------------------------------------
  # * Pre-termination Processing
  #----------------------------------------------------------------------------
  def pre_terminate
    super
    close_command_window
  end
  def terminate
    @titlebar.dispose
    @statusbar.dispose
    @describe.dispose
  end
  #----------------------------------------------------------------------------
  # * Return to Original Screen
  #----------------------------------------------------------------------------
  def return_scene
    $scene = Scene_Map.new
  end
  #----------------------------------------------------------------------------
  # * Frame Update
  #----------------------------------------------------------------------------
  def update
    super
    update_menu_background
    @command_window.update
    if @window_contents != @command_window.index
      @window_contents = @command_window.index
    end
    @statusbar.refresh(@window_contents)
    @describe.refresh(@window_contents)
    if Input.trigger?(Input::B)
      Sound.play_cancel
      return_scene
    end
  end
  #----------------------------------------------------------------------------
  # * Update Background for Menu Screen
  #----------------------------------------------------------------------------
  def update_menu_background
    super
    @menuback_sprite.tone.set(0, 0, 0, 128)
  end
  #----------------------------------------------------------------------------
  # * Create Command Window
  #----------------------------------------------------------------------------
  def create_command_window
    @command_window = Window_Command.new(196, MNK_Achievements::TITLE)
    @command_window.x = 0
    @command_window.y = 55
    @command_window.opacity = MNK_Achievements::WINDOWS[2]
    @command_window.openness = 0
    @command_window.height = Graphics.height-55
  end
  #----------------------------------------------------------------------------
  # * Dispose of Choice Window
  #----------------------------------------------------------------------------
  def dispose_command_window
    @command_window.dispose
  end
  #----------------------------------------------------------------------------
  # * Open Choice Window
  #----------------------------------------------------------------------------
  def open_command_window
    @command_window.open
    begin
      @command_window.update
      Graphics.update
    end until @command_window.openness == 255
  end
  #----------------------------------------------------------------------------
  # * Close Choice Window
  #----------------------------------------------------------------------------
  def close_command_window
    @command_window.close
    begin
      @command_window.update
      Graphics.update
    end until @command_window.openness == 0
  end
end
#------------------------------------------------------------------------------
#  * This notifies the player when they've unlocked an achievement.
#------------------------------------------------------------------------------
class Notify_Achievement < Window_Base
  def initialize
    super(MNK_Achievements::WIN_X,MNK_Achievements::WIN_Y,MNK_Achievements::WIDTH,MNK_Achievements::HEIGHT)
    self.visible = false
    @display_time = 0
    self.opacity = MNK_Achievements::WIN_O
  end
  def show_message(display_time = MNK_Achievements::WINDOWS[8])
    @display_time = display_time
    self.visible = true
    Audio.se_play("audio/se/"+MNK_Achievements::WINDOWS[10],100,100)
    create_contents
    refresh
  end
  def refresh
    self.contents.clear
    x = 0
    if MNK_Achievements::WINDOWS[1] != 0 and MNK_Achievements::WINDOWS[9] == ""
      draw_icon (MNK_Achievements::WINDOWS[1], x, 0)
      x += Graphics.width-55
      draw_icon (MNK_Achievements::WINDOWS[1], x, 0)
      x = 24
    end
    if MNK_Achievements::WINDOWS[9] == ""
      if @icon == 0
        self.contents.draw_text(x-15, 0, Graphics.width, WLH, MNK_Achievements::WINDOWS[3], 1)
      else
        self.contents.draw_text(x-39, 0, Graphics.width, WLH, MNK_Achievements::WINDOWS[3], 1)
      end
    else
      bitmap = Cache.picture(MNK_Achievements::WINDOWS[9])
      rect = Rect.new(MNK_Achievements::WINDOWS[4], MNK_Achievements::WINDOWS[5], Graphics.width, Graphics.height)
      self.contents.blt(x, y, bitmap, rect)
      bitmap.dispose
    end
    return
  end
  def update
    return unless self.visible
    @display_time -= 1
    self.visible = (@display_time > 0)
  end
end
class Scene_Map < Scene_Base
  alias munkis_achievement_start start
  alias munkis_achievement_update update
  alias munkis_achievement_terminate terminate
  def start
    munkis_achievement_start
    @notify = Notify_Achievement.new
  end
  def unlock_achievement(index)
    @notify.show_message(MNK_Achievements::WINDOWS[8])
    $game_switches[MNK_Achievements::COMPLETED_SWITCH[index]] = true
  end
  def update
    munkis_achievement_update
    @notify.update
  end
  def terminate
    munkis_achievement_terminate
    @notify.dispose
    return
  end
end


Compatibility patch for Munkis' Picture-based Window Cursor
CODE
class Window_Command < Window_Selectable
  def draw_item(index, enabled = true)
    rect = item_rect(index)
    rect.x += 4
    rect.width -= 8
    self.contents.clear_rect(rect)
    self.contents.font.color = normal_color
    self.contents.font.color.alpha = enabled ? 255 : 128
    if $scene.is_a?(Munkis_Achievements)
      self.contents.font.size = 15
      if MNK_Achievements::IS_SECRET[index] == true and $game_switches[MNK_Achievements::COMPLETED_SWITCH[index]] == false
       self.contents.draw_paragraph(rect.x,rect.y+2,Graphics.width-228,Graphics.height-55, MNK_Achievements::WINDOWS[11])
      else
       self.contents.draw_paragraph(rect.x,rect.y+2,Graphics.width-228,Graphics.height-55, @commands[index])
      end
    elsif $scene.is_a?(Scene_Menu) or $scene.is_a?(Scene_End) or $scene.is_a?(Scene_Title)
      self.contents.draw_text(rect, @commands[index],1)
    else
      self.contents.draw_text(rect, @commands[index])
    end
  end
end


Customization
Apart from easily adding your own achievements, you can also change what the pop up looks like, either with text/icons or a picture. the window can also be moved/resized, unless you have a picture in it, in which case the pic will move around in the window (as explained in the script header).

Compatibility
No known issues.

Screenshot


DEMO
It should be easy to figure out, but I can throw a quick demo together if a lot of people ask for it.

Installation
Place in MATERIALS, above MAIN.

FAQ
Q: ZOMG teh scriptz doesn't werk!!!
A: First of all, be more specific. Second, all reports typed in chat-speak or 1337-speak will be ignored.

Terms and Conditions
I don't mind this script being posted or linked on other sites AS LONG AS YOU GIVE CREDIT!!! Same goes for using this in your project. Contact me if you want to use this in a commercial project.

Credits
Credit goes to me for the script.

This post has been edited by munkis: Feb 16 2012, 04:54 PM


__________________________
Go to the top of the page
 
+Quote Post
   
munkis
post Feb 12 2012, 06:07 AM
Post #2


Woah, dude...
Group Icon

Group: Revolutionary
Posts: 197
Type: Writer
RM Skill: Intermediate




NOTE: The second script call CAN ONLY BE USED IN AN EVENT.


__________________________
Go to the top of the page
 
+Quote Post
   
Pera
post Feb 13 2012, 01:47 PM
Post #3


Level 2
Group Icon

Group: Member
Posts: 28
Type: Event Designer
RM Skill: Undisclosed




Nice script. Definitively using this in my game. happy.gif


__________________________
Crede quod habes, et habes
-Believe that you have it, and you do.
Go to the top of the page
 
+Quote Post
   
munkis
post Feb 16 2012, 04:55 PM
Post #4


Woah, dude...
Group Icon

Group: Revolutionary
Posts: 197
Type: Writer
RM Skill: Intermediate




Uploaded a compatibility patch for my picture-based window cursor script. They wouldn't clash, but they would override each other's settings. They need to be in this order:

Achievements
Cursor
Patch

EDIT: All three scripts also should be placed be BELOW all other custom scripts to ensure compatibility.

This post has been edited by munkis: Feb 24 2012, 11:22 AM


__________________________
Go to the top of the page
 
+Quote Post
   

Closed TopicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 17th May 2013 - 11:17 PM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker