Player : Dash

Player : Dash
Version: 3.5
By: Kain Nobel

Introduction

This is a running (or "dashing" if we may) system, requested by Reon-Eclispe, which allows the player to dash for a designated period of time until they've depleted their stamina. The settings are instances of Game_Player::Dash, meaning you'll be able to modify, save and load them between game sessions.

I hate to say it but the settings are a bit touchy, you might want to experiment with whatever is suitable for your game. However, I'm sure you'll enjoy it once you get the hang of it!

Features

  • One-button running feature!
  • Easy to setup and control!
  • Customizable speeds for different movement phases
  • Player can be exhausted from running too much
  • Compatable with my Vehicles XP (not yet released)
  • Probably other stuff I'm too lazy to list right now

Script

Player : Dash Spoiler
  1. #===============================================================================
  2. # ** Player : Dash
  3. #===============================================================================
  4.  
  5. #-------------------------------------------------------------------------------
  6. # * SDK Log
  7. #-------------------------------------------------------------------------------
  8. SDK.log('Player.Dash', 'Kain Nobel ©', 3.5, '2009.06.17')
  9. #-------------------------------------------------------------------------------
  10. # * SDK Enabled Test : Begin
  11. #-------------------------------------------------------------------------------
  12. if SDK.enabled?('Player.Dash')
  13.  
  14. #===============================================================================
  15. # ** Game_Player::Dash
  16. #===============================================================================
  17.  
  18. class Game_Player::Dash
  19.   #-----------------------------------------------------------------------------
  20.   # * Switch which disables the dash system and HUD
  21.   #-----------------------------------------------------------------------------
  22.   Switch_Disable = 1
  23.   #-----------------------------------------------------------------------------
  24.   # * Switch which disables exhaustion
  25.   #-----------------------------------------------------------------------------
  26.   Switch_Exhaust = 2
  27.   #-----------------------------------------------------------------------------
  28.   # * Maps which disable the dash system and HUD
  29.   #-----------------------------------------------------------------------------
  30.   Maps_Disabled  = []
  31.   #-----------------------------------------------------------------------------
  32.   # * Scenes which don't display dash HUD (alternate scenes with Spriteset_Map)
  33.   #-----------------------------------------------------------------------------
  34.   Scenes_Disabled = true
  35.   #-----------------------------------------------------------------------------
  36.   # * Button used for Dashning
  37.   #-----------------------------------------------------------------------------
  38.   Button = Input::C
  39.   #-----------------------------------------------------------------------------
  40.   # * Public Instance Variables
  41.   #-----------------------------------------------------------------------------
  42.   attr_accessor :slow_speed
  43.   attr_accessor :walk_speed
  44.   attr_accessor :dash_speed
  45.   attr_accessor :stamina
  46.   attr_accessor :points
  47.   #-----------------------------------------------------------------------------
  48.   # * Object Initialization
  49.   #-----------------------------------------------------------------------------
  50.   def initialize
  51.     @slow_speed   = 3                       # Speed for when player is exhausted
  52.     @walk_speed   = 3.5                     # Speed for when player is walking
  53.     @dash_speed   = 5                       # Speed for when player is dashing
  54.     @stamina      = 1                       # Steps player can take while dashing
  55.     @stamina_rate = 0.01                    # Frames that stamina is replenished
  56.     @exhersion    = @stamina / 8            # At the point where player exhausted
  57.     @points       = @stamina                # Sets points to stamina (don't touch)
  58.   end
  59.   #-----------------------------------------------------------------------------
  60.   # * Enabled?
  61.   #-----------------------------------------------------------------------------
  62.   def enabled?
  63.     return false if $game_switches[Switch_Disable]
  64.     return false if Maps_Disabled[$game_map.map_id]
  65.     if Scenes_Disabled == true
  66.       return false unless $scene.is_a?(Scene_Map)
  67.     else
  68.       return false if Scenes_Disabled.include?($scene.class.to_s)
  69.     end
  70.     return true
  71.   end
  72.   #-----------------------------------------------------------------------------
  73.   # * Increase Points
  74.   #-----------------------------------------------------------------------------
  75.   def increase_points(n)
  76.     @points = [[@points + n, @stamina].min, 0].max
  77.   end
  78.   #-----------------------------------------------------------------------------
  79.   # * Decrease Points
  80.   #-----------------------------------------------------------------------------
  81.   def decrease_points(n)
  82.     increase_points(-n)
  83.   end
  84.   #-----------------------------------------------------------------------------
  85.   # * Update
  86.   #-----------------------------------------------------------------------------
  87.   def update
  88.     unless enabled?
  89.       update_disabled
  90.       return
  91.     end
  92.     @disabled = false
  93.     if idle?
  94.       update_idle
  95.       return
  96.     elsif exhausted?
  97.       update_exhausted
  98.       return
  99.     elsif walking?
  100.       update_walking
  101.       return
  102.     elsif dashing?
  103.       update_dashing
  104.       return
  105.     end
  106.   end
  107.   #-----------------------------------------------------------------------------
  108.   # * Update Disabled
  109.   #-----------------------------------------------------------------------------
  110.   def update_disabled
  111.     unless @disabled
  112.       $game_player.move_speed = (Game_Player.new).move_speed
  113.       @disabled = true
  114.     end
  115.   end
  116.   #-----------------------------------------------------------------------------
  117.   # * Idle?
  118.   #-----------------------------------------------------------------------------
  119.   def idle?
  120.     !$game_player.moving?
  121.   end
  122.   #-----------------------------------------------------------------------------
  123.   # * Exhausted?
  124.   #-----------------------------------------------------------------------------
  125.   def exhausted?
  126.     @exhausted && !$game_switches[Switch_Exhaust]
  127.   end
  128.   #-----------------------------------------------------------------------------
  129.   # * Walking?
  130.   #-----------------------------------------------------------------------------
  131.   def walking?
  132.     return true if $game_player.move_route_forcing
  133.     $game_player.moving? && !Input.press?(Button)
  134.   end
  135.   #-----------------------------------------------------------------------------
  136.   # * Dashing?
  137.   #-----------------------------------------------------------------------------
  138.   def dashing?
  139.     return false if $game_system.map_interpreter.running?
  140.     return false if $game_temp.message_window_showing
  141.     return false if $game_player.move_route_forcing
  142.     $game_player.moving? && Input.press?(Button)
  143.   end
  144.   #-----------------------------------------------------------------------------
  145.   # * Update Idle
  146.   #-----------------------------------------------------------------------------
  147.   def update_idle
  148.     increase_points(exhausted? ? @stamina_rate * 0.5 : @stamina_rate)
  149.     if @points > (@exhersion)
  150.       @exhausted = false
  151.     end
  152.   end
  153.   #-----------------------------------------------------------------------------
  154.   # * Update Exhausted
  155.   #-----------------------------------------------------------------------------
  156.   def update_exhausted
  157.     $game_player.move_speed = @slow_speed
  158.     increase_points(@stamina_rate * 0.5)
  159.     if @points > (@exhersion)
  160.       @exhausted = false
  161.     end
  162.   end
  163.   #-----------------------------------------------------------------------------
  164.   # * Update Walking
  165.   #-----------------------------------------------------------------------------
  166.   def update_walking
  167.     $game_player.move_speed = @walk_speed
  168.     increase_points(@stamina_rate * 0.5)
  169.   end
  170.   #-----------------------------------------------------------------------------
  171.   # * Update Dashing
  172.   #-----------------------------------------------------------------------------
  173.   def update_dashing
  174.     unless $game_player.move_speed == @dash_speed
  175.       $game_player.move_speed += (@dash_speed * 0.1)
  176.       return
  177.     end
  178.     decrease_points(@stamina_rate * 2)
  179.     if @points.zero?
  180.       @exhausted = true
  181.     end
  182.   end
  183.   #-----------------------------------------------------------------------------
  184.   # * Last Move
  185.   #-----------------------------------------------------------------------------
  186.   def last_move
  187.     return 0 if idle?
  188.     return 1 if exhausted?
  189.     return 2 if walking?
  190.     return 3 if dashing?
  191.   end
  192. end
  193.  
  194. #===============================================================================
  195. # ** Game_Player
  196. #===============================================================================
  197.  
  198. class Game_Player < Game_Character
  199.   #-----------------------------------------------------------------------------
  200.   # * Public Instance Variables
  201.   #-----------------------------------------------------------------------------
  202.   attr_accessor :move_speed
  203.   #-----------------------------------------------------------------------------
  204.   # * Alias Listings
  205.   #-----------------------------------------------------------------------------
  206.   alias_method :dashsystem_gmplayer_updateplayermove, :update_player_movement
  207.   #-----------------------------------------------------------------------------
  208.   # * Dash
  209.   #-----------------------------------------------------------------------------
  210.   def dash
  211.     @dash ||= Game_Player::Dash.new
  212.     @dash
  213.   end
  214.   #-----------------------------------------------------------------------------
  215.   # * Update
  216.   #-----------------------------------------------------------------------------
  217.   def update_player_movement
  218.     dashsystem_gmplayer_updateplayermove
  219.     @dash.update
  220.   end
  221. end
  222.  
  223. #===============================================================================
  224. # ** Window_DashStamina
  225. #===============================================================================
  226.  
  227. class Window_DashStamina < Window_Base
  228.   #-----------------------------------------------------------------------------
  229.   # * Object Initialization
  230.   #-----------------------------------------------------------------------------
  231.   def initialize
  232.     super(0, 416, 160, 64)
  233.     self.contents = Bitmap.new(width - 32, height - 32)
  234.     self.opacity = 0
  235.     refresh
  236.   end
  237.   #-----------------------------------------------------------------------------
  238.   # * Refresh
  239.   #-----------------------------------------------------------------------------
  240.   def refresh
  241.     self.contents.clear
  242.     @points    = $game_player.dash.points
  243.     @last_move = $game_player.dash.last_move
  244.     self.contents.draw_seph_gradient_bar(0, 0, @points,
  245.     $game_player.dash.stamina, 128)
  246.     if $game_player.dash.idle?
  247.       color = ($game_player.dash.exhausted? ? Color.new(255,0,0) : normal_color)
  248.       self.contents.font.color = color
  249.       self.contents.draw_text(0, 0, 128, 32, "Idle", 1)
  250.     elsif $game_player.dash.exhausted?
  251.       self.contents.font.color = Color.new(255,0,0)
  252.       self.contents.draw_text(0, 0, 128, 32, "Exhausted", 1)
  253.     elsif $game_player.dash.walking?
  254.       self.contents.font.color = normal_color
  255.       self.contents.draw_text(0, 0, 128, 32, "Walking", 1)
  256.     elsif $game_player.dash.dashing?
  257.       self.contents.font.color = system_color
  258.       self.contents.draw_text(0, 0, 128, 32, "Dashing", 1)
  259.     end
  260.   end
  261.   #-----------------------------------------------------------------------------
  262.   # * Update?
  263.   #-----------------------------------------------------------------------------
  264.   def update?
  265.     need_update = false
  266.     need_update |= $game_player.dash.points    != @points
  267.     need_update |= $game_player.dash.last_move != @last_move
  268.     (need_update && Graphics.frame_count % 4 == 1)
  269.   end
  270.   #-----------------------------------------------------------------------------
  271.   # * Update
  272.   #-----------------------------------------------------------------------------
  273.   def update
  274.     self.visible = $game_player.dash.enabled?
  275.     if update?
  276.       refresh
  277.     end
  278.   end
  279. end
  280.  
  281. #===============================================================================
  282. # ** Spriteset_Map
  283. #===============================================================================
  284.  
  285. class Spriteset_Map
  286.   #-----------------------------------------------------------------------------
  287.   # * Alias Lisitngs
  288.   #-----------------------------------------------------------------------------
  289.   alias_method :dashsystem_ssmap_initialize, :initialize
  290.   alias_method :dashsystem_ssmap_update,     :update
  291.   alias_method :dashsystem_ssmap_dispose,    :dispose
  292.   #-----------------------------------------------------------------------------
  293.   # * Object Initialization
  294.   #-----------------------------------------------------------------------------
  295.   def initialize
  296.     @window_dashstamina = Window_DashStamina.new
  297.     dashsystem_ssmap_initialize
  298.   end
  299.   #-----------------------------------------------------------------------------
  300.   # * Update
  301.   #-----------------------------------------------------------------------------
  302.   def update
  303.     @window_dashstamina.update
  304.     dashsystem_ssmap_update
  305.   end
  306.   #-----------------------------------------------------------------------------
  307.   # * Dispose
  308.   #-----------------------------------------------------------------------------
  309.   def dispose
  310.     @window_dashstamina.dispose
  311.     dashsystem_ssmap_dispose
  312.   end
  313. end
  314.  
  315. #-------------------------------------------------------------------------------
  316. # * SDK Enabled Test : End
  317. #-------------------------------------------------------------------------------
  318. end
