Running Common Event -> a small script?

Started by MarkHest, April 21, 2012, 04:11:17 pm

Previous topic - Next topic

MarkHest

April 21, 2012, 04:11:17 pm Last Edit: April 21, 2012, 04:14:28 pm by MarkHest
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)
   

ForeverZer0

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
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

KK20

@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

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!

Blizzard

April 21, 2012, 05:03:49 pm #3 Last Edit: April 21, 2012, 05:05:45 pm by Blizzard
*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.
Check out our game brands:

Daygames
Game Night Games
Chugnar Games

Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

MarkHest

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
   

KK20

Common Event: ShowHide

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.

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!

Blizzard

April 21, 2012, 05:30:54 pm #6 Last Edit: April 21, 2012, 05:33:29 pm by Blizzard
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.
Check out our game brands:

Daygames
Game Night Games
Chugnar Games

Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

MarkHest

That worked like a charm!
You're all awesome :3

Level++
To all of you!
   

MarkHest

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 :^_^':
   

nathmatt

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
Join Dead Frontier
Sorry, I will no longer be scripting for RMXP. I may or may not give support for my scripts. I don't have the will to script in RGSS anymore.
My script


KK20

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.

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!

MarkHest

April 30, 2012, 06:16:08 pm #11 Last Edit: April 30, 2012, 06:17:54 pm by MarkHest
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: