RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
'Always on' Passive skills

0 Members and 1 Guest are viewing this topic.

**
Rep:
Level 86
This is a passive skill script that has the skill 'always on'.  So, let's say you want skill number 83 to add 5% to hp, this script allows it.

The instructions are in the header of the script, and screenshots, well, it is hard to show a stat being increased by a skill.

Spoiler for script:
Code: [Select]
#===============================================================================
#  Passive Skills, by Leon_Westbrooke
#  v. 1.0
#----------------------------------------------------------------------
#  Instructions:  Put below all default scripts, and above Main

#  Features:  Creates passive skills that adds to the stats:
#    HP, SP, STR, DEX, AGI, INT, EVA, Atk, PDef, MDef
#   
#    Adds stats based on a percentage. (so, 100% will double that stat.)
#
#  To have a skill lower stats, make the number negative in the module.
#
#  Compatability:
#    There are no known clashes with other scripts.
#
#  Notes:
#    This script aliases the stats in Game_Actor, and rewrites the refresh
#    method in Window_Skill.
#===============================================================================


#===============================================================================
#  module Passive_Skills
#===============================================================================
module Passive_Skills
  #--------------------------------------------------------------------
  #  Passive_Skills = { skill_id => {'stat' => amount,..},..}
  #  stats:  'hp', 'sp', 'str', 'dex', 'agi', 'int', 'eva', 'atk', 'pdef', 'mdef'
  #--------------------------------------------------------------------
  Passive_Skills = {
  1 => {'hp' => 5}
  }
end
#===============================================================================
#  END module Passive_Skills
#===============================================================================


#===============================================================================
#  Game_Actor
#===============================================================================
class Game_Actor < Game_Battler
 
  attr_accessor :passive_hp
  attr_accessor :passive_sp
  attr_accessor :passive_str
  attr_accessor :passive_dex
  attr_accessor :passive_agi
  attr_accessor :passive_int
  attr_accessor :passive_eva
  attr_accessor :passive_atk
  attr_accessor :passive_pdef
  attr_accessor :passive_mdef
 
  alias leon_passiveskills_gameactor_setup setup
  alias leon_passiveskills_gameactor_basehp base_maxhp
  alias leon_passiveskills_gameactor_basesp base_maxsp
  alias leon_passiveskills_gameactor_basestr base_str
  alias leon_passiveskills_gameactor_basedex base_dex
  alias leon_passiveskills_gameactor_baseagi base_agi
  alias leon_passiveskills_gameactor_baseint base_int
  alias leon_passiveskills_gameactor_baseeva base_eva
  alias leon_passiveskills_gameactor_baseatk base_atk
  alias leon_passiveskills_gameactor_basepdef base_pdef
  alias leon_passiveskills_gameactor_basemdef base_mdef
 
  def setup(actor_id)
    @passive_hp = 0
    @passive_sp = 0
    @passive_str = 0
    @passive_dex = 0
    @passive_agi = 0
    @passive_int = 0
    @passive_eva = 0
    @passive_atk = 0
    @passive_pdef = 0
    @passive_mdef = 0
    leon_passiveskills_gameactor_setup(actor_id)
  end
 
  def passive_bonus
    ps = Passive_Skills
    hp = 0
    sp = 0
    str = 0
    dex = 0
    agi = 0
    int = 0
    eva = 0
    atk = 0
    pdef = 0
    mdef = 0
    for i in 0...@skills.size
      if ps::Passive_Skills.keys.include?(@skills[i])
        for j in 0...ps::Passive_Skills[@skills[i]].size
          case ps::Passive_Skills[@skills[i]].keys[j]
          when 'hp'
            hp += ps::Passive_Skills[@skills[i]]['hp']
          when 'sp'
            sp += ps::Passive_Skills[@skills[i]]['sp']
          when 'str'
            str += ps::Passive_Skills[@skills[i]]['str']
          when 'dex'
            dex += ps::Passive_Skills[@skills[i]]['dex']
          when 'agi'
            agi += ps::Passive_Skills[@skills[i]]['agi']
          when 'int'
            int += ps::Passive_Skills[@skills[i]]['int']
          when 'eva'
            eva += ps::Passive_Skills[@skills[i]]['eva']
          when 'atk'
            atk += ps::Passive_Skills[@skills[i]]['atk']
          when 'pdef'
            pdef += ps::Passive_Skills[@skills[i]]['pdef']
          when 'mdef'
            mdef += ps::Passive_Skills[@skills[i]]['mdef']
          end
        end
      end
    end
    @passive_hp = hp
    @passive_sp = sp
    @passive_str = str
    @passive_dex = dex
    @passive_agi = agi
    @passive_int = int
    @passive_eva = eva
    @passive_atk = atk
    @passive_pdef = pdef
    @passive_mdef = mdef
  end
 
  def base_maxhp
    ps = Passive_Skills
    n = leon_passiveskills_gameactor_basehp
    n = n + (n * @passive_hp * 0.01)
    passive_bonus
    return n
  end
 
  def base_maxsp
    ps = Passive_Skills
    n = leon_passiveskills_gameactor_basesp
    n = n + (n * @passive_sp * 0.01)
    return n
  end
 
  def base_str
    ps = Passive_Skills
    n = leon_passiveskills_gameactor_basestr
    n = n + (n * @passive_str * 0.01)
    return n
  end
 
  def base_dex
    ps = Passive_Skills
    n = leon_passiveskills_gameactor_basedex
    n = n + (n * @passive_dex * 0.01)
    return n
  end
 
  def base_agi
    ps = Passive_Skills
    n = leon_passiveskills_gameactor_baseagi
    n = n + (n * @passive_agi * 0.01)
    return n
  end
 
  def base_int
    ps = Passive_Skills
    n = leon_passiveskills_gameactor_baseint
    n = n + (n * @passive_int * 0.01)
    return n
  end
 
  def base_atk
    ps = Passive_Skills
    n = leon_passiveskills_gameactor_baseatk
    n = n + (n * @passive_atk * 0.01)
    return n
  end
 
  def base_pdef
    ps = Passive_Skills
    n = leon_passiveskills_gameactor_basepdef
    n = n + (n * @passive_pdef * 0.01)
    return n
  end
 
  def base_mdef
    ps = Passive_Skills
    n = leon_passiveskills_gameactor_basemdef
    n = n + (n * @passive_mdef * 0.01)
    return n
  end
