RMRK is retiring.
Server is paid up for the rest of 2026, but the forum may go after that. See here for more information. Please archive or save anything you would like to keep before 2027.
Main Menu
  • Welcome to The RPG Maker Resource Kit.

[Resolved] Variable increase on level up

Started by Acolyte, June 13, 2011, 09:47:39 PM

0 Members and 1 Guest are viewing this topic.

Acolyte

I'm using an ability grid system that allows the characters to buy abilities with ability points.
class Game_Actor
  def level_up
    @level += 1
    # increment the corresponding game variable
    $game_variables[@actor_id] += 2
    for learning in self.class.learnings
      learn_skill(learning.skill_id) if learning.level == @level
    end
  end
end


This is supposed to allow each actor to gain AP on level up, but it's tied to the variables equal to the actors' IDs. Is there a way to change this so I can use a different variable for each actor?

Here's the actual ability grid script, though I don't think it matters, as I've had to rework it into a common event to be compatible with yanfly's menu system anyway.
#==============================================================================
# ** Ability Grid Setup
#==============================================================================
module Ability_Grid
  # The Ability Grid map id
  # SYNTAX: actor_id => map_id
  Maps = {
          1 => 72,
          2=>  75,
          3=>  76,
          4 => 73
         }
  # The initial position on the Ability Grid map id
  # SYNTAX: actor_id => [x,y]
  Position = {
              1 => [1,1],
              4 => [12,7]
             }
end
           
# Command name for Ability Grid
Vocab::AbilityGrid = 'Ability Grid'

#==============================================================================
# ** Font
#==============================================================================

class Font
  def marshal_dump;end
  def marshal_load(obj);end
end

#==============================================================================
# ** Bitmap
#==============================================================================

class Bitmap
  # Win32API
  RtlMoveMemory_pi = Win32API.new('kernel32', 'RtlMoveMemory', 'pii', 'i')
  RtlMoveMemory_ip = Win32API.new('kernel32', 'RtlMoveMemory', 'ipi', 'i')
  #--------------------------------------------------------------------------
  # * Dump
  #--------------------------------------------------------------------------
  def _dump(limit)
    data = "rgba" * width * height
    RtlMoveMemory_pi.call(data, address, data.length)
    [width, height, Zlib::Deflate.deflate(data)].pack("LLa*")
  end
  #--------------------------------------------------------------------------
  # * Load
  #--------------------------------------------------------------------------
  def self._load(str)
    w, h, zdata = str.unpack("LLa*"); b = new(w, h)
    RtlMoveMemory_ip.call(b.address, Zlib::Inflate.inflate(zdata), w * h * 4); b
  end
  #--------------------------------------------------------------------------
  # * Address
  #--------------------------------------------------------------------------
  def address
    buffer, ad = "xxxx", object_id * 2 + 16
    RtlMoveMemory_pi.call(buffer, ad, 4); ad = buffer.unpack("L")[0] + 8
    RtlMoveMemory_pi.call(buffer, ad, 4); ad = buffer.unpack("L")[0] + 16
    RtlMoveMemory_pi.call(buffer, ad, 4); return buffer.unpack("L")[0]
  end
end

#==============================================================================
# ** Game_System
#------------------------------------------------------------------------------
#  This class handles system-related data. Also manages vehicles and BGM, etc.
# The instance of this class is referenced by $game_system.
#==============================================================================

class Game_System
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :last_map_id
  attr_accessor :in_ability_grid
  attr_accessor :last_party_members
  attr_accessor :temp_background_bitmap
  alias dargor_vx_ag_system_initialize initialize
  def initialize
    dargor_vx_ag_system_initialize
    @last_map_id = 0
    @in_ability_grid = false
    @last_party_members = []
    @temp_background_bitmap = Bitmap.new(1,1)
  end
end

#==============================================================================
# ** 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
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor   :last_grid_x
  attr_accessor   :last_grid_y
  #--------------------------------------------------------------------------
  # * Alias Listing
  #--------------------------------------------------------------------------
  alias dargor_vx_ag_actor_setup setup
  #--------------------------------------------------------------------------
  # * Setup
  #     actor_id : actor ID
  #--------------------------------------------------------------------------
  def setup(actor_id)
    @last_grid_x = 0
    @last_grid_y = 0
    unless Ability_Grid::Position[actor_id].nil?
      @last_grid_x = Ability_Grid::Position[actor_id][0]
      @last_grid_y = Ability_Grid::Position[actor_id][1]
    end
    dargor_vx_ag_actor_setup(actor_id)
  end
end

#==============================================================================
# ** Game_Party
#------------------------------------------------------------------------------
#  This class handles the party. It includes information on amount of gold
# and items. The instance of this class is referenced by $game_party.
#==============================================================================

class Game_Party
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :actors
  attr_accessor :last_map_id
  attr_accessor :last_map_x
  attr_accessor :last_map_y
  #--------------------------------------------------------------------------
  # * Alias Listing
  #--------------------------------------------------------------------------
  alias dargor_vx_ag_party_initialize initialize
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    dargor_vx_ag_party_initialize
    @last_map_id = 0
    @last_map_x = 0
    @last_map_y = 0
  end
  #--------------------------------------------------------------------------
  # * Set Actors
  #--------------------------------------------------------------------------
  def set_actors(new_actors)
    @actors = new_actors
  end
