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.
Gradual leveling

0 Members and 1 Guest are viewing this topic.

pokeball TDSOffline
***
Rep:
Level 84
-T D S-
Silver - GIAW 11 (Hard)Silver - Game In A Week VII
Gradual Leveling
Version: 1.1
Author: TDS
Date: August 8, 2011

Version History


  • 1.0 08.08.2011 - Public release.
  • 1.1 08.09.2011 - Improved and shortened code.

Description


This script modifies attributes such as HP, MP, Attack etc, So that they are gained as you receive experience rather than all at once when you level up.

Features

  • Modifies attributes based on experience gained.

Instructions

Place it below any scripts that change actor stats and it should work.

Script


Code: [Select]
#==============================================================================
# ** TDS Gradual Leveling
#    Ver: 1.1
#------------------------------------------------------------------------------
#  * Description:
#  This script modifies attributes such as HP, MP, Attack etc, So that they are
#  gained as you receive experience rather than all at once when you level up.
#------------------------------------------------------------------------------
#  * Features:
#  Modifies characters attributes based on their experience.
#------------------------------------------------------------------------------
#  * Instructions:
#  None.
#------------------------------------------------------------------------------
#  * Notes:
#  None.
#------------------------------------------------------------------------------
#  * New Methods:
#  Game_Actor:
#  - gradual_parameter(parameter)
#    ^ Used to calculate the attribute based on experience.
#------------------------------------------------------------------------------
#  * Aliased Methods:
#  Game_Actor:
#  - change_exp(exp, show)
#    ^ Aliased to modify HP/MP when experience changes.
#  - base_maxhp 
#  - base_maxmp
#  - base_atk
#  - base_def
#  - base_spi
#  - base_agi
#    ^ Above methods aliased to add gradual parameter value.
#------------------------------------------------------------------------------
# WARNING:
#
# Do not release, distribute or change my work without my expressed written
# consent, doing so violates the terms of use of this work.
#
# If you really want to share my work please just post a link to the original
# site.
#
# * Not Knowing English or understanding these terms will not excuse you in any
#   way from the consequenses.
#==============================================================================


#==============================================================================
# ** Game_Actor
#------------------------------------------------------------------------------
#  This class handles actors. It's used within the Game_Actors class
# ($game_actors) and referenced by the Game_Party class ($game_party).
#==============================================================================

class Game_Actor < Game_Battler
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias tds_gradual_leveling_game_actor_change_exp                 change_exp
  #--------------------------------------------------------------------------
  # * Alias listing and method definition
  #-------------------------------------------------------------------------- 
  # Basic Stats Array as symbols
  stats = [:base_maxhp, :base_maxmp, :base_atk, :base_def, :base_spi, :base_agi] 
  # Go Through Stats
  stats.each_with_index {|stat, i|
    # Alias Method
    alias_method ("tds_gradual_leveling_game_actor_#{stat}".to_sym, stat)
    # Define Stat Method
    define_method (stat) {
      # Return Base Stat with Gradual Experience Value
      return self.send ("tds_gradual_leveling_game_actor_#{stat}") + gradual_parameter(i)
     }
  }
  #--------------------------------------------------------------------------
  # * Determine Gradual Parameter Value
  #     parameter : parameter (0: Max HP, 1: Max MP, 2: Atk,etc)
  #--------------------------------------------------------------------------
  def gradual_parameter(parameter)
    # Determine Actor Next Level
    next_level = @level + 1
    # Return 0 if There is no exp for the next level
    return 0 if @exp_list[next_level] == nil or @exp_list[next_level] == 0   
    # Required Exp for next level
    lvl_exp = @exp_list.at(@level + 1) - @exp_list.at(@level)   
    # Current Experience towards next level
    exp = @exp - @exp_list.at(@level) 
    # Total Experience %
    total_exp = exp.to_f / lvl_exp.to_f * 100   
    # Parameter value difference
    difference = (actor.parameters[parameter, next_level] - actor.parameters[parameter, @level])
    # Return Calculated Percent of difference based on exp %
    return ((difference * total_exp) / 100.0).to_i
  end
  #--------------------------------------------------------------------------
  # * Change Experience
  #     exp  : New experience
  #     show : Level up display flag
  #--------------------------------------------------------------------------
  def change_exp(exp, show)
    # Get HP Before Exp change
    before_hp = maxhp
    # Get MP Before Exp change
    before_mp = maxmp   
    # Run Original Method
    tds_gradual_leveling_game_actor_change_exp(exp, show)     
    # Adjust Current HP if there has been a change in Max HP
    @hp = [@hp + (maxhp - before_hp), maxhp].min if maxhp > before_hp
    # Adjust Current MP if there has been a change in Max MP
    @mp = [@mp + (maxmp - before_mp), maxmp].min if maxmp > before_mp
  end
end


Credit


  • TDS

Thanks

  • modern algebra for improving the code and reducing it.
  • cozziekuns

Support


On this topic.

Known Compatibility Issues

There could be compatibility issues with scripts that modify actor stats.


Author's Notes


None for now.

Restrictions

Only for use in non-commercial games.
« Last Edit: August 09, 2011, 07:48:48 PM by TDS »

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Best Member2012 Best RPG Maker User (Scripting)2012 Favorite Staff Member2012 Most Mature 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 split the topic and created a new topic in scripts with them: Concepts in RGSS/2. I hope that it will invite us to have further discussions like this one.

Anyway and again, nice script TDS.