I'm attempting to make a dashing system that revolves around the player's stamina, which I had represented by their SP stat; they can only run by pressing shift when their stamina is above a certain level, and their stamina increases when they stand still or walk normally. I had been trying to implement this through a long and complicated parallel process event system on my maps (if you're interested in seeing that, it's here, but it's not really relevant anymore), but I found that that caused issues with my idle animations -- neiljwd suggested a handy script called StandWalkRun by Synthesize/Night Runner. I was unable to find the original source on google, but this is the code that was provided to me:
(Note: my search on Google showed that there is a version of this script for VX Ace, but I am using the RPG Maker XP version instead, as that's my engine!)
This is definitely an interesting script that could work for me. My only real qualm about it is that I want the ability to run to be tied to this stamina stat that I want in my game... I could make the run points represent the stamina stat, but then I have no way of showing the player it, either on the start menu or on the game screen itself (which was why I'd turned SP into Stamina, cause at least then the player could check on their stamina during the game). So after fiddling with it a bit, these are my questions/quandaries with the script:
The most important question: Is there any way to make a visible representation of this invisible run point stat, maybe by making SP equal to it? Is there a script for an RMXP HUD that could show this?
Of lesser importance, but still something I'd love to be answered: Is there a way to restore run points only while walking/standing, not running? I want to make it so after standing or walking normally for x amount of time, your run points fully restore -- I changed line 77 to $game_player.run_points += 100 if @wait_time2 == StandWalkRun::Run_points_restore and tried testing that out, but then it's like I never run out of run points, since I guess they restore while you're running too. If not, then I guess I can just turn off the restore run points by walking and make it so that you can only regain stamina by finding and ingesting energy drinks...
(Note: my search on Google showed that there is a version of this script for VX Ace, but I am using the RPG Maker XP version instead, as that's my engine!)
Code:
# Written by Synthesize# Version 2.70# January 26, 2008 (v1)# Revised: March 1, 2008 (v2)# Revised: September 4, 2010 (v2.5)# Revised: 8 May, 2012 (2.6, NREdit)# Revised: 15 Nov, 2013 (2.7, NREdit)#===============================================================================# Customization#-------------------------------------------------------------------------------module StandWalkRun Use_run = true # Use Run Points? Use_run_sprite = true# Use a Running sprite? Run_speed = 5 # Player speed while running Walk_speed = 4 # Player speed while walking Run_sprite_suffix = '_dash' # Running Sprite Suffix Run_points = 100 # The maximum amount of Run Points Run_points_restore = 500 # 1 Run Point is restored in X Frames Restore_run_while_walking = true # Restore points while walking? Use_idle_sprite = true # Use Idle Sprite? Idle_sprite_suffix = '_idle' # idle Sprite Suffix Use_anime = true # Animate your Idle Sprite? Idle_time = 100 # Time before sprite is animatedend#-------------------------------------------------------------------------------# Scene_Map:: The main functions of the script are here#-------------------------------------------------------------------------------class Scene_Map # Aliases alias syn_map_update update #----------------------------------------------------------------------------- # Initiate variables #----------------------------------------------------------------------------- def initialize if $game_player.old_character_name == nil $game_player.old_character_name = $game_player.character_name end @wait_time = 0 @wait_time2 = 0 end #----------------------------------------------------------------------------- # Update:: Update the scene #----------------------------------------------------------------------------- def update syn_map_update if Input.dir4 == 0 wait(1, false) if StandWalkRun::Use_idle_sprite if $game_player.move_route_forcing == false call_idle($game_player.character_name + StandWalkRun::Idle_sprite_suffix, StandWalkRun::Use_anime) if @wait_time == StandWalkRun::Idle_time $game_temp.syn_state = "idle" end #restore_run if StandWalkRun::Use_run else $game_temp.syn_state = "" restore_run if StandWalkRun::Restore_run_while_walking call_idle($game_player.old_character_name, false) if $game_player.character_name != $game_player.old_character_name @wait_time = 0 end if $game_temp.sprite_changed == true $game_player.old_character_name = $game_player.character_name $game_temp.sprite_changed = false end end #----------------------------------------------------------------------------- # Call_Idle:: Sets and animates the idle Sprite #----------------------------------------------------------------------------- def call_idle(sprite, anime) $game_player.set_step_anime(anime) $game_player.set_graphic(sprite) end #----------------------------------------------------------------------------- # Restore_Run: Restore Run Points #----------------------------------------------------------------------------- def restore_run if $game_player.run_points < $game_player.max_run_points wait(1, true) $game_player.run_points += 10 if @wait_time2 == StandWalkRun::Run_points_restore @wait_time2 = 0 if @wait_time2 == StandWalkRun::Run_points_restore end end #----------------------------------------------------------------------------- # Wait:: Allows Wait Times #----------------------------------------------------------------------------- def wait(duration, value) for i in 0...duration @wait_time += 1 if value == false @wait_time2 += 1 if value break if i >= duration / 2 end endend #-------------------------------------------------------------------------------# Game_Temp:: Create current state#-------------------------------------------------------------------------------class Game_Temp attr_accessor :syn_state attr_accessor :sprite_changed alias syn_temp_init initialize def initialize @syn_state = "" @sprite_changed = false syn_temp_init endend#-------------------------------------------------------------------------------# Game_Character:: Create the Change_Sprite method#-------------------------------------------------------------------------------class Game_Character # Attr(s) attr_accessor :old_character_name attr_accessor :run_points attr_accessor :max_run_points alias syn_ch_init initialize #----------------------------------------------------------------------------- # Initialize Variables #----------------------------------------------------------------------------- def initialize @run_points = StandWalkRun::Run_points @max_run_points = @run_points syn_ch_init end #----------------------------------------------------------------------------- # Set Setp Animation #----------------------------------------------------------------------------- def set_step_anime(value) @step_anime = value return @step_anime endend#-------------------------------------------------------------------------------# Game_Player:: This handles the dash process#-------------------------------------------------------------------------------class Game_Player < Game_Character alias syn_player_initialize initialize alias syn_player_update update alias syn_player_refresh refresh alias syn_player_move_type_custom move_type_custom def initialize(*args, &blk) ret_val = syn_player_initialize(*args, &blk) set_walk_speed(StandWalkRun::Walk_speed) set_run_speed(StandWalkRun::Run_speed) end def dash? return false if @run_points == 0 and StandWalkRun::Use_run return true if Input.press?(Input::A) end def refresh syn_player_refresh self.old_character_name = @character_name end def set_run_speed(val) @ty_RunWalk_run_speed = [[@ty_RunWalk_walk_speed + 1, val.to_i].max, 7].min end def set_walk_speed(val) @ty_RunWalk_walk_speed = [[val.to_i, 1].max, 6].min set_run_speed(val + 1) end #----------------------------------------------------------------------------- # Update:: Update the scene #---------------------------------------------------------------------------- def update if dash? if Input.dir4 == 0 $game_player.set_graphic($game_player.old_character_name) end unless $game_temp.syn_state == "idle" if StandWalkRun::Use_run_sprite set_graphic(@character_name + StandWalkRun::Run_sprite_suffix) end @move_speed = @ty_RunWalk_run_speed @run_points -= 1 syn_player_update end else @move_speed = @ty_RunWalk_walk_speed syn_player_update end end def set_graphic(character_name) @tile_id = 0 @character_name = character_name end #-------------------------------------------------------------------------- # * Move Type : Custom #-------------------------------------------------------------------------- def move_type_custom old_ch_name = @character_name syn_player_move_type_custom if old_ch_name != @character_name # Change Graphic self.old_character_name = @character_name end endend#-------------------------------------------------------------------------------# * This script is not compatible with RPG Maker XP * YES IT IS LOL#-------------------------------------------------------------------------------# Written by Synthesize# Version 2.7# Requested by Cerulean Sky
The most important question: Is there any way to make a visible representation of this invisible run point stat, maybe by making SP equal to it? Is there a script for an RMXP HUD that could show this?
Of lesser importance, but still something I'd love to be answered: Is there a way to restore run points only while walking/standing, not running? I want to make it so after standing or walking normally for x amount of time, your run points fully restore -- I changed line 77 to $game_player.run_points += 100 if @wait_time2 == StandWalkRun::Run_points_restore and tried testing that out, but then it's like I never run out of run points, since I guess they restore while you're running too. If not, then I guess I can just turn off the restore run points by walking and make it so that you can only regain stamina by finding and ingesting energy drinks...