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.

Changing the character

Some one knows any way to make a charecter change into another when it levels up? Some other way then puting a 'Parallel Process' event the chaking the level of the party member on every map and changing the member if the condition met?
 
Try this out...

Insert this script right above "Main"

Code:
 class Game_Actor
   
  #--------------------------------------------------------------------------
  # 04DEC07 - Added "Change Character Graphic with Level" code - Brew
  #
  #  Create a character set named <actor_name>_<level>.png
  #  in the Graphics\Characters\ folder.
  #  For example, to change Aluxes graphic when he hits level 5,
  #  Create a character set named "Aluxes_5.png"
  #--------------------------------------------------------------------------
  # * Change Level
  #     level : new level
  #--------------------------------------------------------------------------
  def exp=(exp)
    @exp = [[exp, 9999999].min, 0].max
    # Level up
    while @exp >= @exp_list[@level+1] and @exp_list[@level+1] > 0
      @level += 1
      # Check to see if there is a new graphic for this level
      new_graphic = "#{@name}_#{@level}.png"
      if FileTest.exist?("Graphics\\Characters\\#{new_graphic}")
        # Change the character graphic
        set_graphic(new_graphic, @character_hue, @battler_name, @battler_hue)
        $game_player.refresh
      end
      # Learn skill
      for j in $data_classes[@class_id].learnings
        if j.level == @level
          learn_skill(j.skill_id)
        end
      end
    end
    # Level down
    while @exp < @exp_list[@level]
      @level -= 1
    end
    # Correction if exceeding current max HP and max SP
    @hp = [@hp, self.maxhp].min
    @sp = [@sp, self.maxsp].min
  end
  
  def level=(level)
    # Check up and down limits
    level = [[level, $data_actors[@actor_id].final_level].min, 1].max
    # Check to see if there is a new graphic for this level
    new_graphic = "#{@name}_#{level}.png"
    if FileTest.exist?("Graphics\\Characters\\#{new_graphic}")
      # Change the character graphic
      set_graphic(new_graphic, @character_hue, @battler_name, @battler_hue)
      $game_player.refresh
    end
    # Change EXP
    self.exp = @exp_list[level]
  end
end

See the comments at the top to create the new graphic.

Be Well

Seph, feel free to check this for 'brain farts'! :)
 
I must teach you the power of the alias function Brew. ;)

If you use the alias, you don't need to even tough the exp= method.

Code:
class Game_Actor
  alias_method :brew_levelgraphicchange_gmactr_cn, :character_name
  alias_method :brew_levelgraphicchange_gmactr_bn, :battler_name
  def character_name
    name = brew_levelgraphicchange_gmactr_cn.dup
    # this is a better way to test if a file is included
    begin
      bitmap = RPG::Cache.character("#{name}_#{@level}", @character_hue)
      name += "_#{@level}"
    rescue
    end
    return name
  end
  def battler_name
    name = brew_levelgraphicchange_gmactr_bn.dup
    # this is a better way to test if a file is included
    begin
      bitmap = RPG::Cache.battler("#{name}_#{@level}", @battler_hue)
      name += "_#{@level}"
    rescue
    end
    return name
  end
end

Now, this uses the character/battler name. I never suggest using actual character names, just graphical filenames. 001-Fighter01_1.

Let me know if there's any part of the code you don't understand Brew. I would be happy to explain any of it to you.
 
Cool, I get most of it.

Scratching my head on:

is "alias_method" the same as "alias"?

Isn't "character_name" a property?  (didn't know I could alias a property to a method)

why do we need the '.dup'?  (we're not dealing with pointers, are we?)

when does the new "character_name" method get called?

I still need to call 'set_graphic' from the exp= or level= methods?

Or, we need a $game_player.refresh somewhere...

If you try this out, using an event to change the exp or level, it doesn't change the graphic of the current player sprite. If I go to the menu, which calls character_name, it changes the graphic in the menu.  (same if you test it in battle)


Thanks
 
So many questions... lol

1) is "alias_method" the same as "alias"?

Yes, it is. I use alias_method because of the SDK. The SDK has a alias log method, that aliases the alias_method, to auto-log methods. XD

2) Isn't "character_name" a property?  (didn't know I could alias a property to a method)

You can alias a method, and...
Code:
class Game_Actor
  attr_reader :character_name

Creates a method that returns the instance making it public by accessing the character_name method (hence, public instance variables).

3) why do we need the '.dup'?  (we're not dealing with pointers, are we?)

Yeah, that's why we dup. I honestly can't say for sure if we need to do it (because I am too lazy to test 85% of the code I give out), but I believe we do, as the original method returns an instance, and modifying it modifies the pointers and all that jazz. I hate pointers. They always get me.

4) when does the new "character_name" method get called?

Anywhere. All Game_Actor objects are readable by accessing the $game_actor[actor_id], and because character_name is a method that returns the instance, any place in the game can read this instance. In our instance, Sprite_Character and Sprite_Battler read this method in their update methods. They set the bitmaps.

5)
I still need to call 'set_graphic' from the exp= or level= methods?

Or, we need a $game_player.refresh somewhere...

If you try this out, using an event to change the exp or level, it doesn't change the graphic of the current player sprite. If I go to the menu, which calls character_name, it changes the graphic in the menu.  (same if you test it in battle)

You shouldn't have too, but I will look into it.
 
Ah, I got it. (attr_reader).

I tested it without the .dup, and it works the same. ok.

I don't 'hate' pointers, they can be really handy. What drives me nuts is
inconsistent use of them in libraries.

4) character_name is not getting called when Exp or Level gets changed. (thus the reason I overloaded those methods)
I don't see anywhere else that $game_player.refresh gets called, so I'm pretty sure we have to force it.
I see where Sprite_Character is checking & setting:
@character_name = @character.character_name
but that's defined in the Game_Character class, not in Game_Actor.
Where does the filename get transferred from Game_Actor to Game_Character?
(in the refresh method of Game_Player?)

It also looks like Spriteset_Map, should refresh the player with:
@character_sprites.push(Sprite_Character.new(@viewport1, $game_player))

but the sprite isn't changing when I transfer maps either.

my brain hurts!

thanks
 
So you can make the script to change the battler too?
P.S: I don't get it, how people know how to script? :O I learned once scripting and I know some basic methods but I just don't know what to do on a real script :(
 
You can do this really easily with Common events, I think

Just set a Common event so that it has the conditional or whatever "When X is level Y or more" and then put change character/graphic, or whatever.

Set it to Parallel Process, and have it be activated by a really early switch in the game (like... a "beginning cutscene" switch or something)

Then it should work once you reach that level.
 

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