[XP] Skill Equipment System

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

Previous topic - Next topic

KK20

I should have probably said this. Can you upload a demo?

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

zottel89

Yeah of course I can, but the game is in german, sooo...
I don't know if you can make your way through to the first area
of fights :D

Or is it just so you can look through the scripts ?

I guess I could upload it, yeah.

KK20

Yes, I just only want to figure out the bug. I don't really need to play the game other than maybe to test battle. If it's something you don't feel comfortable sharing with everyone, send me the link/file via email.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

G_G

Updated to 1.35. Fixed a bug that could possibly conflict with any other scripts relating to skill learning. Didn't really realize that the bug existed until recently. Special thanks to KK20 for providing the fix (in another thread).

zottel89

The updated version seems to have a syntax error in line 173

G_G


Zexion

October 17, 2012, 05:54:18 pm #86 Last Edit: October 17, 2012, 06:00:24 pm by Noctis
Is there any way to make a skill un-removable? I ask because I'm using this as a base for abilities in my evented battle system. They will gain abilities at certain levels, and throughout the game, and some of them (like hp boost) shouldn't be removable ever. At least not for my game lol.

In addition to that, how would I make 1 skill un-equip another skill?

KK20

October 17, 2012, 11:38:18 pm #87 Last Edit: October 17, 2012, 11:54:07 pm by Ezel Berbier
Looking into that as I type this (avoiding homework FTW).

Also, now that I fully understand how this system works, I'd like to point out that the variable @eeskills is entirely unnecessary as long as you replace any instance of it in conditional statements with @skills instead.

Quote from: Noctis on October 17, 2012, 05:54:18 pm
In addition to that, how would I make 1 skill un-equip another skill?
Do you mean like you have 'slots' to equip skills (universal)? Or do you mean something more like "You can only know a fire spell or an ice spell, but you cannot have both equipped at the same time, but I could care less about the other skills you have equipped" (strict)?

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

G_G

Quote from: Ezel Berbier on October 17, 2012, 11:38:18 pm
Also, now that I fully understand how this system works, I'd like to point out that the variable @eeskills is entirely unnecessary as long as you replace any instance of it in conditional statements with @skills instead.


Oh I know. You gotta remember though, I made this three years ago, only one year after I had just started programming. If I had the motivation and time to do it, I'd go through and revamp all of my scripts. Between now and then, my knowledge of programming has definitely grew and still growing.

As for Zexion's question, if I can find some time, I might redo this script entirely, first to revamp it, secondly, to throw in your suggestions for Permanent Skills and Equipment Rules. Though don't get your hopes up too much, I've been pretty busy with school lately, and when I'm not, I'm usually relaxing from school. Been finding it hard to find any sort of motivation for programming lately.

Zexion

Quote from: Ezel Berbier on October 17, 2012, 11:38:18 pm
Quote from: Noctis on October 17, 2012, 05:54:18 pm
In addition to that, how would I make 1 skill un-equip another skill?
Do you mean like you have 'slots' to equip skills (universal)? Or do you mean something more like "You can only know a fire spell or an ice spell, but you cannot have both equipped at the same time, but I could care less about the other skills you have equipped" (strict)?


I meant more along the lines of the second option, but not quite either. I have a skill which is the "finisher" attack after a combo, and throughout the game, it will upgrade with your level, and once it upgrades to "finisher2" it will unequip "finisher" for that one, but can be replaced at any time with "finisher, finisher2, finisher3" etc.

To clearify: When you put on one skill, it removes others that aren't allowed with it. Only 1 finishing move at a time.

KK20

Quote from: Lightning on October 18, 2012, 12:00:58 am
Oh I know. You gotta remember though, I made this three years ago, only one year after I had just started programming.
Oh, I just guessed that after all these years you didn't notice it. It was only like a 2 minute fix, so yeah...I guess that's where my assumption came from.

Quote from: Lightning on October 18, 2012, 12:00:58 am
Though don't get your hopes up too much, I've been pretty busy with school lately, and when I'm not, I'm usually relaxing from school. Been finding it hard to find any sort of motivation for programming lately.
That's what I'm here for, right?  :naughty:
Version 1.4: 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
I recall reading those forum posts months back about your situation and I deeply understand your position.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

G_G

Thanks! <3 Added you to the credits, added your script to the original post. Thanks KK20. *levels up*

TrueCynder

Hey there
when i tried to replace the scene for the normal equipment with the skillequipment
i got this error message



What it does is kinda funny actuelly
it uses the wrong index when i select the first actor it crushes
when i select the second actor it uses the actor 1 and so on
so the fourth actor has the third id =S

how can i fix that ? id love to use this script its exactly what i was looking for :)

G_G

January 19, 2014, 09:40:31 pm #93 Last Edit: January 19, 2014, 09:42:38 pm by gameus
Actually, it's not using the wrong index at all. Arrays always start at 0. Even without this script, that's how it works in the default scripts. 0 being the first member, 1 being the second, and so on. I'll try to look into the error real quick.

EDIT: I know what you're issue is (I think). You said you were trying to replace the normal equipment with this scene instead. The party goes off of party indexes, while my script goes off of actor_id.

The line where you have
$scene = Scene_SkillEquip.new(@status_window.index)

Should look like this
$scene = Scene_SkillEquip.new($game_party[@status_window.index].id)


And it should work.

TrueCynder

now it does not work at all
now it crushes with everyone :(


KK20

Typo on G_G's end (forgot #actors):
$scene = Scene_SkillEquip.new($game_party.actors[@status_window.index].id)

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

TrueCynder

Awesome :) worked ^^
(thanks  :shy:)

Just one last question
can i aslo increase an actors AP due a script call ?

KK20


Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

TrueCynder