[XP] Skill Equipment System

Started by G_G, September 24, 2009, 11:20:10 pm

Previous topic - Next topic

G_G

September 24, 2009, 11:20:10 pm Last Edit: October 19, 2012, 12:09:04 am by Lightning
Skill Equipment System
Authors: game_guy & KK20
Version: 1.4
Type: Skill Equipping
Key Term: Custom Skill System



Introduction

Okay well its a system that makes it so you can't use all of your skills at once while in battle. Instead you have to equip them. Now here's the catch. Every skill has its own "ap" so when its equipped it takes some of the actor's ap. That way you can't use all of your skills and it adds some uniqueness to the game.


Features


  • Equip Skills Strategically
  • Only Equip Limited Amount of Skills Using Ap
  • Have Different Starting Ap for Each Actor
  • Have Different Ap Gain for Each Actor per Level Up
  • Have Different Ap for Each Skill
  • Have an Exit Scene for When the Skill Equipment Closes
  • Permanently Learn Skills (Thanks KK20)
  • Certain skills cannot be equipped together at the same time (Thanks KK20)



Screenshots

Spoiler: ShowHide



Demo

Updating Demo


Script

Spoiler: ShowHide

#===============================================================================
# Skill Equipment System
# Author game_guy
# Editted by KK20
# Version 1.4
#-------------------------------------------------------------------------------
# Intro:
# Okay well its a system that makes it so you can't use all of your skills at
# once while in battle. Instead you have to equip them. Now here's the catch.
# Every skill has its own "ap" so when its equipped it takes some of the actor's
# ap. That way you can't use all of your skills and it adds some uniqueness to
# the game.
#
# Features:
# Equip Skills Strategically
# Only Equip Limited Amount of Skills Using Ap
# Have Different Starting Ap for Each Actor
# Have Different Ap Gain for Each Actor per Level Up
# Have Different Ap for Each Skill
# Have an Exit Scene for When the Skill Equipment Closes
#
# Instructions:
# Okay so these could be confusing but lets try and get through this.
# Okay they're not that confusing. Okay so go down where it says
# # Begin Config
# And do all of you're configuration there.
#
# Now theres some stuff you need to know.
#
# When adding a skill it does not automatically equip it. So to equip a
# skill use this
# $game_actors[actor_id].equip_skill(skill_id)
# To unequip a skill use this
# $game_actors[id].remove_skill(skill_id)
#
# Now it will not equip it unless there's enough ap left. So you can either do
# this $game_actors[id].add_map(amount) to add to max ap or you can do this
# $game_actors[id].clear_skills to unequip all skills and give all ap back.
# Just to make it a bit easier.
#
# You can always remove max ap to by doing this
# $game_actors[id].remove_map(amount) but note that doing that clears the
# equipped skills as well to avoid any problems.
#
# To open the skill equipment scene use this.
# $scene = $scene = Scene_SkillEquip.new(actor_id)
# To tell if a skill is equipped or not you'll notice the text is greyed out.
# That means it equipped. If its white it means it can be equipped.
# In the scene though to equip/unequip things just press the action button.
#
# Well thats about it.
# Credits:
# game_guy ~ for making it
# Ethan ~ for the idea of it
# Branden ~ beta testing
#
# Enjoy and give credits.
#===============================================================================
# [ KK20's change notes ]
#
# V 1.4
#   - Cleaned up and modified a bit of the existing methods in Game_Actor
#   - Fixed the AP display in the window
#   - Allow user to show the skill's AP cost instead of its SP cost in the scene
#   - Added new feature: Permanent Skills
#     + Skills can be permanently equipped
#     + Script call for this is as follows:
#       $game_actors[id].learn_skill(skill_id, true)
#   - Added new feature: Skill Limitations
#     + Certain skills cannot be equipped together at the same time
#===============================================================================
module GameGuy
  #---------------------------------------------------------------------------
  # ApWord     = This is the word that displays when showing the ap the actor
  #              has.
  #---------------------------------------------------------------------------
  ApWord       = "AP"
  #---------------------------------------------------------------------------
  # StartingAp = The starting ap for every actor. Different amounts can be
  #              defined below at # Config Starting Ap.
  #---------------------------------------------------------------------------
  StartingAp   = 5
  #---------------------------------------------------------------------------
  # ApCost     = The default ap cost for all skills. Different amounts can be
  #              defined below at # Config Ap Costs.
  #---------------------------------------------------------------------------
  ApCost       = 1
  #---------------------------------------------------------------------------
  # ApGain     = The max ap gained when an actor levels up. Different amounts
  #              can be defined below at # Config Sp Gain
  #---------------------------------------------------------------------------
  ApGain       = 2
  #---------------------------------------------------------------------------
  # DisplayAP  = Will display AP costs instead of SP in the scene.
  #              Set to true if you wish to use this. Use false otherwise.
  #---------------------------------------------------------------------------
  DisplayAP    = true
  #---------------------------------------------------------------------------
  # ExitScene  = The scene it goes to when the Skill Equipment closes.
  #
  #---------------------------------------------------------------------------
  ExitScene    = Scene_Menu.new
  #---------------------------------------------------------------------------
  # SkillLimit = A series of arrays that represent what skills cannot
  #              be equipped at the same time.
  #  Examples: [[2,3]]
  #           >> Greater Heal and Mass Heal cannot be equipped together
  #
  #            [[7,10],[7,11],[7,12],[8,10],[8,11],[8,12],[9,10],[9,11],[9,12]]
  #           >> Cannot equip any type of fire spell along with an ice spell
  #
  #            [[53,54,55,56]]
  #           >> Can only equip one: Sharp, Barrier, Resist, Blink
  #---------------------------------------------------------------------------
  SkillLimit = [[7,10],[7,11],[7,12],[8,10],[8,11],[8,12],[9,10],[9,11],[9,12]]
