Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

[XP]passive skills and gold multiplier help.

Hello,

I've been trying to write a passive skills script, and pretty much everything works, except one thing.
I want to have an option so whenever a certain skill is learned, the player gets his gold gain when he wins a battle multiplied by something.
I think i've come up with a solution, although i'm not sure it will work.
Here is the script i've written:

Code:
#==============================================================================
# ** Passive_Skills
#----------------------------------------------------------------------------------------------------
#
#
#
#
#
#
#
#==============================================================================
  PASSIVE_SKILLS = [1, 2, 3]
  #skill_id => [max_hp, max_sp, str, dex, agi, int, atk, pdef, mdef, gold_multiplier]
  ATTRIBUTES =
  {
  1 => [999, 999, 999, 999, 999, 999, 999, 999, 999, 2] ,
  2 => [0, 100, 0, 0, 0, 0, 0, 0, 0, 1] ,  
  3 => [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] 
  }
  
class Game_Actor < Game_Battler
  attr_accessor :goldt 
  alias passive_skill_learn learn_skill
  alias passive_skill_forget forget_skill
  #--------------------------------------------------------------------------
  # * Get Actor ID
  #--------------------------------------------------------------------------
  def learn_skill(skill_id)
    passive_skill_learn(skill_id)
    if PASSIVE_SKILLS.include?(skill_id)
      @maxhp_plus += ATTRIBUTES[skill_id][0]
      @maxsp_plus += ATTRIBUTES[skill_id][1]
      @str_plus   += ATTRIBUTES[skill_id][2]
      @dex_plus   += ATTRIBUTES[skill_id][3]
      @agi_plus   += ATTRIBUTES[skill_id][4]
      @int_plus   += ATTRIBUTES[skill_id][5]
      @atk_plus   += ATTRIBUTES[skill_id][6]
      @pdef_plus  += ATTRIBUTES[skill_id][7]
      @mdef_plus  += ATTRIBUTES[skill_id][8]
      @goldt      += ATTRIBUTES[skill_id][9]
    end
  end
  def forget_skill(skill_id)
    passive_skill_forget(skill_id)
    if PASSIVE_SKILLS.include?(skill_id)
      @maxhp_plus -= ATTRIBUTES[skill_id][0]
      @maxsp_plus -= ATTRIBUTES[skill_id][1]
      @str_plus   -= ATTRIBUTES[skill_id][2]
      @dex_plus   -= ATTRIBUTES[skill_id][3]
      @agi_plus   -= ATTRIBUTES[skill_id][4]
      @int_plus   -= ATTRIBUTES[skill_id][5]
      @atk_plus   -= ATTRIBUTES[skill_id][6]
      @pdef_plus  -= ATTRIBUTES[skill_id][7]
      @mdef_plus  -= ATTRIBUTES[skill_id][8]
      @goldt      -= ATTRIBUTES[skill_id][9]
    end
  end
end

class Game_Battler
  attr_accessor :goldt
  alias parameter_init initialize
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    @atk_plus = 0
    @pdef_plus = 0
    @mdef_plus = 0
    @goldt = 0
    parameter_init
  end
  
  #--------------------------------------------------------------------------
  # * Get Attack
  #--------------------------------------------------------------------------
  def atk
    n = [[base_atk + @atk_plus, 1].max, 999].min
    for state in states do n *= state.atk_rate / 100.0 end
    n = [[Integer(n), 1].max, 999].min
    return n
  end

  #--------------------------------------------------------------------------
  # * Get Defense
  #--------------------------------------------------------------------------
  def pdef
    n = [[base_pdef + @pdef_plus, 1].max, 999].min
    for i in @states
      n *= $data_states[i].pdef_rate / 100.0
    end
    return Integer(n)
  end
  
  #--------------------------------------------------------------------------
  # * Get Defense
  #--------------------------------------------------------------------------
  def mdef
    n = [[base_mdef + @mdef_plus, 1].max, 999].min
    for i in @states
      n *= $data_states[i].mdef_rate / 100.0
    end
    return Integer(n)
  end
  
  #--------------------------------------------------------------------------
  # * Set Attack
  #     new_atk : new attack
  #--------------------------------------------------------------------------
  def atk=(new_atk)
    @atk_plus += new_atk - self.atk
    @atk_plus = [[@atk_plus, -999].max, 999].min
  end
  
  #--------------------------------------------------------------------------
  # * Set Defense
  #     new_def : new defense
  #--------------------------------------------------------------------------
  def pdef=(new_pdef)
    @pdef_plus += new_pdef - self.pdef
    @pdef_plus = [[@pdef_plus, -999].max, 999].min
  end
  
  #--------------------------------------------------------------------------
  # * Set Defense
  #     new_def : new defense
  #--------------------------------------------------------------------------
  def mdef=(new_mdef)
    @mdef_plus += new_mdef - self.mdef
    @mdef_plus = [[@mdef_plus, -999].max, 999].min
  end
