[XP] Achievements Script

Started by G_G, April 20, 2009, 01:18:40 am

Previous topic - Next topic

G_G

Thanks for the help Thallion. :) And glad things worked out exile! Once you're done with your version Thallion, I'd be more than happy to add you to the credits and add it to the first post.

ThallionDarkshine

January 12, 2013, 08:11:00 pm #121 Last Edit: January 13, 2013, 09:30:49 am by ThallionDarkshine
Alright, done. Here is the modified script:
Script
And you will need this script and this dll for the script to work. The disappearance animations are not fully documented yet, but I'll get to that soon.

Edit - Added a little more functionality, as well as fixed a few errors in my Transitions module. Also properly documented the disappearance animations.

Edit2 - Fixed the Damage Achievement Mod, and also added a new mod for gold spent. Also added another mod for items in inventory. Here they are:
Spoiler: ShowHide

#===============================================================================
# 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. Added code to allow total
# damage dealt to trigger achievements.
#
# Instructions:
# Edit list of awards below.
#
# Place below the achievements script.
#===============================================================================
DMG_AWARDS = []
# Add new lines here
# Type in
# DMG_AWARDS[number] = [award_id, total?, amount_of_damage]
DMG_AWARDS[0] = [3, false, 500]
DMG_AWARDS[1] = [13, false, 1000]
DMG_AWARDS[2] = [14, true, 5000]
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
       $game_system.damage += damage
       DMG_AWARDS.each {|i|
         if !i[1] and damage > i[2]
           Awards.gain(i[0])
         elsif i[1] and $game_system.damage > i[2]
           Awards.gain(i[0])
         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
       $game_system.damage += damage
       DMG_AWARDS.each {|i|
         if !i[1] and damage > i[2]
           Awards.gain(i[0])
         elsif i[1] and $game_system.damage > i[2]
           Awards.gain(i[0])
         end
       }
     end
     return result
   else
     return gg_init_damage_skill_award_lat(user, skill)
   end
 end
end

class Game_System
 attr_accessor :damage
 
 alias tdks_xdmg_init initialize
 def initialize
   tdks_xdmg_init
   @damage = 0
 end
end


#===============================================================================
# X Gold Spent Achievement Mod
# Author ThallionDarkshine
#-------------------------------------------------------------------------------
# Info:
# Small snippet to give the player an achievement when they spend a certain amount
# of gold either total or in a single purchase.
#
# Instructions:
# Edit list of awards below.
#
# Compatibility:
# Probably won't work with Scene_Shop scripts.
#
# Place below the achievements script.
#===============================================================================
GOLD_AWARDS = []
# Add new lines here
# Type in
# GOLD_AWARDS[number] = [award_id, total?, amount_of_gold]
GOLD_AWARDS[0] = [15, false, 500]
GOLD_AWARDS[1] = [16, false, 1000]
GOLD_AWARDS[2] = [17, true, 5000]
if $gg_achievements == nil || $gg_achievements < 2.0
 raise 'Gold Spent Achievement Mod requires game_guy\'s Achievements v2.0 or higher'
end

class Scene_Shop
 alias tdks_xgold_updt_num update_number
 def update_number
   gold = $game_party.gold
   tdks_xgold_updt_num
   if $game_party.gold < gold
     $game_system.gold_spent += gold - $game_party.gold
     GOLD_AWARDS.each { |i|
       if !i[1] and gold - $game_party.gold >= i[2]
         Awards.gain(i[0])
       elsif i[1] and $game_system.gold_spent >= i[2]
         Awards.gain(i[0])
       end
     }
   end
 end
end

class Game_System
 attr_accessor :gold_spent
 
 alias tdks_xgold_init initialize
 def initialize
   tdks_xgold_init
   @gold_spent = 0
 end
end


#===============================================================================
# X Item Achievement Mod
# Author ThallionDarkshine
#-------------------------------------------------------------------------------
# Info:
# Small snippet to give players achievements when they have a certain number of
# items in their inventory.
#
# Instructions:
# Edit list of awards below.
#
# Compatibility:
# Probably won't work with Scene_Shop scripts.
#
# Place below the achievements script.
#===============================================================================
ITEM_AWARDS = []
# Add new lines here
# Type in
# ITEM_AWARDS[number] = [award_id, amount_of_items]
ITEM_AWARDS[0] = [18, 10]
ITEM_AWARDS[1] = [19, 25]
if $gg_achievements == nil || $gg_achievements < 2.0
  raise 'Item Achievement Mod requires game_guy\'s Achievements v2.0 or higher'
end

class Game_Party
  def num_items
    num = 0
    @items.each { |i| num += i[1] }
    @weapons.each { |i| num += i[1] }
    @armors.each { |i| num += i[1] }
    num
  end
 
  alias tdks_item_awrds_gain_item gain_item
  def gain_item(id, n)
    tdks_item_awrds_gain_item(id, n)
    if n > 0
      ITEM_AWARDS.each { |i|
        if num_items >= i[1]
          Awards.gain(i[0])
        end
      }
    end
  end
 
  alias tdks_item_awrds_gain_weapon gain_weapon
  def gain_weapon(id, n)
    tdks_item_awrds_gain_weapon(id, n)
    if n > 0
      ITEM_AWARDS.each { |i|
        if num_items >= i[1]
          Awards.gain(i[0])
        end
      }
    end
  end
 
  alias tdks_item_awrds_gain_armor gain_armor
  def gain_armor(id, n)
    tdks_item_awrds_gain_armor(id, n)
    if n > 0
      ITEM_AWARDS.each { |i|
        if num_items >= i[1]
          Awards.gain(i[0])
        end
      }
    end
  end
end


G_G

Updated first post, added Thallion's three snippets and script. I just added your own section Thallion in case people don't want an extra dependency. :3

ThallionDarkshine

January 13, 2013, 12:00:58 pm #123 Last Edit: January 13, 2013, 03:13:05 pm by ThallionDarkshine
Yeah, that makes sense. I wouldn't really want to have some random script in my project that just takes up space. And I'll be working on more snippets for this, because I really like how this script works.

Edit - Here's a demo that I made for the script:
Demo

G_G

Thanks Thallion! Added the demo to the first post.

exile360

Thanks, Thallion!
Strange though, I'm getting an error with the demo "This project is from an old version of RPG Maker and cannot be loaded". Never had this before. I'll try using the script itself in my project soon, after I get some other issues sorted out.

G_G

All you have to do is replace the Game.rxproj file.

exile360

Worked, thanks. However, I keep getting this error randomly throughout the demo:
Spoiler: ShowHide

At first it popped up as soon as I launched it, but I downloaded the .dll again and replaced it with the one in the folder and now I can sometimes play for like 10-30 seconds before it errors. Still, not very practical, lol.

ThallionDarkshine

I tried to fix it, and edited the script that I linked to. Replace the Transitions Module from the demo with the new version.