# SkillLimit = [] # <--If you do not wish to use this feature, do this
 
  def self.start_ap(id)
    case id
    #-------------------------------------------------------------------------
    # Config Starting Ap
    # Use this when configuring
    # when actor_id then return starting_ap
    #-------------------------------------------------------------------------
    when 1 then return 10 # Actor 1 : Aluxes
    when 2 then return 8  # Actor 2 : Basil
    end
    return StartingAp
  end
  def self.skill_ap(id)
    case id
    #-------------------------------------------------------------------------
    # Config Ap Costs
    # Use this when configuring
    # when skill_id then return ap_cost
    #-------------------------------------------------------------------------
    when 1 then return 2 # Skill Id 1 : Heal
    when 7 then return 3 # Skill Id 7 : Fire
    when 57 then return 6
    end
    return ApCost
  end
  def self.ap_gain(id)
    case id
    #-------------------------------------------------------------------------
    # Config Ap gain
    # Use this when configuring
    # when actor_id then return ap_gain
    #-------------------------------------------------------------------------
    when 1 then return 4 # Actor 1 : Aluxes
    end
    return ApGain
  end
end

#==============================================================================
# Game_Actor
#------------------------------------------------------------------------------
# Added stuff for Skill Equipping.
#==============================================================================
class Game_Actor < Game_Battler
  attr_accessor :eskills
  attr_accessor :skills
  attr_accessor :skillap
  attr_accessor :skillmaxap
 
  alias gg_add_stuff_lat_ap setup
  def setup(actor_id)
    @actor = $data_actors[actor_id]
    @skillap = GameGuy.start_ap(actor_id)
    @skillmaxap = GameGuy.start_ap(actor_id)
    @eskills = []
    return gg_add_stuff_lat_ap(actor_id)
  end
 
  def skill_learn?(skill_id)
    return @skills.include?(skill_id) || @eskills.include?(skill_id)
  end
 
  def learn_skill(skill_id, perm = false)
    if perm and skill_id > 0
      remove_skill(skill_id) if @skills.include?(skill_id)
      @eskills.delete(skill_id)
      @skills.push(skill_id)
      @skills.sort!
    elsif skill_id > 0 and not skill_learn?(skill_id)
      @eskills.push(skill_id)
      @eskills.sort!
    end
  end
 
  def forget_skill(skill_id)
    remove_skill(skill_id)
    @eskills.delete(skill_id)
  end
 
  def equip_skill(skill_id)
    return unless skill_id > 0 && @eskills.include?(skill_id)
    potential_ap = @skillap
    removal_list = []
    GameGuy::SkillLimit.each{|set|
      if set.include?(skill_id)
        set.each{|id|
          if @skills.include?(id) && @eskills.include?(id) && !removal_list.include?(id)
            potential_ap += GameGuy.skill_ap(id)
            removal_list.push(id)
          end
        }
      end
    }
    if potential_ap >= GameGuy.skill_ap(skill_id)
      removal_list.each{|id| remove_skill(id)}
      @skillap -= GameGuy.skill_ap(skill_id)
      @skills.push(skill_id)
      @skills.sort!
      return true
    else
      return false
    end
  end
 
  def remove_skill(id)
    @skillap += GameGuy.skill_ap(id) if (@skills.include?(id) and @eskills.include?(id))
    @skills.delete(id)
  end
 
  def add_map(n)
    @skillmaxap += n
    clear_skills
    @skillap = @skillmaxap
  end
 
  def remove_map(n)
    @skillmaxap -= n
    if @skillmaxap < 0
      @skillmaxap = 0
    end
    if @skillap > @skillmaxap
      @skillap = @skillmaxap
    end
    clear_skills
  end
 
  def exp=(exp)
    @exp = [[exp, 9999999].min, 0].max
    while @exp >= @exp_list[@level+1] and @exp_list[@level+1] > 0
      @level += 1
      @skillap += GameGuy.ap_gain(@id)
      @skillmaxap += GameGuy.ap_gain(@id)
      for j in $data_classes[@class_id].learnings
        if j.level == @level
          learn_skill(j.skill_id)
        end
      end
    end
    while @exp < @exp_list[@level]
      @level -= 1
    end
    @hp = [@hp, self.maxhp].min
    @sp = [@sp, self.maxsp].min
  end
 
  def clear_skills
    deleting_these = @skills.clone
    deleting_these.each{|id| @skills.delete(id) if @eskills.include?(id) }
    @skillap = @skillmaxap
  end
 
