The RPG Maker Resource Kit

RMRK RPG Maker Creation => VX => VX Scripts Database => Topic started by: modern algebra on October 30, 2010, 01:42:42 AM

Title: Replace Skill
Post by: modern algebra on October 30, 2010, 01:42:42 AM
Replace Skill
Version: 1.0
Author: modern algebra
Date: October 29, 2010

Version History



Description


This script is very simple. It allows you to specify skills to forget when a certain skill is learned. As a corollary, you also will not learn a new skill if you already have a skill that would have replaced it.

Sounds useless? Kind of. But it can be helpful if, say, you want to give the impression of a skill levelling up. Say you have a series of skills: Heal I is learned at level 2, Heal II is learned at level 14, and Heal III is learned at level 32. With this script, you can set it so that Heal I is forgotten when you learn Heal II, and Heal II is forgotten when you learn Heal III.

Also, since it was designed with consideration to the idea that it would be used to give the illusion that skills were levelling, a conditional branch check to see if a skill is learned will return true as long as you have either the skill asked for or any skill that would cause you to forget the skill asked for. So, if your conditional branch is checking for the Heal I skill, it will return true if you have Heal I, Heal II, or Heal III.

Features


Instructions

Place the script above Main and below Materials in the Script Editor. If using my Note Editor script with the General Compatibility Patch, then this script must be placed below that. If you encounter any problems, try placing this script below every other custom script you are using. If it is still troublesome, then find the topic at RMRK.net and report it.

The script is easy to setup: all you need to do is put the following code into the notebox of a skill:

        \forget[x, y, ..., z]

where: x-z are the IDs of the skills you want to forget when this skill is learned. It allows for multiples so that, with serial skills, you can ensure that all lower levels will not be learnable when you have a higher level of that skil. So, for the Heal I, II, III example (and let's say the ID of Heal I is 34, the ID of Heal II is 35, and the ID of Heal II is 36 - they don't have to be sequential, but they are those by default):
    Heal I would be empty;
    Heal II would have the code:  \forget[34]
    Heal III would have the code: \forget[34, 35]

Script


Code: [Select]
#==============================================================================
#    Replace Skill
#    Version: 1.0
#    Author: modern algebra (rmrk.net)
#    Date: October 29, 2010
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Description:
#
#    This script is very simple. It allows you to specify skills to forget when
#   a certain skill is learned. As a corollary, you also will not learn a new
#   skill if you already have a skill that would have replaced it.
#
#    Sounds useless? Kind of. But it can be helpful if, say, you want to give
#   the impression of a skill levelling up. Say you have a series of skills:
#   Heal I is learned at level 2, Heal II is learned at level 14, and Heal III
#   is learned at level 32. With this script, you can set it so that Heal I is
#   forgotten when you learn Heal II, and Heal II is forgotten when you learn
#   Heal III.
#
#    Also, since it was designed with consideration to the idea that it would
#   be used to give the illusion that skills were levelling, a conditional
#   branch check to see if a skill is learned will return true as long as you
#   have either the skill asked for or any skill that would cause you to forget
#   the skill asked for. So, if your conditional branch is checking for the
#   Heal I skill, it will return true if you have Heal I, Heal II, or Heal III.
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Instructions:
#
#    Place the script above Main and below Materials in the Script Editor. If
#   using my Note Editor script with the General Compatibility Patch, then this
#   script must be placed below that. If you encounter any problems, try
#   placing this script below every other custom script you are using. If it
#   is still troublesome, then find the topic at RMRK.net and report it.
#
#    The script is easy to setup: all you need to do is put the following code
#   into the notebox of a skill:
#
#        \forget[x, y, ..., z]
#
#   where: x-z are the IDs of the skills you want to forget when this skill is
#  learned. It allows for multiples so that, with serial skills, you can ensure
#  that all lower levels will not be learnable when you have a higher level of
#  that skil. So, for the Heal I, II, III example (and let's say the ID of Heal
#  I is 34, the ID of Heal II is 35, and the ID of Heal II is 36 - they don't
#  have to be sequential, but they are those by default):
#    Heal I would be empty;
#    Heal II would have the code:  \forget[34]
#    Heal III would have the code: \forget[34, 35]
#==============================================================================

#==============================================================================
# ** RPG::Skill
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    new method - mars_forget_skills
#==============================================================================

class RPG::Skill
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Forget Skills
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def mars_forget_skills
    if !@mars_forget_skills
      @mars_forget_skills = []
      if self.note[/\\FORGET\[(.+?)\]/i] != nil
        $1.scan (/\d+/).each { |id| @mars_forget_skills.push (id.to_i) }
      end
    end
    return @mars_forget_skills
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Compatibility with Note Editor + General Compatibility Patch
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  if self.method_defined? (:ma_reset_note_values)
    alias morlg_relcskl_reset_6hw1 ma_reset_note_values
    def ma_reset_note_values (*args)
      morlg_relcskl_reset_6hw1 (*args) # Run Original Method
      @mars_forget_skills = nil
    end
  end
end

#==============================================================================
# ** Game_Actor
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    aliased method - learn_skill; skill_learn?
#==============================================================================

class Game_Actor
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Skill Learn?
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias malab_replce_skllrn_8uj3 skill_learn?
  def skill_learn? (skill, *args)
    (@skills - skill.mars_forget_skills).each { |s_id|
      return true if $data_skills[s_id].mars_forget_skills.include? (skill.id)
    }
    return malab_replce_skllrn_8uj3 (skill, *args)
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Learn Skill
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias mlg_rplskl_lernskl_7yh3 learn_skill
  def learn_skill (skill_id, *args)
    mlg_rplskl_lernskl_7yh3 (skill_id, *args) # Run Original method
    $data_skills[skill_id].mars_forget_skills.each { |s_id| forget_skill (s_id) } if @skills.include? (skill_id)
  end
end

Credit



Thanks


Support


If you encounter any bugs with this script, please report it in this topic. Remember to look at the Script Troubleshooting for the Non-Scripter (http://rmrk.net/index.php/topic,40220.0.html) tutorial first and see if anything in there helps. Even if it does and you are able to fix the problem, please alert me to the issue.

Known Compatibility Issues

If using the Note Editor and General Compatibility Patch, then this script must be placed below it.
Title: Re: Replace Skill
Post by: Dimosthennis on October 30, 2010, 02:17:50 AM
Nice!
But i think you Scripted this to fast :P
An error poped up when i chosed New game. Might be one of the scripts i got that bugged this problem :/
Code: [Select]
Script 'Replace Skill' line 96: NoMethodError occurred.
undefined method 'mars_forget_skills' for 857:Fixnum
Title: Re: Replace Skill
Post by: modern algebra on October 30, 2010, 02:31:54 PM
It works fine when using all default scripts; it must be an incompatibility with another script. The skill_learn? method is supposed to accept only a skill object as its argument. Whatever other script you are using must change it so that it can accept skill IDs as well. At least, that's what I assume it does. Do you have >857 skills? If not, then it is doing something else entirely and I would need to see the offending script.

If the other script aliases and doesn't overwrite, then you'll be able to fix it simply by putting this script above the other one in the script editor. Otherwise, you can try replacing the skill_learn? method in my script with:

Code: [Select]

  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Skill Learn?
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias malab_replce_skllrn_8uj3 skill_learn?
  def skill_learn? (skill, *args)
    orig_skill = skill
    skill = $data_skills[orig_skill] if skill.is_a? (Fixnum)
    (@skills - skill.mars_forget_skills).each { |s_id|
      return true if $data_skills[s_id].mars_forget_skills.include? (skill.id)
    }
    return malab_replce_skllrn_8uj3 (orig_skill, *args)
  end
Title: Re: Replace Skill
Post by: Dimosthennis on October 30, 2010, 03:40:52 PM
Ah!
It works fine now.
Hade to 'replace Skill_Learn?' what you script.
Thanks alot :)
and how do i give you a Rep point? :P

MrD
Title: Re: Replace Skill
Post by: modern algebra on October 30, 2010, 08:40:57 PM
youu have to have 75 posts or more. Rep is meaningless anyway.
Title: Re: Replace Skill
Post by: Infinate X on December 01, 2010, 10:30:21 PM
You can do this with common events set to parallel process... You can also set an event to every map so you don't need a switch but that would take longer and be harder...
Title: Re: Replace Skill
Post by: modern algebra on December 01, 2010, 10:47:37 PM
Yeah, but it's not exactly efficient to have a ton of conditional branches operating every frame just to check whether every actor has however many skills and replace them if they have the next level of it. And by "not exactly efficient," I mean "totally inefficient".
Title: Re: Replace Skill
Post by: zerothedarklord on March 24, 2011, 12:30:07 AM
What Modern says is true, I tried what the other guy said, about running parallel processes, it worked fine, but it lagged the fuck out of the game. I was lucky to be running at 5 FPS at any given time, and it was annoying. Thanks for the awesome script modern.
Title: Re: Replace Skill
Post by: modern algebra on March 24, 2011, 12:51:05 AM
Well, you could use wait frames to reduce that since there is no reason to run an event like that every frame, but it is still inefficient