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.

Script edit.

I am creating a RMVX game and I have found a level up script.  The problem is that the script keeps adding a new command to the menu, when there is already one.  I am using the default menu system for RMVX.   There is no clash with any scripts.

The script is KGC's Distribute Parameter

Code:
#_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_
#_/â—†     Attribute Point Stat Distribution - KGC_DistributeParameter     Ã¢â€”† VX â—†
#_/â—‡                        Last Update: 2008/04/10                           Ã¢â€”‡
#_/â—†                 Original translation by Mr. Anonymous                    â—†
#_/â—†              Extended annotation and updates by Touchfuzzy               Ã¢â€”†
#_/-----------------------------------------------------------------------------
#_/                       Ã¢â€”† 2008/04/10 UPDATE [MRA] â—† 
#_/  Added toggle to display actor sprites in the Distribute Parameter window
#_/   next to the actor name. Also included actor's class in the same window.
#_/    Added by Mr. Anonymous
#_/-----------------------------------------------------------------------------
#_/                       Ã¢â€”† 2008/04/01 UPDATE [MRA] â—† 
#_/  Added toggle to display actor's AP and position on the status screen, and 
#_/   toggle to enable the display of Accuracy, Evasion, and Critical parameters 
#_/   on the status screen. 
#_/-----------------------------------------------------------------------------
#_/                       Ã¢â€”† 2008/03/23 UPDATE [KGC] â—†          
#_/   Updated to latest version of KGC Script.  Fixes a bug in the calculation
#_/     of Max Ap.
#_/-----------------------------------------------------------------------------
#_/                       Ã¢â€”† 2008/03/10 UPDATE [TF] â—†          
#_/   Level-based maximums moved into GAIN_PARAMETERS charts and MAXRP equation
#_/     moved into GAIN_PARAMETERS charts so that it can be changed for each
#_/     character/class.
#_/-----------------------------------------------------------------------------
#_/                       Ã¢â€”† 2008/03/09 UPDATE [TF] â—†          
#_/   Level-based maximums & separate maxes for current status bars.
#_/-----------------------------------------------------------------------------
#_/                       Ã¢â€”† 2008/03/08 UPDATE [KGC] â—†
#_/   Updated to the newest KGC version through the efforts of Touchfuzzy,
#_/  which added Class-specific parameter tables and other features/fixes.
#_/=============================================================================
#_/                       Ã¢â€”† Script Commands â—†
#_/  These commands are used in "Script" function in the third page of event
#_/   commands under "Advanced".
#_/
#_/ * gain_rp(ActorID, Value)
#_/    Increases the MaxRP of a given actor.
#_/
#_/ * reset_distributed_count(ActorID)
#_/    Resets the distributed RP of a given actor.
#_/
#_/ * call_distribute_parameter(ActorID)
#_/    Calls the Distribute Parameter screen for a given actor.
#_/
#_/=============================================================================
#_/ Installation: Insert this script above Main.
#_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_

#==============================================================================#
#                           Ã¢Ëœâ€¦ Customization ★                                  #
#==============================================================================#