end

#==============================================================================
# Window_GGAPSkill
#------------------------------------------------------------------------------
# Copy of Window_Skill but just slightly different.
#==============================================================================
class Window_GGAPSkill < Window_Selectable
  def initialize(actor)
    super(0, 128, 640, 352)
    @actor = actor
    @column_max = 2
    refresh
    self.index = 0
  end
  def skill
    return @data[self.index]
  end
  def refresh
    if self.contents != nil
      self.contents.dispose
      self.contents = nil
    end
    @data = []
    for i in 0...@actor.eskills.size
      skill = $data_skills[@actor.eskills[i]]
      if skill != nil
        @data.push(skill)
      end
    end
    @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)
    skill = @data[index]
    if @actor.skill_can_use?(skill.id)
      self.contents.font.color = normal_color
    else
      self.contents.font.color = disabled_color
    end
    x = 4 + index % 2 * (288 + 32)
    y = index / 2 * 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(skill.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, 204, 32, skill.name, 0)
    self.contents.draw_text(x + 232, y, 48, 32, skill.sp_cost.to_s, 2)
  end
  def update_help
    @help_window.set_text(self.skill == nil ? "" : self.skill.description)
  end
end

#==============================================================================
# Window_GGAPSkillEquip
#------------------------------------------------------------------------------
# Window uses for equipping skills.
#==============================================================================
class Window_GGAPSkillEquip < Window_Selectable
  def initialize(actor)
    super(0, 128, 640, 352)
    @actor = actor
    @column_max = 2
    refresh
    self.index = 0
  end
  def skill
    return @data[self.index]
  end
  def refresh
    if self.contents != nil
      self.contents.dispose
      self.contents = nil
    end
    @data = []
    for i in 0...@actor.eskills.size
      skill = $data_skills[@actor.eskills[i]]
      if skill != nil
        @data.push(skill)
      end
    end
    @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)
    skill = @data[index]
    if @actor.skills.include?(skill.id)
      self.contents.font.color = normal_color
    else
      self.contents.font.color = disabled_color
    end
    x = 4 + index % 2 * (288 + 32)
    y = index / 2 * 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(skill.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, 204, 32, skill.name, 0)
    if GameGuy::DisplayAP
      self.contents.draw_text(x + 232, y, 48, 32, GameGuy.skill_ap(skill.id).to_s, 2)
    else
      self.contents.draw_text(x + 232, y, 48, 32, skill.sp_cost.to_s, 2)
    end
  end
  def update_help
    @help_window.set_text(self.skill == nil ? "" : self.skill.description)
  end
end

#==============================================================================
# Window_GGActorAp
#------------------------------------------------------------------------------
# Window used to display AP and Actor name.
#==============================================================================
class Window_GGActorAp < Window_Base
  def initialize(actor)
    super(0,64,640,64)
    self.contents = Bitmap.new(width-32,height-32)
    @actor = $game_actors[actor]
    refresh
  end
  def refresh
    self.contents.clear
    ap = GameGuy::ApWord
    self.contents.draw_text(0, 0, 640, 32, "#{@actor.name}")
    self.contents.draw_text(0, 0, 640-32, 32, "#{ap} #{@actor.skillap} / " +
                                           "#{@actor.skillmaxap}", 2)
  end
end

#==============================================================================
# Scene_Skill
#------------------------------------------------------------------------------
# Just slightly modded the main method.
#==============================================================================


