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
#==============================================================================
# ** 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
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.