module KGC
 module DistributeParameter
  #                      â—† Distribution Tables â—†
  # Here you may customize the costs and increase rates of specific parameters.
  # The order in which these costs and increase rates are set are as follows:
  #                     [IPC, IPSG, MAP, PCI, PSGI, SBM]
  #                                Key:
  # IPC = Initial Point Cost. This is how many AP it cost to buy the first
  #       point of this parameter.
  #
  # IPSG = Initial Point Stat Growth. This is how much the stat will go up with
  #        the first point of this parameter.
  #                                              
  # MAP = Maximum Attribute Points. The maximum amount of AP that can be spent  
  #       on this stat.  You may also put a level based equation in this but
  #       remember that if you put in an equation it is IMPORTANT that you put
  #       quotation marks ("") around it and to use level in all lower case.
  #       Example: "level"
  #
  # PCI = Point Cost Increase.  For every AP spent in this parameter the cost
  #       of this parameter increases by this amount.
  #
  # PSGI = Point Stat Growth Increase.  For every AP spent in this parameter
  #        the number of points you gain in the stat increases by this much.
  #
  #                           A Touchfuzzy Update
  # SBM = Separate Bar Maximum. This will let you use a different maximum for
  #       the bar in the current status section.  Useful if using a level based
  #       MAP and wish to show the bar at max level instead of current.  If
  #       this is omitted the script instead uses the MAP (or the result of the
  #       equation your maximum is based on).
  #
  #   Also, if you completely remove a line (e.g. ":hit => [1, 1, 20, 0.7],")
  #   it will remove it from the distribution screen altogether.
  #   Very useful if your project doesn't require a specific stat.
  #                         Ã¢â€”† AP Gain Rate â—†
  #  I added this in to the GAIN_PARAMETER tables so that you can use seperate
  #  equations for different characters and classes.
  #  This is the equation that determines your total AP gained every level.
  #  (Character Level to the 0.25th power + 2) * Level
  #  This causes you to start at 3 points per level and increase slightly over
  #  time.
  #  As an example if you wish to gain a static 3 points per level write it as
  #  :maxrpexp = "level * 3"
  
  GAIN_PARAMETER = {
    :maxhp => [1, 30, 100, 0.4, 2],    # Maximum HP
    :maxmp => [1,  5, 100, 0.4, 0.5],  # Maximum MP
    :atk   => [1,  2, 100, 0.4, 0.5],  # Attack
    :def   => [1,  2, 100, 0.4, 0.5],  # Defense
    :spi   => [1,  2, 100, 0.4, 0.5],  # Spirit (AKA Intelligence)
    :agi   => [1,  2, 100, 0.4, 0.5],  # Agility
    :hit   => [1,  1, 50, 0.9],       # Hit Percentage (AKA Accuracy)
    :eva   => [2,  1, 20, 1.5],       # Evasion
    :cri   => [2,  1, 20, 1.5],       # Critical
    :maxrpexp => ["(level ** 0.25 + 2.0) * level"]  # Max AP
  } # Do not remove this!

  #              â—† Individual Actor Gain Parameter Tables â—†
  #  You may choose to manually specify an individual actor's gain parameters.
  #  To do so, use the same format as above GAIN_PARAMETER table but instead
  #  use PERSONAL_GAIN_PARAMETER [n] (Where n = Actor ID)
  #  Any parameter you do not set in this table will instead draw from the
  #  GAIN_PARAMETER chart.
  #
  #  Example:
  # PERSONAL_GAIN_PARAMETER[1] = {
  # :maxhp => [2, 20, 50, 0.5,   5],    
  # :maxmp => [1, 10, 30, 0.3, 0.5],  
  # :atk   => [1,  1, 30, 0.3, 0.5],  
  # :def   => [1,  2, 30, 0.4, 0.5],  
  # :spi   => [1,  2, 50, 0.5, 0.8],  
  # :agi   => [1,  2, 30, 0.4, 0.6],  
  # :hit   => [1,  1, 20, 0.7],      
  # :eva   => [1,  1, 20, 0.7],      
  # :cri   => [1,  1, 20, 0.7],      
  # :maxrpexp => ["(level ** 0.25 + 2.0) * level"]
  # }
    PERSONAL_GAIN_PARAMETER = []  # Do not remove or alter this!
  #            ★ Insert Custom Actor Gain Tables Below Here ★ 

  
  
  
  #            ★ Insert Custom Actor Gain Tables Above Here ★ 

  #               Ã¢â€”† Class-Specific Gain Parameter Tables â—†
  #  You may choose to manually specify an entire class's gain parameters.
  #  To do so, use the same format as above GAIN_PARAMETER table but instead
  #  use CLASS_GAIN_PARAMETER [n] (Where n = Number of class in the database)
  #  Any parameter you do not set in this table will instead draw from the
  #  GAIN_PARAMETER chart. Also note that class gain parameters take the highest
  #  priority.
    CLASS_GAIN_PARAMETER = [] # Do not remove or alter this!
  #            ★ Insert Custom Class Gain Tables Below Here ★ 

  
  
  
  #            ★ Insert Custom Class Gain Tables Above Here ★ 

  # â—† AP = Attribute Points. These settings are for the AP Distrubution Screen.
  #  VOCAB_RP appears at the top of the column which lists the AP cost of
  #  the parameter
  VOCAB_RP   = "Cost"

  # VOCAB_RP_A appears next to where it lists your current and total AP.
  VOCAB_RP_A = "AP"

  #                        â—† Extended Vocabulary â—†
  #  Allows you to change the text of Hit Ratio, Evasion, and Critical on the
  #   distribution screen.
  VOCAB_PARAM = {
    :hit => "ACU",       # Hit Ratio
    :eva => "EVA",        # Evasion
    :cri => "CRI",        # Criticals
  }
  #  Text of the menu title for the AP Distribution Screen.
  DISTRIBUTE_SCENE_CAPTION = "AP Distribution - Press L or R to switch characters.  Used AP cannot be reclaimed."

  #  Allows you to change the color of the guages that appear under the stats
  #   side bar. The color can also be determined by a numerical expression.
  #  Example: GAUGE_START_COLOR = Color.new(255, 0, 0)  <- This is red.
  #  This is the fill color for the early phase of the guage.
  GAUGE_START_COLOR = 28
  #  This is the fill color for the late phase of the guage. (When full)
  GAUGE_END_COLOR   = 29

  #                   Ã¢â€”† Menu Command Button & Text â—†
  #  When USE_MENU_DISTRIBUTE_PARAMETER_COMMAND = true,
  #  the AP Distribution System is added to the menu under "Quit Game".
  #  When false, it does not. (Obviously)
  USE_MENU_DISTRIBUTE_PARAMETER_COMMAND = true
  #  Allows you to change the text for this button on the main command menu.
  VOCAB_MENU_DISTRIBUTE_PARAMETER       = "Level Up"
  
  #                    â—† Parameter Re-distribution â—†
  #  This affects whether the player can delevel the parameters that have
  #  been increased.
  #  true  : Allows the player to reassign AP.
  #  false : Prevents the player from unassigning AP if set to false.
  ENABLE_REVERSE_DISTRIBUTE = false
  
  #                        â—† AP in Status Window â—†
  # The following four features have been scripted by Mr. Anonymous.
  #  This toggle allows you to enable/disable the AP display on the status 
  #   screen.
  SHOW_STATUS_RP = true
  #  This toggle allows you to adjust the position of the AP display on the
  #   status screen. (If SHOW_STATUS_RP = true)
  #  0. Below Actor's Face Image
  #  1. Below Actor's Parameters
  SHOW_STATUS_RP_POS = 1
  
  #                   Ã¢â€”† Extra Parameters in Status Window â—†
  #  This toggle allows you to enable/disable the parameters for accuracy, 
  #   evasion, and critical below the regular paramaters (STR, DEF, SPI, AGI)
  SHOW_STATUS_EX_PARAMS = true
  
  #              â—† Call DistributeParameter from the Status Window â—†
  #  This allows you to change what key/button is pressed on the status window
  #   to shift to the DistributeParameter window.
  #  When set to nil, this is disabled. ( CALL_DISTPARAMKEY = Input::nil )
  CALL_DISTPARAMKEY = Input::X   # On the keyboard, button X is the A key.
  
  #                   Ã¢â€”† Show Actor Graphic â—†
  #  This toggle allows you to enable/disable the actor sprite in the Distribute
  #   Parameter window next to the actor name.
  #  true = Show the sprite.
  #  false = Do not show.
  SHOW_SPRITE = true
  
 end
