Script for idle pose

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:

Image
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:
  1. case 4dir
  2. when 2
  3.   self.sprite = $data_actors[self.id].graphic # add this line
  4.   # ...
  5. when 4
  6.   self.sprite = $data_actors[self.id].graphic # add this line
  7.   # ...
  8. when 6
  9.   self.sprite = $data_actors[self.id].graphic # add this line
  10.   # ...
  11. when 8
  12.   self.sprite = $data_actors[self.id].graphic # add this line
  13.   # ...
  14. else # add this and the following line
  15.   self.sprite = RPG::Cache.characters($game_party.actors[0].name + '_idle')
  16. end
Expand to see the code.

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.
*wrong topic*
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.

  1. #==============================================================================
  2. # ** Game_Player
  3. #------------------------------------------------------------------------------
  4. #  This class handles the player. Its functions include event starting
  5. #  determinants and map scrolling. Refer to "$game_player" for the one
  6. #  instance of this class.
  7. #==============================================================================
  8.  
  9. class Game_Player < Game_Character
  10.   #--------------------------------------------------------------------------
  11.   # * Invariables
  12.   #--------------------------------------------------------------------------
  13.   CENTER_X = (320 - 16) * 4   # Center screen x-coordinate * 4
  14.   CENTER_Y = (240 - 16) * 4   # Center screen y-coordinate * 4
  15.   #--------------------------------------------------------------------------
  16.   # * Passable Determinants
  17.   #     x : x-coordinate
  18.   #     y : y-coordinate
  19.   #     d : direction (0,2,4,6,8)
  20.   #         * 0 = Determines if all directions are impassable (for jumping)
  21.   #--------------------------------------------------------------------------
  22.   def passable?(x, y, d)
  23.     # Get new coordinates
  24.     new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
  25.     new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
  26.     # If coordinates are outside of map
  27.     unless $game_map.valid?(new_x, new_y)
  28.       # Impassable
  29.       return false
  30.     end
  31.     # If debug mode is ON and ctrl key was pressed
  32.     if $DEBUG and Input.press?(Input::CTRL)
  33.       # Passable
  34.       return true
  35.     end
  36.     super
  37.   end
  38.   #--------------------------------------------------------------------------
  39.   # * Set Map Display Position to Center of Screen
  40.   #--------------------------------------------------------------------------
  41.   def center(x, y)
  42.     max_x = ($game_map.width - 20) * 128
  43.     max_y = ($game_map.height - 15) * 128
  44.     $game_map.display_x = [0, [x * 128 - CENTER_X, max_x].min].max
  45.     $game_map.display_y = [0, [y * 128 - CENTER_Y, max_y].min].max
  46.   end
  47.   #--------------------------------------------------------------------------
  48.   # * Move to Designated Position
  49.   #     x : x-coordinate
  50.   #     y : y-coordinate
  51.   #--------------------------------------------------------------------------
  52.   def moveto(x, y)
  53.     super
  54.     # Centering
  55.     center(x, y)
  56.     # Make encounter count
  57.     make_encounter_count
  58.   end
  59.   #--------------------------------------------------------------------------
  60.   # * Increaase Steps
  61.   #--------------------------------------------------------------------------
  62.   def increase_steps
  63.     super
  64.     # If move route is not forcing
  65.     unless @move_route_forcing
  66.       # Increase steps
  67.       $game_party.increase_steps
  68.       # Number of steps are an even number
  69.       if $game_party.steps % 2 == 0
  70.         # Slip damage check
  71.         $game_party.check_map_slip_damage
  72.       end
  73.     end
  74.   end
  75.   #--------------------------------------------------------------------------
  76.   # * Get Encounter Count
  77.   #--------------------------------------------------------------------------
  78.   def encounter_count
  79.     return @encounter_count
  80.   end
  81.   #--------------------------------------------------------------------------
  82.   # * Make Encounter Count
  83.   #--------------------------------------------------------------------------
  84.   def make_encounter_count
  85.     # Image of two dice rolling
  86.     if $game_map.map_id != 0
  87.       n = $game_map.encounter_step
  88.       @encounter_count = rand(n) + rand(n) + 1
  89.     end
  90.   end
  91.   #--------------------------------------------------------------------------
  92.   # * Refresh
  93.   #--------------------------------------------------------------------------
  94.   def refresh
  95.     # If party members = 0
  96.     if $game_party.actors.size == 0
  97.       # Clear character file name and hue
  98.       @character_name = ""
  99.       @character_hue = 0
  100.       # End method
  101.       return
  102.     end
  103.     # Get lead actor
  104.     actor = $game_party.actors[0]
  105.     # Set character file name and hue
  106.     @character_name = actor.character_name
  107.     @character_hue = actor.character_hue
  108.     # Initialize opacity level and blending method
  109.     @opacity = 255
  110.     @blend_type = 0
  111.   end
  112.   #--------------------------------------------------------------------------
  113.   # * Same Position Starting Determinant
  114.   #--------------------------------------------------------------------------
  115.   def check_event_trigger_here(triggers)
  116.     result = false
  117.     # If event is running
  118.     if $game_system.map_interpreter.running?
  119.       return result
  120.     end
  121.     # All event loops
  122.     for event in $game_map.events.values
  123.       # If event coordinates and triggers are consistent
  124.       if event.x == @x and event.y == @y and triggers.include?(event.trigger)
  125.         # If starting determinant is same position event (other than jumping)
  126.         if not event.jumping? and event.over_trigger?
  127.           event.start
  128.           result = true
  129.         end
  130.       end
  131.     end
  132.     return result
  133.   end
  134.   #--------------------------------------------------------------------------
  135.   # * Front Envent Starting Determinant
  136.   #--------------------------------------------------------------------------
  137.   def check_event_trigger_there(triggers)
  138.     result = false
  139.     # If event is running
  140.     if $game_system.map_interpreter.running?
  141.       return result
  142.     end
  143.     # Calculate front event coordinates
  144.     new_x = @x + (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
  145.     new_y = @y + (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
  146.     # All event loops
  147.     for event in $game_map.events.values
  148.       # If event coordinates and triggers are consistent
  149.       if event.x == new_x and event.y == new_y and
  150.          triggers.include?(event.trigger)
  151.         # If starting determinant is front event (other than jumping)
  152.         if not event.jumping? and not event.over_trigger?
  153.           event.start
  154.           result = true
  155.         end
  156.       end
  157.     end
  158.     # If fitting event is not found
  159.     if result == false
  160.       # If front tile is a counter
  161.       if $game_map.counter?(new_x, new_y)
  162.         # Calculate 1 tile inside coordinates
  163.         new_x += (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
  164.         new_y += (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
  165.         # All event loops
  166.         for event in $game_map.events.values
  167.           # If event coordinates and triggers are consistent
  168.           if event.x == new_x and event.y == new_y and
  169.              triggers.include?(event.trigger)
  170.             # If starting determinant is front event (other than jumping)
  171.             if not event.jumping? and not event.over_trigger?
  172.               event.start
  173.               result = true
  174.             end
  175.           end
  176.         end
  177.       end
  178.     end
  179.     return result
  180.   end
  181.   #--------------------------------------------------------------------------
  182.   # * Touch Event Starting Determinant
  183.   #--------------------------------------------------------------------------
  184.   def check_event_trigger_touch(x, y)
  185.     result = false
  186.     # If event is running
  187.     if $game_system.map_interpreter.running?
  188.       return result
  189.     end
  190.     # All event loops
  191.     for event in $game_map.events.values
  192.       # If event coordinates and triggers are consistent
  193.       if event.x == x and event.y == y and [1,2].include?(event.trigger)
  194.         # If starting determinant is front event (other than jumping)
  195.         if not event.jumping? and not event.over_trigger?
  196.           event.start
  197.           result = true
  198.         end
  199.       end
  200.     end
  201.     return result
  202.   end
  203.   #--------------------------------------------------------------------------
  204.   # * Frame Update
  205.   #--------------------------------------------------------------------------
  206.   def update
  207.     # Remember whether or not moving in local variables
  208.     last_moving = moving?
  209.     # If moving, event running, move route forcing, and message window
  210.     # display are all not occurring
  211.     unless moving? or $game_system.map_interpreter.running? or
  212.            @move_route_forcing or $game_temp.message_window_showing
  213.       # Move player in the direction the directional button is being pressed
  214.       case Input.dir4
  215.       when 2
  216.         move_down
  217.       when 4
  218.         move_left
  219.       when 6
  220.         move_right
  221.       when 8
  222.         move_up
  223.       end
  224.     end
  225.     # Remember coordinates in local variables
  226.     last_real_x = @real_x
  227.     last_real_y = @real_y
  228.     super
  229.     # If character moves down and is positioned lower than the center
  230.     # of the screen
  231.     if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y
  232.       # Scroll map down
  233.       $game_map.scroll_down(@real_y - last_real_y)
  234.     end
  235.     # If character moves left and is positioned more let on-screen than
  236.     # center
  237.     if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X
  238.       # Scroll map left
  239.       $game_map.scroll_left(last_real_x - @real_x)
  240.     end
  241.     # If character moves right and is positioned more right on-screen than
  242.     # center
  243.     if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X
  244.       # Scroll map right
  245.       $game_map.scroll_right(@real_x - last_real_x)
  246.     end
  247.     # If character moves up and is positioned higher than the center
  248.     # of the screen
  249.     if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y
  250.       # Scroll map up
  251.       $game_map.scroll_up(last_real_y - @real_y)
  252.     end
  253.     # If not moving
  254.     unless moving?
  255.       # If player was moving last time
  256.       if last_moving
  257.         # Event determinant is via touch of same position event
  258.         result = check_event_trigger_here([1,2])
  259.         # If event which started does not exist
  260.         if result == false
  261.           # Disregard if debug mode is ON and ctrl key was pressed
  262.           unless $DEBUG and Input.press?(Input::CTRL)
  263.             # Encounter countdown
  264.             if @encounter_count > 0
  265.               @encounter_count -= 1
  266.             end
  267.           end
  268.         end
  269.       end
  270.       # If C button was pressed
  271.       if Input.trigger?(Input::C)
  272.         # Same position and front event determinant
  273.         check_event_trigger_here([0])
  274.         check_event_trigger_there([0,1,2])
  275.       end
  276.     end
  277.   end
  278. end
  279.  
Expand to see the code.
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.

  1. class Game_Player < Game_Character
  2.   #--------------------------------------------------------------------------
  3.   alias idleframe_update update
  4.   def update
  5.     last_moving = moving?
  6.     unless moving? or $game_system.map_interpreter.running? or
  7.            @move_route_forcing or $game_temp.message_window_showing
  8.       case Input.dir4
  9.       when 2
  10.         @character_name = actor.character_name
  11.         move_down
  12.       when 4
  13.         @character_name = actor.character_name
  14.         move_left
  15.       when 6
  16.         @character_name = actor.character_name
  17.         move_right
  18.       when 8
  19.         @character_name = actor.character_name
  20.         move_up
  21.       else
  22.         @character_name = actor.character_name + '_idle'
  23.       end
  24.     end
  25.     idleframe_update
  26.   end
  27.   #--------------------------------------------------------------------------
  28. end
Expand to see the code.


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

  1. class Game_Player < Game_Character
  2.   #--------------------------------------------------------------------------
  3.   def update
  4.     last_moving = moving?
  5.     unless moving? or $game_system.map_interpreter.running? or
  6.            @move_route_forcing or $game_temp.message_window_showing
  7.       case Input.dir4
  8.       when 2
  9.         @character_name = actor.character_name
  10.         move_down
  11.       when 4
  12.         @character_name = actor.character_name
  13.         move_left
  14.       when 6
  15.         @character_name = actor.character_name
  16.         move_right
  17.       when 8
  18.         @character_name = actor.character_name
  19.         move_up
  20.       else
  21.         @character_name = actor.character_name + '_idle'
  22.       end
  23.     end
  24.     last_real_x = @real_x
  25.     last_real_y = @real_y
  26.     super
  27.     if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y
  28.       $game_map.scroll_down(@real_y - last_real_y)
  29.     end
  30.     if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X
  31.       $game_map.scroll_left(last_real_x - @real_x)
  32.     end
  33.     if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X
  34.       $game_map.scroll_right(@real_x - last_real_x)
  35.     end
  36.     if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y
  37.       $game_map.scroll_up(last_real_y - @real_y)
  38.     end
  39.     unless moving?
  40.       if last_moving
  41.         result = check_event_trigger_here([1,2])
  42.         if result == false
  43.           unless $DEBUG and Input.press?(Input::CTRL)
  44.             if @encounter_count > 0
  45.               @encounter_count -= 1
  46.             end
  47.           end
  48.         end
  49.       end
  50.       if Input.trigger?(Input::C)
  51.         check_event_trigger_here([0])
  52.         check_event_trigger_there([0,1,2])
  53.       end
  54.     end
  55.   end
  56.   #--------------------------------------------------------------------------
  57. end
Expand to see the code.


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.

  1. class Game_Player < Game_Character
  2.   #--------------------------------------------------------------------------
  3.   def update
  4.     # Get lead actor
  5.     actor = $game_party.actors[0]
  6.    
  7.     last_moving = moving?
  8.     unless moving? or $game_system.map_interpreter.running? or
  9.            @move_route_forcing or $game_temp.message_window_showing
  10.       case Input.dir4
  11.       when 2
  12.         @character_name = actor.character_name
  13.         move_down
  14.       when 4
  15.         @character_name = actor.character_name
  16.         move_left
  17.       when 6
  18.         @character_name = actor.character_name
  19.         move_right
  20.       when 8
  21.         @character_name = actor.character_name
  22.         move_up
  23.       else
  24.         @character_name = actor.character_name + '_idle'
  25.       end
  26.     end
  27.     last_real_x = @real_x
  28.     last_real_y = @real_y
  29.     super
  30.     if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y
  31.       $game_map.scroll_down(@real_y - last_real_y)
  32.     end
  33.     if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X
  34.       $game_map.scroll_left(last_real_x - @real_x)
  35.     end
  36.     if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X
  37.       $game_map.scroll_right(@real_x - last_real_x)
  38.     end
  39.     if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y
  40.       $game_map.scroll_up(last_real_y - @real_y)
  41.     end
  42.     unless moving?
  43.       if last_moving
  44.         result = check_event_trigger_here([1,2])
  45.         if result == false
  46.           unless $DEBUG and Input.press?(Input::CTRL)
  47.             if @encounter_count > 0
  48.               @encounter_count -= 1
  49.             end
  50.           end
  51.         end
  52.       end
  53.       if Input.trigger?(Input::C)
  54.         check_event_trigger_here([0])
  55.         check_event_trigger_there([0,1,2])
  56.       end
  57.     end
  58.   end
  59.   #--------------------------------------------------------------------------
  60. end
Expand to see the code.
Heh, guess I didn't think actually defining the actor would be important... :o: 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 ^^
Thanks Bluescope, that's all i really needed to understand. I just gotta find a way of doing it now :)

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=71161