#==============================================================================
# Scene_SkillEquip
#------------------------------------------------------------------------------
# The scene that deals with equipping skills.
#==============================================================================
class Scene_SkillEquip
  def initialize(actor_id=1)
    @id = actor_id
  end
  def main
    @actor = $game_actors[@id]
    @help_window = Window_Help.new
    @skill_window = Window_GGAPSkillEquip.new(@actor)
    @skill_window.help_window = @help_window
    @status_window = Window_GGActorAp.new(@actor.id)
    Graphics.transition
    loop do
      Graphics.update
      Input.update
      update
      if $scene != self
        break
      end
    end
    @help_window.dispose
    @skill_window.dispose
    @status_window.dispose
  end
  def update
    @help_window.update
    @skill_window.update
    @status_window.update
    if @skill_window.active
      update_skill
      return
    end
  end
  def update_skill
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      $scene = GameGuy::ExitScene
      return
    end
    if Input.trigger?(Input::C)
      skill = @skill_window.skill
      if @actor.skills.include?(skill.id)
        $game_system.se_play($data_system.decision_se)
        @actor.remove_skill(skill.id)
      else
        result = @actor.equip_skill(skill.id)
        if result
          $game_system.se_play($data_system.decision_se)
        else
          $game_system.se_play($data_system.buzzer_se)
        end
      end
      @status_window.refresh
      @skill_window.refresh
      return
    end
  end
end



Instructions

In the script.


Compatibility

Not tested with SDK.
The Skill Equipment System is not compatible with the "Materia-System"(from "SepirothSpawn" and the translated/modified ones)
The Skills, which are added by a materia aren`t appended in the Skill Equipment Screen.


Credits and Thanks


  • game_guy ~ for making it
  • KK20 ~ For adding new features and optimizing the script
  • Ethan ~ for making the idea of it
  • Branden ~ beta testing



Author's Notes

Give credits and enjoy!

Hellfire Dragon

Nice, don't know about uniqueness though :P Does it work with Blizz ABS?

Aqua

Shouldn't white be equipped and greyed out be non-equipped? :P

G_G

September 25, 2009, 06:03:33 pm #3 Last Edit: September 25, 2009, 11:46:48 pm by game_guy
I'm going to test it with Blizz-Abs and aqua I'll switch it real fast

EDIT:
Switched the colors aqua need to update the demo tho

EDIT 2:
Updated demo

EDIT 3:
Works with Blizz-Abs

Aqua

Lol...I could have told you that it was compatible with Blizz-ABS just by looking at the script... :P

tSwitch

I wouldn't call it AP, just because of the EQUAP skills in Tons of Addons.


FCF3a A+ C- D H- M P+ R T W- Z- Sf RLCT a cmn+++ d++ e++ f h+++ iw+++ j+ p sf+
Follow my project: MBlok | Find me on: tSwitch.us | Twitter | Tumblr

G_G

well it is changable and I named the actors variabls differently so its ok.

Blizzard

Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

G_G

Yea but this doesnt use equipment for skills, you literally equip skills to the actor not using weapons or armor that way you actor doesnt have a crap load of spells to use in battle. It was my friends idea but yea you equip the spells to teh actor not through equipment

Blizzard

Ah, then I misunderstood the concept. Nice script. :D
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

tSwitch

Quote from: game_guy on September 27, 2009, 02:30:08 pm
well it is changable and I named the actors variabls differently so its ok.


yeah I noticed when I put it in my game.


FCF3a A+ C- D H- M P+ R T W- Z- Sf RLCT a cmn+++ d++ e++ f h+++ iw+++ j+ p sf+
Follow my project: MBlok | Find me on: tSwitch.us | Twitter | Tumblr

G_G

Quote from: Blizzard on September 27, 2009, 02:58:50 pm
Ah, then I misunderstood the concept. Nice script. :D


Thanks :)

Anyways yea this didnt take long to make but I feel there should still be something added...its probably just me but anyone have any suggestions?

tSwitch

found a bug.

when you call the equip skill from the map it doesn't update ap
because you only have ap update during the equip scene.

solution: move ap change to the equip_skill method.


FCF3a A+ C- D H- M P+ R T W- Z- Sf RLCT a cmn+++ d++ e++ f h+++ iw+++ j+ p sf+
Follow my project: MBlok | Find me on: tSwitch.us | Twitter | Tumblr

G_G

September 29, 2009, 11:54:37 am #13 Last Edit: September 29, 2009, 11:57:58 am by game_guy
doing that right now

EDIT: Updated demo and script, fixed minor bug....

Orici

I downloaded the demo and got this error when tried to equip a skill
Script 'Skill Equipment System' line 151 nomethoderror ocurred
undefined method 'skillap' for nil:Nilclass

G_G


Orici

now it says, in the same line

undefined method 'skillap' for #<RPG::Actor:0x14c0c70>  :(

G_G

now try it I think I fixed it for sure.

Calintz

Sounds fantastic!!
I'll have to try it out!!

G_G

*updates yet again* Fixed another small bug