end

#------------------------------------------------------------------------------#

$imported = {} if $imported == nil
$imported["DistributeParameter"] = true

module KGC::DistributeParameter
  PARAMS = [:maxhp, :maxmp, :atk, :def, :spi, :agi, :hit, :eva, :cri]
end

#==============================================================================
# â–  Vocab
#==============================================================================

module Vocab

  def self.hit
    return KGC::DistributeParameter::VOCAB_PARAM[:hit]
    return $data_system.terms.hit    # Added 4/1/08
  end

  def self.eva
    return KGC::DistributeParameter::VOCAB_PARAM[:eva]
    return $data_system.terms.eva    # Added 4/1/08
  end

  def self.cri
    return KGC::DistributeParameter::VOCAB_PARAM[:cri]
    return $data_system.terms.cri    # Added 4/1/08
  end

  def self.rp
    return KGC::DistributeParameter::VOCAB_RP
  end

  def self.rp_a
    return KGC::DistributeParameter::VOCAB_RP_A
  end

  def self.distribute_parameter
    return KGC::DistributeParameter::VOCAB_MENU_DISTRIBUTE_PARAMETER
  end
end

#==============================================================================
# â–¡ KGC::Commands
#==============================================================================

module KGC::Commands
  module_function

  def check_distribution_values
    (1...$data_actors.size).each { |i|
      actor = $game_actors[i]
      actor.check_distribution_values
      actor.calc_distribution_values
    }
  end

  def gain_rp(actor_id, value)
    actor = $game_actors[actor_id]
    return if actor == nil
    actor.gain_rp(value)
  end

  def reset_distributed_count(actor_id)
    actor = $game_actors[actor_id]
    return if actor == nil
    actor.clear_distribution_values
    actor.calc_distribution_values
  end

  def call_distribute_parameter(actor_index = 0)
    return if $game_temp.in_battle
    $game_temp.next_scene = :distribute_parameter
    $game_temp.next_scene_actor_index = actor_index
  end
