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.

A simple script I think

Hello, im working on my game where you need to press 'D' button ('Z' in RMXP) to change the character's graphic. Im using Alworks Iinput script that somehow prevents me from doing Conditional branch if Z button pressed  :sad:
So what I need is a script that changes the hero's graphic by pressing 'D' only if character X is in party and is not dead and then turns a switch on.

I hope its not too complicated to be done.  :crazy:
 
Huum, I think I can do it pretty easily.

I'll see what I can do. :)

DONE! Wasn't very hard at all, just paste this above main:

Code:
#==============================================================================
# Change Hero Graphic v. 1.00
# by xBrokenSin (April 19, 2008)
#------------------------------------------------------------------------------
# ** Change_Hero_Graphic
#==============================================================================
module Change_Hero_Graphic
  #--------------------------------------------------------------------------
  # * Character ID
  #--------------------------------------------------------------------------
  @character_id = 1
  #--------------------------------------------------------------------------
  # * Change Character ID (id = character_id)
  #--------------------------------------------------------------------------
  def self.change_character_id(id)
    @character_id = id
  end
  #--------------------------------------------------------------------------
  # * Returns Characer ID
  #--------------------------------------------------------------------------
  def self.character_id
    return @character_id
  end
  #--------------------------------------------------------------------------
  # * Change Graphic To 
  #--------------------------------------------------------------------------
  @change_graphic_to = '002-Fighter02'
  #--------------------------------------------------------------------------
  # * Change To (graphic_name = file_name)
  #--------------------------------------------------------------------------
  def self.change_to(graphic_name)
    @old_graphic = @change_graphic_to
    @change_graphic_to = graphic_name
  end
  #--------------------------------------------------------------------------
  # * Returns Change Graphic To
  #--------------------------------------------------------------------------
  def self.change_graphic_to
    return @change_graphic_to
  end
  #--------------------------------------------------------------------------
  # * Old Graphic
  #--------------------------------------------------------------------------
  @old_graphic = nil
  #--------------------------------------------------------------------------
  # * Sets Old Graphic (graphic_name = file_name)
  #--------------------------------------------------------------------------
  def self.set_old_graphic(graphic_name)
    @old_graphic = graphic_name
  end
  #--------------------------------------------------------------------------
  # * Switch
  #--------------------------------------------------------------------------
  @switch = false
  #--------------------------------------------------------------------------
  # * Set Switch (condition = true/false)
  #--------------------------------------------------------------------------
  def self.set_switch(condition)
    @swith = condition
  end
  #--------------------------------------------------------------------------
  # * Returns Switch
  #--------------------------------------------------------------------------
  def self.switch
    return @switch
  end
end

#==============================================================================
# ** Game_Actor
#------------------------------------------------------------------------------
#  This class handles the actor. It's used within the Game_Actors class
#  ($game_actors) and refers to the Game_Party class ($game_party).
#==============================================================================

class Game_Actor
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor   :character_name           # character file name
  attr_accessor   :character_hue            # character hue
end

#==============================================================================
# ** Game_Player
#------------------------------------------------------------------------------
#  This class handles the player. Its functions include event starting
#  determinants and map scrolling. Refer to "$game_player" for the one
#  instance of this class.
#==============================================================================
class Game_Player
  #--------------------------------------------------------------------------
  # * Alias
  #--------------------------------------------------------------------------
  alias broken_changegraph_gameplayer_update update
  
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # Calls alias
    broken_changegraph_gameplayer_update
    # If "Z" is pressed
    if Input.trigger?(Input::Z)
      # Stores the module into a variable
      chg = Change_Hero_Graphic
      # Checks if actor is in party
      if $game_party.actors.include?($game_actors[chg.character_id])
        # Returns if the actor is dead
        return if $game_actors[chg.character_id].hp == 0
        # Sets the old graphic
        chg.set_old_graphic(chg.change_graphic_to)
        # Changes hero to new graphic
        $game_actors[chg.character_id].character_name = chg.change_graphic_to
        # Sets switch to true/on
        chg.set_switch(true)
        # Refreshes the screen
        refresh
      end
    end
  end
end

If you need any help with the script just ask!  :thumb:
 
it doesn't work :(

Edit: I figured it out and there was a little mistake where you did "@swith" instead of "@switch".
Also, I changed some scripts that I had and I wonder if you could do the same but instead of using 'D'(Z) geting the same effect using 'X'(B) without opening the menu. I need it to be only X and not Esc. If you could do it I'll be thankfull! :D