end

#==============================================================================
# ** Scene_Map
#------------------------------------------------------------------------------
#  This class performs the map screen processing.
#==============================================================================

class Scene_Map < Scene_Base
  #--------------------------------------------------------------------------
  # * Alias Listing
  #--------------------------------------------------------------------------
  alias dargor_vx_ag_map_call_menu call_menu
  alias dargor_vx_ag_map_snapshot snapshot_for_background
  #--------------------------------------------------------------------------
  # * Determine if Menu is Called due to Cancel Button
  #--------------------------------------------------------------------------
  def call_menu
    if $game_system.in_ability_grid
      exit_ability_grid
      return
    end
    $game_system.temp_background_bitmap = Graphics.snap_to_bitmap
    dargor_vx_ag_map_call_menu
  end
  def snapshot_for_background
    if !$game_system.in_ability_grid
      dargor_vx_ag_map_snapshot
    end
  end
  #--------------------------------------------------------------------------
  # * Exit Ability Grid
  #--------------------------------------------------------------------------
  def exit_ability_grid
    fadeout(10)
    $game_party.members[0].last_grid_x = $game_player.x
    $game_party.members[0].last_grid_y = $game_player.y
    $game_party.set_actors($game_system.last_party_members)
    $game_player.refresh
    $game_map.setup($game_party.last_map_id)
    $game_player.moveto($game_party.last_map_x, $game_party.last_map_y)
    #$game_system.in_ability_grid = false
    $game_temp.next_scene = ""
    $scene = Scene_Menu.new
  end
end

#==============================================================================
# ** Scene_Menu
#------------------------------------------------------------------------------
#  This class performs the menu screen processing.
#==============================================================================

class Scene_Menu < Scene_Base
  #--------------------------------------------------------------------------
  # * Alias Listing
  #--------------------------------------------------------------------------
  alias dargor_vx_ag_menu_create_command_window create_command_window
  alias dargor_vx_ag_menu_update_command_selection update_command_selection
  alias dargor_vx_ag_menu_update_actor_selection update_actor_selection
  #--------------------------------------------------------------------------
  # * Create Command Window
  #--------------------------------------------------------------------------
  def create_command_window
    #$game_system.in_ability_grid = false
    #if Graphics.brightness == 0
    if $game_system.in_ability_grid
      $game_system.in_ability_grid = false
      Graphics.fadein(10)
      $game_temp.background_bitmap = $game_system.temp_background_bitmap
      create_menu_background
    end
    commands = $game_system.menu_commands
    $game_system.add_menu_command(commands.size-1, Vocab::AbilityGrid)
    dargor_vx_ag_menu_create_command_window
  end
  #--------------------------------------------------------------------------
  # * Update Command Selection
  #--------------------------------------------------------------------------
  def update_command_selection
    dargor_vx_ag_menu_update_command_selection
    command = @command_window.commands[@command_window.index]
    if Input.trigger?(Input::B)
      $game_temp.next_scene = "map"
    end
    if Input.trigger?(Input::C)
      Sound.play_decision
      case @command_window.commands[@command_window.index]
      when Vocab::AbilityGrid
        start_actor_selection
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Update Actor Selection
  #--------------------------------------------------------------------------
  def update_actor_selection
    dargor_vx_ag_menu_update_actor_selection
    if Input.trigger?(Input::C)
      Sound.play_decision
      case @command_window.commands[@command_window.index]
      when Vocab::AbilityGrid
        actor_id = $game_party.members[@status_window.index].id
        x = $game_party.members[@status_window.index].last_grid_x
        y = $game_party.members[@status_window.index].last_grid_y
        proceed_ability_grid(actor_id,x,y)
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Proceed Ability Grid
  #--------------------------------------------------------------------------
  def proceed_ability_grid(actor_id, x, y)
    $game_system.in_ability_grid = true
    set_ability_grid_party
    $game_map.setup(Ability_Grid::Maps[actor_id])
    $game_map.autoplay
    $game_player.moveto(x,y)
    $scene = Scene_Map.new
  end
  #--------------------------------------------------------------------------
  # * Set Ability Grid Party
  #--------------------------------------------------------------------------
  def set_ability_grid_party
    new_actor = $game_party.actors[@status_window.index]
    $game_system.last_party_members = $game_party.actors.dup
    $game_party.last_map_id = $game_map.map_id
    $game_party.last_map_x = $game_player.x
    $game_party.last_map_y = $game_player.y
    $game_party.set_actors([new_actor])
    $game_player.refresh
  end
end


cozziekuns


module COZZIEKUNS
  ACTOR_VARIABLES ={
  # Actor ID => Variable Id
    0 => 10,
    1 => 20,
    2 => 30,
    3 => 40,
    4 => 50,
  }
end

#==============================================================================
# ** 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
  #--------------------------------------------------------------------------
  # * Level Up
  #--------------------------------------------------------------------------
  alias coz_whatever_ga_level_up_4895 level_up
  def level_up
    coz_whatever_ga_level_up_4895
    $game_variables[COZZIEKUNS::ACTOR_VARIABLES[@actor_id]] += 2
  end
end


Just replace your old level up script with this one. It's pretty self explanatory.

Acolyte