end

#==============================================================================
# â–  Game_Interpreter
#==============================================================================

class Game_Interpreter
  include KGC::Commands
end

#==================================End Class===================================#

#==============================================================================
# â–  Game_Battler
#==============================================================================

class Game_Battler

  alias clear_extra_values_KGC_DistributeParameter clear_extra_values
  def clear_extra_values
    clear_extra_values_KGC_DistributeParameter

    clear_distribution_values
    calc_distribution_values
  end

  def clear_distribution_values
    @distributed_count = {}
    KGC::DistributeParameter::PARAMS.each { |param|
      @distributed_count[param] = 0
    }
  end

  def check_distribution_values
    last_distributed_count = @distributed_count

    clear_distribution_values

    @distributed_count = last_distributed_count if last_distributed_count !=

nil
  end

  def calc_distribution_values

  end
end

#==================================End Class===================================#

#==============================================================================
# â–  Game_Actor
#==============================================================================

class Game_Actor < Game_Battler

  alias initialize_KGC_DistributeParameter initialize
  def initialize(actor_id)
    @actor_id = actor_id
    @class_id = $data_actors[actor_id].class_id
    initialize_KGC_DistributeParameter(actor_id)
  end

  def gain_parameter_list
    result = KGC::DistributeParameter::GAIN_PARAMETER
    list = KGC::DistributeParameter::PERSONAL_GAIN_PARAMETER[self.id]
    result = result.merge(list) if list != nil
    list = KGC::DistributeParameter::CLASS_GAIN_PARAMETER[self.class_id]
    result = result.merge(list) if list != nil
    return result
  end

  def calc_distribution_values
    @rp_cost = 0
    @distributed_param = {}
    gain_parameter_list.each { |k, v|
      next if v == nil
      cost = 0
      param = 0
      distributed_count(k).times { |i|
        cost_plus   = v[0]
        cost_plus  += v[3] * i if v[3] != nil
        param_plus  = v[1]
        param_plus += v[4] * i if v[4] != nil
        cost  += Integer(cost_plus)
        param += Integer(param_plus)
      }
      @rp_cost += [Integer(cost), 0].max
      @distributed_param[k] = Integer(param)
      # (Original)
      #@rp_cost += [Integer(cost), 0].max
      #@distributed_param[k] = Integer(param)
    }
  end

  def distributed_param(param)
    return 0 if @distributed_param == nil
    return 0 if @distributed_param[param] == nil
    return @distributed_param[param]
  end

  alias base_maxhp_KGC_DistributeParameter base_maxhp
  def base_maxhp
    n = base_maxhp_KGC_DistributeParameter + distributed_param(:maxhp)
    return n
  end

  alias base_maxmp_KGC_DistributeParameter base_maxmp
  def base_maxmp
    n = base_maxmp_KGC_DistributeParameter + distributed_param(:maxmp)
    return n
  end

  alias base_atk_KGC_DistributeParameter base_atk
  def base_atk
    n = base_atk_KGC_DistributeParameter + distributed_param(:atk)
    return n
  end

  alias base_def_KGC_DistributeParameter base_def
  def base_def
    n = base_def_KGC_DistributeParameter + distributed_param(:def)
    return n
  end

  alias base_spi_KGC_DistributeParameter base_spi
  def base_spi
    n = base_spi_KGC_DistributeParameter + distributed_param(:spi)
    return n
  end

  alias base_agi_KGC_DistributeParameter base_agi
  def base_agi
    n = base_agi_KGC_DistributeParameter + distributed_param(:agi)
    return n
  end

  alias hit_KGC_DistributeParameter hit
  def hit
    n = hit_KGC_DistributeParameter + distributed_param(:hit)
    return n
  end

  alias eva_KGC_DistributeParameter eva
  def eva
    n = eva_KGC_DistributeParameter + distributed_param(:eva)
    return n
  end

  alias cri_KGC_DistributeParameter cri
  def cri
    n = cri_KGC_DistributeParameter + distributed_param(:cri)
    return n
  end

  def maxrp
    gain = gain_parameter_list[:maxrpexp]
    n = Integer(eval(gain[0]))
    return [n + maxrp_plus, 0].max
  end
  