end

class Scene_Battle
  #--------------------------------------------------------------------------
  # * Start After Battle Phase
  #--------------------------------------------------------------------------
  def start_phase5
    $whatever = Game_Actor.new
    # Shift to phase 5
    @phase = 5
    # Play battle end ME
    $game_system.me_play($game_system.battle_end_me)
    # Return to BGM before battle started
    $game_system.bgm_play($game_temp.map_bgm)
    # Initialize EXP, amount of gold, and treasure
    exp = 0
    gold = 0
    treasures = []
    # Loop
    for enemy in $game_troop.enemies
      # If enemy is not hidden
      unless enemy.hidden
        # Add EXP and amount of gold obtained
        exp += enemy.exp
        gold += enemy.gold
        # Determine if treasure appears
        if rand(100) < enemy.treasure_prob
          if enemy.item_id > 0
            treasures.push($data_items[enemy.item_id])
          end
          if enemy.weapon_id > 0
            treasures.push($data_weapons[enemy.weapon_id])
          end
          if enemy.armor_id > 0
            treasures.push($data_armors[enemy.armor_id])
          end
        end
      end
    end
    # Treasure is limited to a maximum of 6 items
    treasures = treasures[0..5]
    # Obtaining EXP
    for i in 0...$game_party.actors.size
      actor = $game_party.actors[i]
      if actor.cant_get_exp? == false
        last_level = actor.level
        actor.exp += exp
        if actor.level > last_level
          @status_window.level_up(i)
        end
      end
    end
    gold *= $whatever.goldt
    # Obtaining gold
    $game_party.gain_gold(gold)
    # Obtaining treasure
    for item in treasures
      case item
      when RPG::Item
        $game_party.gain_item(item.id, 1)
      when RPG::Weapon
        $game_party.gain_weapon(item.id, 1)
      when RPG::Armor
        $game_party.gain_armor(item.id, 1)
      end
    end
    # Make battle result window
    @result_window = Window_BattleResult.new(exp, gold, treasures)
    # Set wait count
    @phase5_wait_count = 100
  end
end

My "solution" gives an error.
I thought that i could use the attr_accessor :goldt  in Game_Actor and then use this in Scene_Battle:
Code:
$whatever = Game_Actor.new

Then further down at line 184, i tried this:
Code:
gold *= $whatever.goldt

But this gave me this error:
Code:
Script 'Passive_Skills' line 139: ArgumentError occured.
wrong number of arguments(0 for 1)

But then i tried another thing and i used attr_accessor :goldt in the Game_Battler instead, and changed:
Code:
$whatever = Game_Actor.new

to:
Code:
$whatever = Game_Battler.new

And that works without giving me an error!
But i really can't figure out why it gives me an error when it's Game_Actor..
My intentions where that it would multiply the gold gain with the number that is in the skills "ATTRIBUTES".

So does anyone know why it gives me an error when i change it to "$whatever = Game_Actor.new"?
And if you know from just looking at the script that it won't work, could you please tell me, and maybe give me some directions on how to make it work?
Any help is appreciated^_^

Over and out - Gando
 

khmp

Sponsor

Alright no need to create a global variable to store an actor. I hijacked the for loop that determines EXP to include the gathering of all the gold multipliers of each actor in the party.

Code:
    # Obtaining EXP
    gold_mult = 0
    for i in 0...$game_party.actors.size
      actor = $game_party.actors[i]

      # Add into the gold multiplier.
      gold_mult += $game_party.actors[i].goldt

      if actor.cant_get_exp? == false
        last_level = actor.level
        actor.exp += exp
        if actor.level > last_level
          @status_window.level_up(i)
        end
      end
    end
    gold *= gold_mult

Game_Actor inherits from Game_Battler so no need to have attr_accessor :goldt in both. Is it necessary to override all the parameter methods in Game_Battler as you already have a method for adjusting the parameters in Game_Actor through skill learning. I would also change the gold multiplier to a float where its a percentage. You don't have to. Its just a design suggestion.

If its a float then the code would be:
Code:
gold += (gold * gold_mult).to_i

Good luck with it Gando! :thumb:
 
Yeah, i thought of that too.
I made it check if anyone in the party has the gold multiplier skill learned.
If someone has, it will multiply the gold gain, if not, they will get the default gold.
 

khmp

Sponsor

From the sounds of the checking you are doing you might be doing it the hard way. But I don't know so anyway you can do something like this:
Code:
gold *= gold_mult == 0 ? 1 : gold_mult
 
Aaah, you're probably right..
This is how it looks now:
Code:
gold += (gold * gold_mult == 0? 0: gold * gold_mult / 100).to_i

It will give the gold bonus in percent now instead of multiplying it with the number in ATTRIUTES.
It it seems to be working as it should. Once again, thanks for all the help khmp! :thumb:
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top