Chaos Project

RPG Maker => RPG Maker Scripts => Script Requests => Topic started by: MarkHest on April 21, 2012, 04:11:17 pm

Title: Running Common Event -> a small script?
Post by: MarkHest on April 21, 2012, 04:11:17 pm
In The Missing Part i am using an event command that allows the player to run while holding the 'W' button... and it works just fine!
Exept for one small thing that has been starting to bug me a bit. Because the Common Event is a parallel process i always need to turn off the switch to the Common Event when i use a movement route command for the character or else it will be overridden by the Common Event and the character will only move one step and then stop.

So my question is, will you help getting me a script that allows the exact same function (Run when pressing 'W') but is has a built in function that makes it so i do not have to turn off a switch whenever i use the Movement Route Command for the character.

Just in case someone feels like helping me out a bit i would be very happy :haha:
Or you could just tell me that i am lazy and i should go on the way i am doing it :>.<:

(I once used a script that also allows an Idle animation while not moving that has this run function, but it was too buggy)
Title: Re: Running Common Event -> a small script?
Post by: ForeverZer0 on April 21, 2012, 04:36:45 pm
class Game_Player
 
  DEFAULT_SPEED = 3
  RUN_SPEED = 4
  RUN_BUTTON = Input::SHIFT
 
  alias run_button_update update
  def update
    @move_speed = Input.press?(RUN_BUTTON) ? RUN_SPEED : DEFAULT_SPEED
    run_button_update
  end
end
Title: Re: Running Common Event -> a small script?
Post by: KK20 on April 21, 2012, 04:58:06 pm
@F0
If you hold down shift and then talk to an NPC that forces a move route on the player, you still move at run speed. Actually, you can hold down and let go during the move route to change the player's speed.

So I threw !@move_route_forcing in:
class Game_Player
 
  DEFAULT_SPEED = 3
  RUN_SPEED = 4
  RUN_BUTTON = Input::SHIFT
 
  alias run_button_update update
  def update
    @move_speed = (!@move_route_forcing and Input.press?(RUN_BUTTON)) ? RUN_SPEED : DEFAULT_SPEED
    run_button_update
  end
end


Cookie? :3
Title: Re: Running Common Event -> a small script?
Post by: Blizzard on April 21, 2012, 05:03:49 pm
*gives KK20 a cookie*

Just keep in mind that this will override any movement speed set by event commands.
Of course there is a way to avoid that as well.
Title: Re: Running Common Event -> a small script?
Post by: MarkHest on April 21, 2012, 05:15:50 pm
Aww... that was a great script KK20 and F0, but i kinda need the character to be able to change speed with events as well :P
Title: Re: Running Common Event -> a small script?
Post by: KK20 on April 21, 2012, 05:28:34 pm
Common Event: ShowHide
(http://i1067.photobucket.com/albums/u430/kirbykid20/Run.png)

And the small edit:
class Game_Player
  attr_writer :move_speed
  def force_move_route(move_route)
    @move_speed = 3 # <- Change this to whatever default walking speed is
    super(move_route)
  end
end

This assumes that walking and running speed are forever constant--like you don't get an item that makes you walk/run faster.
Title: Re: Running Common Event -> a small script?
Post by: Blizzard on April 21, 2012, 05:30:54 pm
Blizzard to the rescue: ShowHide
class Game_Player
 
 RUN_SPEED = 4
 RUN_BUTTON = Input::SHIFT
 
 alias run_button_update update
 def update
   if !@move_route_forcing && Input.press?(RUN_BUTTON)
     if !@forced_speed
       @prev_speed = @move_speed
       @move_speed = RUN_SPEED
       @forced_speed = true
     end
   elsif @forced_speed
     @move_speed = @prev_speed
     @forced_speed = false
   end
   run_button_update
 end
 
end


You only may have to be careful to not change the speed immediately in the beginning of the move route. Put a frame wait of 1 first so the code can first restore the normal moving speed before you go ahead and change it. It might actually work without that, but safe is safe.
Title: Re: Running Common Event -> a small script?
Post by: MarkHest on April 21, 2012, 06:28:51 pm
That worked like a charm!
You're all awesome :3

Level++
To all of you!
Title: Re: Running Common Event -> a small script?
Post by: MarkHest on April 30, 2012, 04:36:41 pm
Oh shit! I totaly forgot something really important!

There are moments in this game where i used to turn off the Run Event because i had an event in game that made the character unable to run.
Is there a way i can turn on/off this script for those pericular moments. I totaly forgot i had these things going on in the game, hehe :^_^':
Title: Re: Running Common Event -> a small script?
Post by: nathmatt on April 30, 2012, 05:15:21 pm
class Game_Player
 
  SWITCH_ID = 1
  RUN_SPEED = 4
  RUN_BUTTON = Input::SHIFT
 
  alias run_button_update update
  def update
    return run_button_update if $game_switches[SWITCH_ID]
    if !@move_route_forcing && Input.press?(RUN_BUTTON)
      if !@forced_speed
        @prev_speed = @move_speed
        @move_speed = RUN_SPEED
        @forced_speed = true
      end
    elsif @forced_speed
      @move_speed = @prev_speed
      @forced_speed = false
    end
    run_button_update
  end
 
end
Title: Re: Running Common Event -> a small script?
Post by: KK20 on April 30, 2012, 06:00:25 pm
Small bug: If the game switch is turned on while the player has the key held down, your character moves at run speed until the switch is turned off again.

class Game_Player
  attr_accessor :move_speed
  SWITCH_ID = 1
  RUN_SPEED = 4
  RUN_BUTTON = Input::SHIFT
 
  alias run_button_update update
  def update
    if $game_switches[SWITCH_ID]
      if @forced_speed
        @move_speed = @prev_speed
        @forced_speed = false
      end
    elsif !@move_route_forcing && Input.press?(RUN_BUTTON)
      if !@forced_speed
        @prev_speed = @move_speed
        @move_speed = RUN_SPEED
        @forced_speed = true
      end
    elsif @forced_speed
      @move_speed = @prev_speed
      @forced_speed = false
    end
    run_button_update
  end
 
end

Quote from: Blizzard on April 21, 2012, 05:30:54 pm
You only may have to be careful to not change the speed immediately in the beginning of the move route. Put a frame wait of 1 first so the code can first restore the normal moving speed before you go ahead and change it. It might actually work without that, but safe is safe.
Is true.
Title: Re: Running Common Event -> a small script?
Post by: MarkHest on April 30, 2012, 06:16:08 pm
Quote from: BlizzardYou only may have to be careful to not change the speed immediately in the beginning of the move route. Put a frame wait of 1 first so the code can first restore the normal moving speed before you go ahead and change it. It might actually work without that, but safe is safe.

Yes, i noticed that i need to but at least a 1 frame wait command before changing the speed at the start of a move route command or the movement speed would be 5 if the player had the 'run' button pressed.


That edit worked perfectly! I thank you once again :)

This makes me a happy man :haha: