sorry, BB code isn't allowed.
#===============================================================================
# Achievements Script
#===============================================================================
# Created By: Game_guy
# Date: April 19th, 2009
#===============================================================================
=begin
This is an achievements script. This is pretty much a system like off the
Xbox360. This is really easy to use its pretty much a simple plug and play!
You don't need to set anything up in the script at all!
Q: If I dont need to setup achievemnts in the script, where do I set them up?
A: Simple! Its all in teh database. With this script the achievements are
items. You make an Item in the database with an Achievement Name and
Description.
Q: That sounds easy! But how do I turn on/give achievemnts?
A: Easy! use this in a script call and enter this in
$achieve.gain_item(item_id)
Q: So how do I view achievements?
A: $scene = Scene_Achievements.new
Q: How do we setup the achievements score?
A: Set the price in the item. That is the score.
=end
module GameGuy
Print = true # Message box comes up and says the achievement you unlocked
ScoreName = "Points: " # The word you want the score to be called.
ScoreVariable = 1 # The variable that the score stays in.
ItemStorageUsed = false # set it true if you use my item storage script
end
class Window_Score < Window_Base
def initialize
super(0, 0, 320, 96)
self.contents = Bitmap.new(width - 32, height - 32)
refresh
end
def refresh
self.contents.clear
self.contents.font.color = system_color
self.contents.draw_text(4, 0, 120, 32, GameGuy::ScoreName.to_s)
self.contents.font.color = normal_color
self.contents.draw_text(4, 32, 120, 32, $game_variables[GameGuy::ScoreVariable].to_s)
end
end
class Achievements
def initialize
@items = {}
@weapons = {}
@armors = {}
end
def item_number(item_id)
return @items.include?(item_id) ? @items[item_id] : 0
end
def weapon_number(weapon_id)
return @weapons.include?(weapon_id) ? @weapons[weapon_id] : 0
end
def armor_number(armor_id)
return @armors.include?(armor_id) ? @armors[armor_id] : 0
end
def gain_item(item_id)
if item_id > 0
@items[item_id] = [[item_number(item_id) + 1, 0].max, 99].min
print $data_items[item_id].name + " Achieved!" if GameGuy::Print == true
$game_variables[GameGuy::ScoreVariable] += $data_items[item_id].price
end
end
def gain_weapon(weapon_id)
if weapon_id > 0
@weapons[weapon_id] = [[weapon_number(weapon_id) + 1, 0].max, 99].min
end
end
def gain_armor(armor_id)
if armor_id > 0
@armors[armor_id] = [[armor_number(armor_id) + 1, 0].max, 99].min
end
end
def lose_item(item_id, n)
gain_item(item_id, -n)
end
def lose_weapon(weapon_id, n)
gain_weapon(weapon_id, -n)
end
def lose_armor(armor_id, n)
gain_armor(armor_id, -n)
end
def item_can_use?(item_id)
# If item quantity is 0
if item_number(item_id) == 0
# Unusable
return false
end
# Get usable time
occasion = $data_items[item_id].occasion
# If in battle
if $game_temp.in_battle
# If useable time is 0 (normal) or 1 (only battle) it's usable
return (occasion == 0 or occasion == 1)
end
# If useable time is 0 (normal) or 2 (only menu) it's usable
return (occasion == 0 or occasion == 2)
end
end
class Scene_Title
alias re_new_game command_new_game
def command_new_game
$achieve = Achievements.new
re_new_game
end
end
class Window_Achievements < Window_Selectable
def initialize
super(0, 64, 320, 416)
@column_max = 1
refresh
self.index = 0
# If in battle, move window to center of screen
# and make it semi-transparent
if $game_temp.in_battle
self.y = 64
self.height = 256
self.back_opacity = 160
end
end
def item
return @data[self.index]
end
def refresh
if self.contents != nil
self.contents.dispose
self.contents = nil
end
@data = []
# Add item
for i in 1...$data_items.size
if $achieve.item_number(i) > 0
@data.push($data_items)
end
end
# Also add weapons and items if outside of battle
unless $game_temp.in_battle
for i in 1...$data_weapons.size
if $achieve.weapon_number(i) > 0
@data.push($data_weapons)
end
end
for i in 1...$data_armors.size
if $achieve.armor_number(i) > 0
@data.push($data_armors)
end
end
end
# If item count is not 0, make a bit map and draw all items
@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]
case item
when RPG::Item
number = $achieve.item_number(item.id)
when RPG::Weapon
number = $achieve.weapon_number(item.id)
when RPG::Armor
number = $achieve.armor_number(item.id)
end
if item.is_a?(RPG::Item)
self.contents.font.color = normal_color
end
x = 4 + index % @column_max * (288 + 32)
y = index / @column_max * 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
class Scene_Achievements
def main
@help_window = Window_Help.new
@achieve_window = Window_Achievements.new
@achieve_window.help_window = @help_window
@score_window = Window_Score.new
@score_window.x = 320
@score_window.y = 384
Graphics.transition
loop do
Graphics.update
Input.update
update
if $scene != self
break
end
end
Graphics.freeze
@help_window.dispose
@achieve_window.dispose
@score_window.dispose
end
def update
@help_window.update
@achieve_window.update
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
$scene = Scene_Menu.new(0)
return
end
end
end
class Scene_Save < Scene_File
def write_save_data(file)
# Make character data for drawing save file
characters = []
for i in 0...$game_party.actors.size
actor = $game_party.actors
characters.push([actor.character_name, actor.character_hue])
end
# Write character data for drawing save file
Marshal.dump(characters, file)
# Wrire frame count for measuring play time
Marshal.dump(Graphics.frame_count, file)
# Increase save count by 1
$game_system.save_count += 1
# Save magic number
# (A random value will be written each time saving with editor)
$game_system.magic_number = $data_system.magic_number
# Write each type of game object
Marshal.dump($game_system, file)
Marshal.dump($game_switches, file)
Marshal.dump($game_variables, file)
Marshal.dump($game_self_switches, file)
Marshal.dump($game_screen, file)
Marshal.dump($game_actors, file)
Marshal.dump($game_party, file)
Marshal.dump($game_troop, file)
Marshal.dump($game_map, file)
Marshal.dump($game_player, file)
Marshal.dump($achievements, file)
Marshal.dump($game_chest, file) if GameGuy::ItemStorageUsed
end
end
class Scene_Load < Scene_File
def read_save_data(file)
# Read character data for drawing save file
characters = Marshal.load(file)
# Read frame count for measuring play time
Graphics.frame_count = Marshal.load(file)
# Read each type of game object
$game_system = Marshal.load(file)
$game_switches = Marshal.load(file)
$game_variables = Marshal.load(file)
$game_self_switches = Marshal.load(file)
$game_screen = Marshal.load(file)
$game_actors = Marshal.load(file)
$game_party = Marshal.load(file)
$game_troop = Marshal.load(file)
$game_map = Marshal.load(file)
$game_player = Marshal.load(file)
$achievements = Marshal.load(file)
$game_chest = Marshal.load(file) if GameGuy::ItemStorageUsed
# If magic number is different from when saving
# (if editing was added with editor)
if $game_system.magic_number != $data_system.magic_number
# Load map
$game_map.setup($game_map.map_id)
$game_player.center($game_player.x, $game_player.y)
end
# Refresh party members
$game_party.refresh
end
end