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 for idle pose

R.J.

Member

I was wondering if there's a script which does the following: If the directional buttons aren't pressed (up, down, left, right), the playable character goes into an idle pose (not animated).

I did this using a common event, but it has a flaw and it would be easier to use a script. The problem with my common event is that, when the playable character is up against a wall, and the button is pressed, the "walking" pose still shows (because the event obviously only checks if the button is pressed, not what the player is doing), and that looks weird.

Event screenshot:

e0pwj.png
 
As you were noticing the vast disadvantage of events over scripts, I feel I should help you. Unfortunately, you're not using RMVX, which makes this relatively hard for me ^^" I'll try to either way...

First of all, you shoudl know that it all takes place within Game_Player. Locate the following block and make some slight changes, as noted in the following:
[rgss]case 4dir
when 2
  self.sprite = $data_actors[self.id].graphic # add this line
  # ...
when 4
  self.sprite = $data_actors[self.id].graphic # add this line
  # ...
when 6
  self.sprite = $data_actors[self.id].graphic # add this line
  # ...
when 8
  self.sprite = $data_actors[self.id].graphic # add this line
  # ...
else # add this and the following line
  self.sprite = RPG::Cache.characters($game_party.actors[0].name + '_idle')
end
[/rgss]
If, for example, you party leader's name is 'Max', you need a file named 'Max_idle.whateversupportedfiletype'. This should work fine, however if you want a nice and awesome version, wait for the next best person taking look in here with access to RMXP scripts to alias this for you.
I'm also puzzled abot wheather 'self.sprite' is correct... you should be able to get the correct name from within the initialize definition.

I hope this works... if it doesn't, you can't get it to work and you'll be as kind to supply me with the Game_Player class, I'll correct it for you.
 

R.J.

Member

I can't find the block you're talking about, so I will just post the entire RMXP Game_Player class instead. I hope this helps.

Code:
#==============================================================================