=begin (Original)
    def maxrp
    n = Integer(eval(KGC::DistributeParameter::MAXRP_EXP))
    return [n + maxrp_plus, 0].max
  end
=end

  def maxrp_plus
    @maxrp_plus = 0 if @maxrp_plus == nil
    return @maxrp_plus
  end

  def rp
    return [maxrp - @rp_cost, 0].max
  end

  def distributed_count(param)
    clear_distribution_values if @distributed_count == nil
    @distributed_count[param] = 0 if @distributed_count[param] == nil
    return @distributed_count[param]
  end

  def gain_rp(value)
    @maxrp_plus = maxrp_plus + value
  end

  def gain_distributed_count(param, value = 1)
    n = distributed_count(param)
    @distributed_count[param] += value if n.is_a?(Integer)
  end

  def rp_growth_effect(param, reverse = false)
    gain = gain_parameter_list[param]
    return if gain == nil

    if reverse
      return if distributed_count(param) == 0
    else
      return unless can_distribute?(param)
    end

    gain_distributed_count(param, reverse ? -1 : 1)
    calc_distribution_values
  end

  def can_distribute?(param)
    gain = gain_parameter_list[param]
    # (Original)
    if gain[2] < 0
      gain[2] = gain[2] * -1
      n = Integer(eval(KGC::DistributeParameter::LEVEL_MAX_DISTRIBUTABLE[gain[2]]))
      gain[2] = n
    end
    return false if gain == nil
    return false if self.rp < distribute_cost(param)
    return false if gain[2] <= distributed_count(param)

    return true
  end

  def distribute_cost(param)
    gain = gain_parameter_list[param]
    return 0 if gain == nil

    n = gain[0]
    n += gain[3] * distributed_count(param) if gain[3] != nil
    return [Integer(n), 0].max
  end

  def distribute_gain(param)
    gain = gain_parameter_list[param]
    return 0 if gain == nil

    n = gain[1]
    n += gain[4] * distributed_count(param) if gain[4] != nil
    return Integer(n)
  end
end

#==================================End Class===================================#

#==============================================================================
# â–  Window_Base
#==============================================================================

class Window_Base < Window

  def rp_color(actor)
    return (actor.rp == 0 ? knockout_color : normal_color)
  end

  def distribute_gauge_color1
    color = KGC::DistributeParameter::GAUGE_START_COLOR
    return (color.is_a?(Integer) ? text_color(color) : color)
  end

  def distribute_gauge_color2
    color = KGC::DistributeParameter::GAUGE_END_COLOR
    return (color.is_a?(Integer) ? text_color(color) : color)
  end

  def draw_actor_rp(actor, x, y, width = 120)
    self.contents.font.color = system_color
    self.contents.draw_text(x, y, 40, WLH, Vocab::rp_a)
    self.contents.font.color = rp_color(actor)
    xr = x + width
    if width < 120
      self.contents.draw_text(xr - 40, y, 40, WLH, actor.rp, 2)
    else
      self.contents.draw_text(xr - 90, y, 40, WLH, actor.rp, 2)
      self.contents.font.color = normal_color
      self.contents.draw_text(xr - 50, y, 10, WLH, "/", 2)
      self.contents.draw_text(xr - 40, y, 40, WLH, actor.maxrp, 2)
    end
    self.contents.font.color = normal_color
  end

  def draw_actor_distribute_gauge(actor, param, x, y, width = 120)
    gain = actor.gain_parameter_list[param]
    return if gain == nil
    if gain[5] == nil
      n = 2
    else
      n = 5
    end
    gw = width * actor.distributed_count(param) / [gain[n], 1].max
    gc1 = distribute_gauge_color1
    gc2 = distribute_gauge_color2
    self.contents.fill_rect(x, y + WLH - 8, width, 6, gauge_back_color)
    self.contents.gradient_fill_rect(x, y + WLH - 8, gw, 6, gc1, gc2)
  end
  #=============================================================================
  #   Added by Mr. Anonymous ( 4/1/08 )
  # Sets up the initial parameters and the entended/extra parameters.
  #=============================================================================
  if KGC::DistributeParameter::SHOW_STATUS_EX_PARAMS
    alias draw_actor_parameter_KGC_DistributeParameter draw_actor_parameter
    def draw_actor_parameter(actor, x, y, type)
      case type
        when 0
          parameter_name = Vocab::atk
          parameter_value = actor.atk
        when 1
          parameter_name = Vocab::def
          parameter_value = actor.def
        when 2
          parameter_name = Vocab::spi
          parameter_value = actor.spi
        when 3
          parameter_name = Vocab::agi
          parameter_value = actor.agi
        when 4
          parameter_name = Vocab::hit
          parameter_value = actor.hit
        when 5
          parameter_name = Vocab::eva
          parameter_value = actor.eva
        when 6
          parameter_name = Vocab::cri
          parameter_value = actor.cri
       end
       self.contents.font.color = system_color
       self.contents.draw_text(x, y, 120, WLH, parameter_name)
       self.contents.font.color = normal_color
       self.contents.draw_text(x + 120, y, 36, WLH, parameter_value, 2)
     end
  end
end

#==================================End Class===================================#

#==============================================================================
# â–  Window_Command
#==============================================================================

class Window_Command < Window_Selectable
  unless method_defined?(:add_command)

  def add_command(command)
    @commands << command
    @item_max = @commands.size
    item_index = @item_max - 1
    refresh_command
    draw_item(item_index)
    return item_index
  end

  def refresh_command
    buf = self.contents.clone
    self.height = [self.height, row_max * WLH + 32].max
    create_contents
    self.contents.blt(0, 0, buf, buf.rect)
    buf.dispose
  end

  def insert_command(index, command)
    @commands.insert(index, command)
    @item_max = @commands.size
    refresh_command
    refresh
  end

  def remove_command(command)
    @commands.delete(command)
    @item_max = @commands.size
    refresh
  end
 end
end

#==================================End Class===================================#

#==============================================================================
# â–  Window_Status
#==============================================================================
# Added by Mr. Anonymous  ( 4/1/08 )
# Checks SHOW_STATUS_RP's value, if true RP is added to Status Window.
#==============================================================================
if KGC::DistributeParameter::SHOW_STATUS_RP
  class Window_Status < Window_Base
  #--------------------------------------------------------------------------
  # â—
 

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