PS: Where in the script is the part when I can choose what switch to turn on and off?
 
Okay, I have deduced (someone correct me if I'm wrong) there is no way to set a function to run when you press the ESC key. I think that B(X) also includes ESC, so I think it would be impossible to select one and leave the other.

So, I think that you will either have to leave the change script as it is, or change the menu to a different button.

On to the switch problem! I change thed script a little so the switch is easier to use for none scripters. Just replace the old one with this:

Code:
#==============================================================================
# Change Hero Graphic v. 1.00
# by xBrokenSin (April 19, 2008)
#------------------------------------------------------------------------------
# ** Change_Hero_Graphic
#==============================================================================
module Change_Hero_Graphic
  #--------------------------------------------------------------------------
  # * Character ID
  #--------------------------------------------------------------------------
  @character_id = 1
  #--------------------------------------------------------------------------
  # * Change Character ID (id = character_id)
  #--------------------------------------------------------------------------
  def self.change_character_id(id)
    @character_id = id
  end
  #--------------------------------------------------------------------------
  # * Returns Characer ID
  #--------------------------------------------------------------------------
  def self.character_id
    return @character_id
  end
  #--------------------------------------------------------------------------
  # * Change Graphic To 
  #--------------------------------------------------------------------------
  @change_graphic_to = '002-Fighter02'
  #--------------------------------------------------------------------------
  # * Change To (graphic_name = file_name)
  #--------------------------------------------------------------------------
  def self.change_to(graphic_name)
    @old_graphic = @change_graphic_to
    @change_graphic_to = graphic_name
  end
  #--------------------------------------------------------------------------
  # * Returns Change Graphic To
  #--------------------------------------------------------------------------
  def self.change_graphic_to
    return @change_graphic_to
  end
  #--------------------------------------------------------------------------
  # * Old Graphic
  #--------------------------------------------------------------------------
  @old_graphic = nil
  #--------------------------------------------------------------------------
  # * Sets Old Graphic (graphic_name = file_name)
  #--------------------------------------------------------------------------
  def self.set_old_graphic(graphic_name)
    @old_graphic = graphic_name
  end
  #--------------------------------------------------------------------------
  # * Switch
  #--------------------------------------------------------------------------
  @switch = false
  #--------------------------------------------------------------------------
  # * Set Switch (condition = true/false)
  #--------------------------------------------------------------------------
  def self.switch=(condition)
    @switch = condition
  end
  #--------------------------------------------------------------------------
  # * Returns Switch
  #--------------------------------------------------------------------------
  def self.switch
    return @switch
  end
end

#==============================================================================
# ** Game_Actor
#------------------------------------------------------------------------------
#  This class handles the actor. It's used within the Game_Actors class
#  ($game_actors) and refers to the Game_Party class ($game_party).
#==============================================================================

class Game_Actor
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor   :character_name           # character file name
  attr_accessor   :character_hue            # character hue
end

#==============================================================================
# ** Game_Player
#------------------------------------------------------------------------------
#  This class handles the player. Its functions include event starting
#  determinants and map scrolling. Refer to "$game_player" for the one
#  instance of this class.
#==============================================================================
class Game_Player
  #--------------------------------------------------------------------------
  # * Alias
  #--------------------------------------------------------------------------
  alias broken_changegraph_gameplayer_update update
  
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # Calls alias
    broken_changegraph_gameplayer_update
    # If "Z" is pressed
    if Input.trigger?(Input::Z)
      # Stores the module into a variable
      chg = Change_Hero_Graphic
      # Checks if actor is in party
      if $game_party.actors.include?($game_actors[chg.character_id])
        # Returns if the actor is dead
        return if $game_actors[chg.character_id].hp == 0
        # Sets the old graphic
        chg.set_old_graphic(chg.change_graphic_to)
        # Changes hero to new graphic
        $game_actors[chg.character_id].character_name = chg.change_graphic_to
        # Sets switch to true/on
        chg.switch = true
        # Refreshes the screen
        refresh
      end
    end
  end
end

So, to use it, all you have to do is use this code:

Code:
Change_Hero_Graphic.switch = true # true = on/ false = off

But that could only be used in conditional branches. I guess you could make a conditional branch that turns on an in-game switch?

If you don't know how to use a script conditional branch, just click Conditional Branch in events page 1, click the 4th tab, then click the circle next to script. There, all you have to do is enter your condition. Ex:

Code:
Change_Hero_Graphic.switch == true # Same as above, but remember to include the double "==" or it won't work
 
Ok thanks :D
And I saw that in Mr.MO's ABS you use X as the dash but you still can open the menu with Esc.
And I know it can be done some how with an input module, so any one has an idea how to do this?
Edit: I use Alworks Input module
Edit2: Another problem I noticed is that he can't change back to the old graphic and I still can't find where in the script I should put the switch's ID to turn it on
 
BUMP
Never mind about the key, the only problem is I don't know where I put the switche's ID (if needed) and I need a way so when I press the key again it changes the graphic back to the old.
 
Once again, replace the old script with this:

Code:
#==============================================================================
# Change Hero Graphic v. 1.02
# by xBrokenSin (April 19, 2008)
#------------------------------------------------------------------------------
# ** Change_Hero_Graphic
#==============================================================================
module Change_Hero_Graphic
  #--------------------------------------------------------------------------
  # * Character ID
  #--------------------------------------------------------------------------
  @character_id = 1
  #--------------------------------------------------------------------------
  # * Change Character ID (id = character_id)
  #--------------------------------------------------------------------------
  def self.change_character_id(id)
    @character_id = id
  end
  #--------------------------------------------------------------------------
  # * Returns Characer ID
  #--------------------------------------------------------------------------
  def self.character_id
    return @character_id
  end
  #--------------------------------------------------------------------------
  # * Change Graphic To 
  #--------------------------------------------------------------------------
  @change_graphic_to = '002-Fighter02'
  #--------------------------------------------------------------------------
  # * Change To (graphic_name = file_name)
  #--------------------------------------------------------------------------
  def self.change_to(graphic_name)
    @change_graphic_to = graphic_name
  end
  #--------------------------------------------------------------------------
  # * Returns Change Graphic To
  #--------------------------------------------------------------------------
  def self.change_graphic_to
    return @change_graphic_to
  end
  #--------------------------------------------------------------------------
  # * Old Graphic
  #--------------------------------------------------------------------------
  @old_graphic = nil
  
  def self.old_graphic
    return @old_graphic
  end
  #--------------------------------------------------------------------------
  # * Sets Old Graphic (graphic_name = file_name)
  #--------------------------------------------------------------------------
  def self.set_old_graphic(graphic_name)
    @old_graphic = graphic_name
  end
  #--------------------------------------------------------------------------
  # * Switch
  #--------------------------------------------------------------------------
  @switch_id = 1
  
  def self.switch_id
    return @switch_id
  end
end

#==============================================================================
# ** Game_Actor
#------------------------------------------------------------------------------
#  This class handles the actor. It's used within the Game_Actors class
#  ($game_actors) and refers to the Game_Party class ($game_party).
#==============================================================================

class Game_Actor
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor   :character_name           # character file name
  attr_accessor   :character_hue            # character hue
end

#==============================================================================
# ** Game_Player
#------------------------------------------------------------------------------
#  This class handles the player. Its functions include event starting
#  determinants and map scrolling. Refer to "$game_player" for the one
#  instance of this class.
#==============================================================================
class Game_Player
  #--------------------------------------------------------------------------
  # * Alias
  #--------------------------------------------------------------------------
  alias broken_changegraph_gameplayer_update update
  
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # Calls alias
    broken_changegraph_gameplayer_update
    # If "Z" is pressed
    if Input.trigger?(Input::Z)
      # Stores the module into a variable
      chg = Change_Hero_Graphic
      # Checks if actor is in party
      if $game_party.actors.include?($game_actors[chg.character_id])
        # Returns if the actor is dead
        return if $game_actors[chg.character_id].hp == 0
        unless $game_switches[chg.switch_id]
          # Changes new change graphic to old graphic
          chg.change_to(chg.old_graphic) unless chg.old_graphic.nil?
          # Sets the old graphic
          chg.set_old_graphic($game_actors[chg.character_id].character_name)
          # Changes hero to new graphic
          $game_actors[chg.character_id].character_name = chg.change_graphic_to
          # Sets switch to true/on
          $game_switches[chg.switch_id] = true
        else
          # Changes new change graphic to old graphic
          chg.change_to(chg.old_graphic)
          # Sets the old graphic
          chg.set_old_graphic($game_actors[chg.character_id].character_name)
          # Changes hero to new graphic
          $game_actors[chg.character_id].character_name = chg.change_graphic_to
          # Sets switch to false/off
          $game_switches[chg.switch_id] = false
        end
        # Refreshes the screen
        refresh
      end
    end
  end
end

You can now change the graphic back and forth, and just find this:

Code:
@switch_id = 1

And change the number to the switch you want to turn on and off.  :thumb:
 

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