# ** 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 < Game_Character

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

  # * Invariables

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

  CENTER_X = (320 - 16) * 4   # Center screen x-coordinate * 4

  CENTER_Y = (240 - 16) * 4   # Center screen y-coordinate * 4

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

  # * Passable Determinants

  #     x : x-coordinate

  #     y : y-coordinate

  #     d : direction (0,2,4,6,8)

  #         * 0 = Determines if all directions are impassable (for jumping)

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

  def passable?(x, y, d)

    # Get new coordinates

    new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)

    new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)

    # If coordinates are outside of map

    unless $game_map.valid?(new_x, new_y)

      # Impassable

      return false

    end

    # If debug mode is ON and ctrl key was pressed

    if $DEBUG and Input.press?(Input::CTRL)

      # Passable

      return true

    end

    super

  end

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

  # * Set Map Display Position to Center of Screen

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

  def center(x, y)

    max_x = ($game_map.width - 20) * 128

    max_y = ($game_map.height - 15) * 128

    $game_map.display_x = [0, [x * 128 - CENTER_X, max_x].min].max

    $game_map.display_y = [0, [y * 128 - CENTER_Y, max_y].min].max

  end

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

  # * Move to Designated Position

  #     x : x-coordinate

  #     y : y-coordinate

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

  def moveto(x, y)

    super

    # Centering

    center(x, y)

    # Make encounter count

    make_encounter_count

  end

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

  # * Increaase Steps

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

  def increase_steps

    super

    # If move route is not forcing

    unless @move_route_forcing

      # Increase steps

      $game_party.increase_steps

      # Number of steps are an even number

      if $game_party.steps % 2 == 0

        # Slip damage check

        $game_party.check_map_slip_damage

      end

    end

  end

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

  # * Get Encounter Count

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

  def encounter_count

    return @encounter_count

  end

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

  # * Make Encounter Count

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

  def make_encounter_count

    # Image of two dice rolling

    if $game_map.map_id != 0

      n = $game_map.encounter_step

      @encounter_count = rand(n) + rand(n) + 1

    end

  end

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

  # * Refresh

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

  def refresh

    # If party members = 0

    if $game_party.actors.size == 0

      # Clear character file name and hue

      @character_name = ""

      @character_hue = 0

      # End method

      return

    end

    # Get lead actor

    actor = $game_party.actors[0]

    # Set character file name and hue

    @character_name = actor.character_name

    @character_hue = actor.character_hue

    # Initialize opacity level and blending method

    @opacity = 255

    @blend_type = 0

  end

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

  # * Same Position Starting Determinant

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

  def check_event_trigger_here(triggers)

    result = false

    # If event is running

    if $game_system.map_interpreter.running?

      return result

    end

    # All event loops

    for event in $game_map.events.values

      # If event coordinates and triggers are consistent

      if event.x == @x and event.y == @y and triggers.include?(event.trigger)

        # If starting determinant is same position event (other than jumping)

        if not event.jumping? and event.over_trigger?

          event.start

          result = true

        end

      end

    end

    return result

  end

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

  # * Front Envent Starting Determinant

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

  def check_event_trigger_there(triggers)

    result = false

    # If event is running

    if $game_system.map_interpreter.running?

      return result

    end

    # Calculate front event coordinates

    new_x = @x + (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)

    new_y = @y + (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)

    # All event loops

    for event in $game_map.events.values

      # If event coordinates and triggers are consistent

      if event.x == new_x and event.y == new_y and

         triggers.include?(event.trigger)

        # If starting determinant is front event (other than jumping)

        if not event.jumping? and not event.over_trigger?

          event.start

          result = true

        end

      end

    end

    # If fitting event is not found

    if result == false

      # If front tile is a counter

      if $game_map.counter?(new_x, new_y)

        # Calculate 1 tile inside coordinates

        new_x += (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)

        new_y += (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)

        # All event loops

        for event in $game_map.events.values

          # If event coordinates and triggers are consistent

          if event.x == new_x and event.y == new_y and

             triggers.include?(event.trigger)

            # If starting determinant is front event (other than jumping)

            if not event.jumping? and not event.over_trigger?

              event.start

              result = true

            end

          end

        end

      end

    end

    return result

  end

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

  # * Touch Event Starting Determinant

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

  def check_event_trigger_touch(x, y)

    result = false

    # If event is running

    if $game_system.map_interpreter.running?

      return result

    end

    # All event loops

    for event in $game_map.events.values

      # If event coordinates and triggers are consistent

      if event.x == x and event.y == y and [1,2].include?(event.trigger)

        # If starting determinant is front event (other than jumping)

        if not event.jumping? and not event.over_trigger?

          event.start

          result = true

        end

      end

    end

    return result

  end

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

  # * Frame Update

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

  def update

    # Remember whether or not moving in local variables

    last_moving = moving?

    # If moving, event running, move route forcing, and message window

    # display are all not occurring

    unless moving? or $game_system.map_interpreter.running? or

           @move_route_forcing or $game_temp.message_window_showing

      # Move player in the direction the directional button is being pressed

      case Input.dir4

      when 2

        move_down

      when 4

        move_left

      when 6

        move_right

      when 8

        move_up

      end

    end

    # Remember coordinates in local variables

    last_real_x = @real_x

    last_real_y = @real_y

    super

    # If character moves down and is positioned lower than the center

    # of the screen

    if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y

      # Scroll map down

      $game_map.scroll_down(@real_y - last_real_y)

    end

    # If character moves left and is positioned more let on-screen than

    # center

    if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X

      # Scroll map left

      $game_map.scroll_left(last_real_x - @real_x)

    end

    # If character moves right and is positioned more right on-screen than

    # center

    if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X

      # Scroll map right

      $game_map.scroll_right(@real_x - last_real_x)

    end

    # If character moves up and is positioned higher than the center

    # of the screen

    if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y

      # Scroll map up

      $game_map.scroll_up(last_real_y - @real_y)

    end

    # If not moving

    unless moving?

      # If player was moving last time

      if last_moving

        # Event determinant is via touch of same position event

        result = check_event_trigger_here([1,2])

        # If event which started does not exist

        if result == false

          # Disregard if debug mode is ON and ctrl key was pressed

          unless $DEBUG and Input.press?(Input::CTRL)

            # Encounter countdown

            if @encounter_count > 0

              @encounter_count -= 1

            end

          end

        end

      end

      # If C button was pressed

      if Input.trigger?(Input::C)

        # Same position and front event determinant

        check_event_trigger_here([0])

        check_event_trigger_there([0,1,2])

      end

    end

  end

end

 
 
This is what you try first, having the very same character graphic in the Characters directory for idle with '_idle' attached to it. Put it above Main, below Game_Player, and run a test game.

[rgss]class Game_Player < Game_Character
  #--------------------------------------------------------------------------
  alias idleframe_update update
  def update
    last_moving = moving?
    unless moving? or $game_system.map_interpreter.running? or
           @move_route_forcing or $game_temp.message_window_showing
      case Input.dir4
      when 2
        @character_name = actor.character_name
        move_down
      when 4
        @character_name = actor.character_name
        move_left
      when 6
        @character_name = actor.character_name
        move_right
      when 8
        @character_name = actor.character_name
        move_up
      else
        @character_name = actor.character_name + '_idle'
      end
    end
    idleframe_update
  end
  #--------------------------------------------------------------------------