end
#===============================================================================
#  END Game_Actor
#===============================================================================


#===============================================================================
#  Window_Skill
#===============================================================================
class Window_Skill
  def refresh
    if self.contents != nil
      self.contents.dispose
      self.contents = nil
    end
    @data = []
    for i in 0...@actor.skills.size
      skill = $data_skills[@actor.skills[i]]
      #-----------------------------------------------------------------
      #  Added 3 Lines right here:
      #  if $game_temp.in_battle
      #    ps = Passive_Skills
      #    unless ps::Passive_Skills.keys.include?(skill)
      # ----------------------------------------------------------------
      if $game_temp.in_battle
        ps = Passive_Skills
        unless ps::Passive_Skills.keys.include?(skill.id)
          if skill != nil
            @data.push(skill)
          end
      #-----------------------------------------------------------------
      # Added two 'end's right here.
      #-----------------------------------------------------------------
        end
      end
    end
    @item_max = @data.size
    if @item_max > 0
      self.contents = Bitmap.new(width - 32, row_max * 32)
      self.contents.font.name = $defaultfonttype  # "Skill" window font
      self.contents.font.size = $defaultfontsize
      for i in 0...@item_max
        draw_item(i)
      end
    end
  end
end
#===============================================================================
# End Window_Skill
#===============================================================================

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
Nice script!

I don't like using hashes for databases myself, but I don't really have a reason to oppose it :P

Nice work.

**
Rep:
Level 86
May i ask why you dont like using modules as databases?

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
I have nothing against modules. I said hashes as in {}. In this case, I think that you are using the hash appropriately and that they make the database more intuitive and easier to use. I just prefer to avoid hashes myself. It's purely preferential on my part.

*
? ? ? ? ? ? ? ? ? The nice kind of alien~
Rep:
Level 92
Martian - Occasionally kind
Retrieving data from arrays are faster than retrieving data from hashes.
In this case the difference will probably be so little and finding out whether a given key is present is on average faster than with an array. That is, if you have used the proper methods.

Don't use:
Code: [Select]
if ps::Passive_Skills.keys.include?(@skills[i])
This will create an array containing the keys in the hash. On this array you check if the skill is present.
Instead you should use:
Code: [Select]
if ps::Passive_Skills.has_key?(@skills[i])  # Or whatever the correct syntax is.

Change accordingly if there are other places where you use .keys.include?(something).

I doubt the decrease in speed will be noticeable. Especially if the information is only updated when necessary. The only time that will be is the first time base_maxhp, base_maxsp, base_str and so on. The first time one of them are called after the actor learns or forgets a skill. Basically, whenever the actors skills changes.
You update the passive skills effects whenever base_maxhp is called and only when base_maxhp is called. (Also, why do you update the skills after you add @passive_skills. This could give you the wrong hp bonus one time.)
You rely on base_maxhp being called before the other methods are called. You shouldn't.
One can notice that either learn_skill or forget_skill must be called for the skills to change.
I suggest that alias both and let them call the alias as well as setting a flag telling the skills might have been changed; for example @passive_skills_update = true.
Then we could for example have a base_maxhp method looking like this:
Code: [Select]
  def base_maxhp
    ps = Passive_Skills
    if @passive_skills_update || @passive_skills_update.nil?
      passive_bonus
      @passive_skills_update = false
    end
    n = leon_passiveskills_gameactor_basehp
    n = n + (n * @passive_hp * 0.01)
    return n
  end

And have similar changes to the other base methods.
Note the code I have written here has not been tested. So don't be surprised if you encounter errors, be critical ;)

You have made accessor for the passive_hp, passive... and so on (attr_accessor :passive_hp)
Why have you made them as accessors and not as readers? (attr_reader :passive_hp)
Changes to the passive values will just be overwritten next time a passive skill is learned or forgotten.

I suggest you test how it works with old saves ;)

All this time I have focused on the problems. I hope you did not get discourage. I wanted to help you make the script better.
It is a nice script as modern said. There were just some inefficiencies in it. Another question is what did you do right. What was good?
It would be unfortunate if you removed or changed a good feature into something worse during the effort of making it even better.
I like how you showed which parts was added to the Window_Skill so it should be relatively easy for the users to add the changes themselves
I like the idea. Good job coming up with it ^_^
The way you aliased the base_ methods in Game_Actor. Should increase compatibility with other scripts.

I'll look forward to your revision.

*hugs*
 - Zeriab

**
Rep:
Level 86
I see where you are coming from, Zeriab. Thanks for the tips, too. I wrote this forever ago (seriously, like... last march) so my scripting in it is rustly.  At any rate, I do appreciate the advice.

**
Rep: +0/-0Level 84
Okay... beginner question:

How do you setup multiple passive skills?

This works, for say skill_id = 1

Code: [Select]
  Passive_Skills = {
  1 => {'sp' => 100}
  }
end

However, I've tried all three of the following methods, and either get a syntax error, or it only places the first/last passive skill:

Only gives SP bonus:
Code: [Select]
  Passive_Skills = {
  1 => {'sp' => 100}
  }
  {
  2 => {'hp' => 100}
  }
end

Syntax Error:
Code: [Select]
  Passive_Skills = {
  1 => {'sp' => 100}
  2 => {'hp' => 100}
  }
end

Only gives HP Bonus:
Code: [Select]
  Passive_Skills = {
  1 => {'sp' => 100}
  }
Passive_Skills = {
  2 => {'hp' => 100}
  }
end

What am I doing wrong?

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
You almost have it right with #2, but you are missing the comma:

Code: [Select]
  Passive_Skills = {
  1 => {'sp' => 100},
  2 => {'hp' => 100}
  }
end

should work. Though, I might be missing something.

**
Rep: +0/-0Level 84
Deleted Original Message:

Yes, thank you, silly comma caused me all this trouble! =)
« Last Edit: January 29, 2009, 12:34:27 AM by themrmystery »

**
Rep: +0/-0Level 84
If anyone else needs to know more information about using this script here's a code snippet for getting multiple increases to one skill:

Code: [Select]
  Passive_Skills = {
  4 => {'sp' => 100, 'hp' => 100}
  }
end

***
Rep:
Level 82
We learn by living...
I tried this system with my game and it just made all my skills disappear. Of course I'm using some custom stats and Mo's ABS, which might be interfering with skill programs.