[RGSS] "Wait" and "Wait for end of movement"

Started by phcs93, February 28, 2015, 11:10:45 pm

Previous topic - Next topic

phcs93

Maybe these commands are written different for you guys since I use a pt-BR version of RPG Maker XP.

I am making animations using charsets, so, between each position change, I want to have a little delay (4 frames for example).

I can do it perfectly by using the "wait" command inside the "move event" window:



But I don't know how to remake this in RGSS.

I tried even creating a attr_accessor for @wait_count inside Game_Character so I could do like:

$game_player.wait_count = 4

But no success...

Also, I couldn't find a way to call "wait for the end of movement" via RGSS.

I found this in the Interpreter class: @move_route_waiting = true
But it doesn't work...

KK20

It's going to be a bit more technical if you want to fully script the animation. Is there any reason why using the Move Event command not preferred?

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

phcs93

Well I was planing to abstract the process and make a function which would run any animation you pass, add some parameters and stuff...

How much technical are we going to get? No problem for me.

KK20

February 28, 2015, 11:53:27 pm #3 Last Edit: February 28, 2015, 11:54:47 pm by KK20
About an entire script's worth. I'm not entirely sure how far of an extent you want the system to be, so I'm just going to be very generic.

I'm going to take it that this will apply to any character/event on the map, so the Game_Character class should be the one to add-on to. You're going to need to define the parameters of the animation based on the file graphic of the character and an array of integers to represent the frame delay between each animation frame.

The main method that handles changing the character graphic animation is in Game_Character#update, namely
Spoiler: ShowHide
Code: ruby

   # If animation count exceeds maximum value
   # * Maximum value is move speed * 1 taken from basic value 18
   if @anime_count > 18 - @move_speed * 2
     # If stop animation is OFF when stopping
     if not @step_anime and @stop_count > 0
       # Return to original pattern
       @pattern = @original_pattern
     # If stop animation is ON when moving
     else
       # Update pattern
       @pattern = (@pattern + 1) % 4
     end
     # Clear animation count
     @anime_count = 0
   end

I recommend that you overwrite this method, perhaps adding a new boolean variable that is TRUE if the character is using a unique animation. Also add a counter for ticking down the wait counter.
Spoiler: ShowHide
Code: ruby

   # If character has unique animation
   if @unique_animation
     @delay_frames -= 1
     # Update the animation to the next frame?
     if @delay_frames == 0
       @pattern = (@pattern + 1) % HOWEVER_MANY_FRAMES_YOUR_GRAPHIC_IS #<== perhaps create a module for configuring this, unless all graphics are 4 frames
       # Reset the delay counter
       @delay_frames = @unique_frame_delays[@pattern] #<== Array of ints that represent frame delay between each animation (ex. [3,3,3,10])
     end
   # If animation count exceeds maximum value
   # * Maximum value is move speed * 1 taken from basic value 18
   elsif @anime_count > 18 - @move_speed * 2
     # If stop animation is OFF when stopping
     if not @step_anime and @stop_count > 0
       # Return to original pattern
       @pattern = @original_pattern
     # If stop animation is ON when moving
     else
       # Update pattern
       @pattern = (@pattern + 1) % 4
     end
     # Clear animation count
     @anime_count = 0
   end

And add a method in Interpreter to call this easily from the map. Oh and don't forget to initialize your new variables in Game_Character.
Spoiler: ShowHide
Code: ruby

class Interpreter
 def character_animation(char_id, frame_delay_array)
   character = get_character(char_id) # -1 = player, 0 = this event, 1+ = event id
   character.unique_frame_delays = frame_delay_array
 end
end

class Game_Character
 def unique_frame_delays=(array)
   @unique_frame_delays = array
   @unique_animation = true
   @delay_frames = array[@pattern]
 end
end

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

phcs93

I don't know what I am doing wrong.

I overwrite Game_Character update, added character_animation method to the Interpreter and unique_frame_delays to Game_Character.

Initialized the new attributes and called the method from the map like this: character_animation(-1, [4, 4, 4, 4, 4]) // I'm using a 5 frame charset

And of course I changed "HOWEVER_MANY_FRAMES_YOUR_GRAPHIC_IS" to 5 to test it.

But the game got frozen...

BTW, thank you for your help!

KK20

Hmmm...just tried it out myself. Of course, I have to use 4 frames of animation since none of the RTP is more than that.

character_animation(-1, [4,16,40,4])


Script: ShowHide

class Interpreter
 def character_animation(char_id, frame_delay_array)
   character = get_character(char_id) # -1 = player, 0 = this event, 1+ = event id
   character.unique_frame_delays = frame_delay_array
 end
end

class Game_Character
 
 def unique_frame_delays=(array)
   @unique_frame_delays = array
   @unique_animation = true
   @delay_frames = array[@pattern]
 end
 #--------------------------------------------------------------------------
 # * Frame Update
 #--------------------------------------------------------------------------
 def update
   # Branch with jumping, moving, and stopping
   if jumping?
     update_jump
   elsif moving?
     update_move
   else
     update_stop
   end
   # If character has unique animation
   if @unique_animation
     @delay_frames -= 1
     # Update the animation to the next frame?
     if @delay_frames == 0
       @pattern = (@pattern + 1) % 4 #<== perhaps create a module for configuring this, unless all graphics are 4 frames
       # Reset the delay counter
       @delay_frames = @unique_frame_delays[@pattern] #<== Array of ints that represent frame delay between each animation (ex. [3,3,3,10])
     end
   # If animation count exceeds maximum value
   # * Maximum value is move speed * 1 taken from basic value 18
   elsif @anime_count > 18 - @move_speed * 2
     # If stop animation is OFF when stopping
     if not @step_anime and @stop_count > 0
       # Return to original pattern
       @pattern = @original_pattern
     # If stop animation is ON when moving
     else
       # Update pattern
       @pattern = (@pattern + 1) % 4
     end
     # Clear animation count
     @anime_count = 0
   end
   # If waiting
   if @wait_count > 0
     # Reduce wait count
     @wait_count -= 1
     return
   end
   # If move route is forced
   if @move_route_forcing
     # Custom move
     move_type_custom
     return
   end
   # When waiting for event execution or locked
   if @starting or lock?
     # Not moving by self
     return
   end
   # If stop count exceeds a certain value (computed from move frequency)
   if @stop_count > (40 - @move_frequency * 2) * (6 - @move_frequency)
     # Branch by move type
     case @move_type
     when 1  # Random
       move_type_random
     when 2  # Approach
       move_type_toward_player
     when 3  # Custom
       move_type_custom
     end
   end
 end

end

Also realized that the animation will keep playing forever, so it would be wise to make another Interpreter method that shuts everything off. Simple as just turning @unique_animation to false.

If you still can't get it to work, I can help you out some more tomorrow (10 PM right now).

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!