end
[/rgss]

If that doesn't bring up an error, but won't work either, have a shot at this:

[rgss]class Game_Player < Game_Character
  #--------------------------------------------------------------------------
  def update
    last_moving = moving?
    unless moving? or $game_system.map_interpreter.running? or
           @move_route_forcing or $game_temp.message_window_showing
      case Input.dir4
      when 2
        @character_name = actor.character_name
        move_down
      when 4
        @character_name = actor.character_name
        move_left
      when 6
        @character_name = actor.character_name
        move_right
      when 8
        @character_name = actor.character_name
        move_up
      else
        @character_name = actor.character_name + '_idle'
      end
    end
    last_real_x = @real_x
    last_real_y = @real_y
    super
    if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y
      $game_map.scroll_down(@real_y - last_real_y)
    end
    if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X
      $game_map.scroll_left(last_real_x - @real_x)
    end
    if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X
      $game_map.scroll_right(@real_x - last_real_x)
    end
    if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y
      $game_map.scroll_up(last_real_y - @real_y)
    end
    unless moving?
      if last_moving
        result = check_event_trigger_here([1,2])
        if result == false
          unless $DEBUG and Input.press?(Input::CTRL)
            if @encounter_count > 0
              @encounter_count -= 1
            end
          end
        end
      end
      if Input.trigger?(Input::C)
        check_event_trigger_here([0])
        check_event_trigger_there([0,1,2])
      end
    end
  end
  #--------------------------------------------------------------------------
end
[/rgss]

Remember to turn line numbers off before copying.

If the second one doesn't work either, please tell me what's going wrong... it should work now really, however, RMXP is a bit too cluttered (OMG huge un-structured update method >> ) to have a quick shot at it, I suppose... ^^"
 
nice Bluescope, something i have been wanting to do for a while, unfortunatly when i used it i had an error, so i've fixed it for you.

heres the error proof script.

Code:
class Game_Player < Game_Character

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

  def update

    # Get lead actor

    actor = $game_party.actors[0]

    

    last_moving = moving?

    unless moving? or $game_system.map_interpreter.running? or

           @move_route_forcing or $game_temp.message_window_showing

      case Input.dir4

      when 2

        @character_name = actor.character_name

        move_down

      when 4

        @character_name = actor.character_name

        move_left

      when 6

        @character_name = actor.character_name

        move_right

      when 8

        @character_name = actor.character_name

        move_up

      else

        @character_name = actor.character_name + '_idle'

      end

    end

    last_real_x = @real_x

    last_real_y = @real_y

    super

    if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y

      $game_map.scroll_down(@real_y - last_real_y)

    end

    if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X

      $game_map.scroll_left(last_real_x - @real_x)

    end

    if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X

      $game_map.scroll_right(@real_x - last_real_x)

    end

    if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y

      $game_map.scroll_up(last_real_y - @real_y)

    end

    unless moving?

      if last_moving

        result = check_event_trigger_here([1,2])

        if result == false

          unless $DEBUG and Input.press?(Input::CTRL)

            if @encounter_count > 0

              @encounter_count -= 1

            end

          end

        end

      end

      if Input.trigger?(Input::C)

        check_event_trigger_here([0])

        check_event_trigger_there([0,1,2])

      end

    end

  end

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

end
 
Heh, guess I didn't think actually defining the actor would be important... :eek:: Nice catch though (and I guess not using the program for over a year now is a somewhat good excuse for me :p ).
 
Yeah thats fine aha, but i would like to continue this request, and have it so that when the player is facing down the pose animates (so i can make his eyes open and close :D) becuase i have no idea on how that whole area works. ^^
 
Well, that'd be a bit bigger than I'd assume I could do without an actual RPG Maker at hand :p The things that make this request more complex is that you need a way to show an animation that's totally independent from button_input, meaning you'd have to set a variable that increases by 1 each frame, and for example at 120 (if you want the delay between the blinks to be 4 seconds; I suggest using a randomizer with at least 4 seconds minimum and not more than a second of variance in randomizing per 5 seconds), it triggers the first blink frame, at 121 the second, 122 third, and so on, until you reached the end of your animation (note that this obviously would work for the character stretching or something, which is why I'm not saying "4 frames should be good for twitching" ^^). At the end, set the variable to 0 again, so the loop starts new.

This should be a fairly easy thing to do, the only hard part would be to draw the graphics really... which isn'T all that hard either. You can do it ^^
 

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