Expand to see the code.


Instructions

Place below SDK/MACL and above Main! Setup is handled by the constants in the top of the script, if you have any questions or are confused don't hesitate to ask! This script uses the following method from MACL's "RGSS.Bitmap.gradient" library...

Bitmap.draw_seph_gradient_bar

Compatibility

Requires SDK stuffs, you can easily alias Game_Player::Dash.enabled? to allow other scripts to disable this system. This script is compatable with my Vehicles XP system (which I haven't released yet.)

Please note, this will corrupt old save files.

Credits and Thanks

Thanks to Reon-Eclispe for making the request, it was fun and I enjoyed doing this one!

Terms and Conditions

Free to use in commercial and non-commercial projects, please credit me for my work!
Small update! Player won't run during evented moveroutes or anything anymore! Same update applied to jump script too (no jumping during messages lol) :P

Also, I realised some people might get a problem because Game_Player#@move_speed isn't an attr_accessor, so I updated that too.

Happy 4th people!
I'm new to scripts and rpg maker in general, so could you tell me what SDK is?
never mind :)
but i get an error on line 231:
@points = $game_player.dash.points
do you know what the problem is?
I'm not sure how you would've gotten the error, do you have any scripts that make a custom initialize method for Game_Player class without calling an alias or alias_method? If you do, you might want to try and put it below those scripts, when in doubt put it as your last custom script but above main.

Also, this snippet might help, place it somewhere within the script itself...

Patch Spoiler
class Game_Player
def dash
@dash ||= Game_Player::Dash.new
@dash
end
end


That'll ensure, if @dash is nil, then it is loaded. If you're still having problems, you might want to list your custom scripts you're using and I'll try and help you out. Best bet would be sending me a demo or just your Scripts.rxdata file, that would be the easiest way for me to find out why it isn't working.
I don't know what I'm doing wrong, but I can't get this script to work at all. I'd really like to use it but it just doesn't seem to want to work.

To make sure it wasn't conflicting with anything I made an entirely new project and added the SDK, MACL, and Player : Dash. No matter what I do nothing from this script works except the dash bar and text which appear (and have that irritating flashing thing...). I've tried changing the stamina, and I've even lowered the walking speed to 1 and the character doesn't move any slower.

And the SDK breaks Sideview Battle System Tankentai XP - Version 2.2xp so I'd appreciate it if you could possibly make it compatible without the SDK?

This really is a great idea and if I could get it to work I'd absolutely love it I'm sure. Thank you for your time.
I like this script thank you so much
Thanks for making the script, but is there a way to turn off the gradient bar?

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