Snippet Request - Customizable Player / Vehicle speed changer

Good Morning / Day / Afternoon / Evening everyone.

I have a request for a certain kind of snippet

Let's say I want players and to move on value 3 in world map, and on value 4 in town and dungeon maps.

There is already this script, but there doesn't seem a way to specify a specific map where this can be applied on, let's say with a notetag on the map id or somethng

Ruby:
#-------------------------------------------------------------------
# Custom Movement Speed
# A simple script made by Ellye.
# This is a free and unencumbered script, provided "as is", no warranties.
#-------------------------------------------------------------------


#-------------------------------------------------------------------
# * Options:
#-------------------------------------------------------------------

# Base speed for every moving character. Default RPG Maker value is 4.
$base_character_speed = 4

# Player movement speed. Default RPG Maker value is 4.
$player_speed = 2

# Player dashing speed bonus. Default RPG Maker value is 1.
# You can also set a negative value, so that you'd have a
# "Walk / Sneaky Button" instead of a "Dash Button".
$dash_speed = 3

# Vehicules movement speed. Default RPG Maker values are 5, 6 and 7.
$boat_speed = 5
$ship_speed = 6
$airship_speed = 5

#-------------------------------------------------------------------
#-------------------------------------------------------------------
#-------------------------------------------------------------------


class Game_CharacterBase
  #Add custom movement speed to characters Init
  alias :old_init_public_members :init_public_members
  def init_public_members
    old_init_public_members
    @move_speed = $base_character_speed
  end

  #Add custom dash bonus speed
  alias :old_real_move_speed :real_move_speed
  def real_move_speed
    old_real_move_speed
    return @move_speed + (dash? ? $dash_speed : 0)
  end

end

class Game_Player
  #Adds an accessor to move_speed, so that it can be manipulated by
  #Scripts in Events and Common Events more easily (always remember
  #to check for vehicles if you do that.)
  attr_accessor :move_speed

  #Add custom movement speed to player Init
  alias :old_initialize :initialize
  def initialize
    old_initialize
    @move_speed = $player_speed
  end

  #The default get_off_vehicle method sets the player speed to 4...
  alias :old_get_off_vehicule :get_off_vehicle
  def get_off_vehicle
    old_get_off_vehicule
    if vehicle.land_ok?(@x, @y, @direction)
      @move_speed = $player_speed
    end
  end
end

class Game_Vehicle
  #Set custom Vehicle speeds
  alias :old_init_move_speed :init_move_speed
  def init_move_speed
    old_init_move_speed
    @move_speed = $boat_speed if @type == :boat
    @move_speed = $ship_speed if @type == :ship
    @move_speed = $airship_speed if @type == :airship
  end
end

Is there a way to achieve this? To make it so

1. Being able to assign different movement speeds for player, npcs and vehicles, for specific maps.
Iam no Scripter, but you could try to assign a Variable instead of a constant.
Change this line:
$player_speed = 2
to this:
$player_speed = $game_variables[23]

If we are lucky no error occurs if variable is equal to 0 at game start.
Variable 23 would determine how fast the player moves.
0aaaaaaa.png

nope
I am looking for something that will make it so for example when the player character is on a specific map id, it's movement speed will be set to a certain value.

Same for vehicles-


If I could code I could make it so I could add a note tag on the map that would do just that.
You can change the player move speed at any time via events like this:
movespeed.PNG

Or by using the script call "$game_player.move_speed = x" because the script you use built an accessor for it, even though it can be done by events already.

For vehicles it's not that easy and would require quite a few changes to Game_Vehicle including a proper update method to avoid screwing over speeds in case there are different vehicles used on the same map.
For specific maps I use this conditional
Code:
if $game_map.map_id == n
You must replace the letter n with the desired map id.
If there is more than one map @A-Moonless-Night gave an example below, correcting an error that I had made in my code. Take a look!
😉
Actually for several map ID's it'd be more convenient to use...

Code:
case $game_map.map_id
when 1
  $game_player.move_speed = 5
when 2
  $game_player.move_speed = 6
else
  $game_player.move_speed = 4
end

the when keyword also allows you to add several arguments in a row like 1,3,5.
Alternatively you could also use a script I wrote years ago in case you want to make speed changes to certain regions rather than just map based. It has a few features regarding customizaion, includes step sounds aswell as sneaking and jumping mechanics. Though it doesn't cover vehicles. If you're interested, just let me know
If there is more than one map for the same condition, it will be necessary to separate as follows:
Code:
if $game_map.map_id == n1 || n2 || n3
(This separator means "or")
😉
That won't work. The system will check if $game_map.map_id == n1 is true, or if n2 is true, or if n3 is true (which, if they are numbers, automatically result in true because of how Ruby determines truthiness). To do it the way you're intending, you would need to do $game_map.map_id == n1 || $game_map.map_id == n2 || $game_map.map_id == n3, or [n1, n2, n3].include?($game_map.map_id)
Err, I insist in using the case statement instead for readability and debugging purposes.
Try this.
I modified the script you posted to have map id's specified.
Turn the switch on that you set and it will use the map id's. turn the switch off and it will do what the script originally was.
Only has one glitch I'm trying to figure out. When boarding the airship the speed change is not applied until you exit and board the airship again.
Spoiler: Modded script
Ruby:
#-------------------------------------------------------------------
# Custom Movement Speed
# A simple script made by Ellye.
# This is a free and unencumbered script, provided "as is", no warranties.
# Modified by Roninator2
# Now allows to specify which maps have different speeds. 
#-------------------------------------------------------------------
module R2_Map_Speed
    # change the number to include the maps where your speed needs to be changed
MAP_SPEED = { :crawl => [19, 20],
                            :slow  => [1, 3, 4, 5, 6],
                            :normal => [7, 8, 9, 10],
                            :fast  => [2, 11,12,13,14,15,16],
                            :ultra => [17, 18]
            }
SPEED_OFF = 1  # switch used to turn on map speed control above
# turn switch on to use the map id for speed control.
#-------------------------------------------------------------------
# * Options:
#-------------------------------------------------------------------

# Base speed for every moving character. Default RPG Maker value is 4.
Base_character_speed = 4

# Player movement speed. Default RPG Maker value is 4. Use either 3, 4 or 5.
Player_speed = 4

# Player dashing speed bonus. Default RPG Maker value is 1.
# You can also set a negative value, so that you'd have a
# "Walk / Sneaky Button" instead of a "Dash Button".
Dash_speed = 1

# Vehicules movement speed. Default RPG Maker values are 5, 6 and 7.
Boat_speed = 4
Ship_speed = 5
Airship_speed = 6

# when switch is on this will add to the speed when in a vehicle. 
# Optional
Vehicle_bonus = 0
end
#-------------------------------------------------------------------
#-------------------------------------------------------------------
#-------------------------------------------------------------------


class Game_CharacterBase
  #Add custom movement speed to characters Init
  alias :old_init_public_members :init_public_members
  def init_public_members
    old_init_public_members
    @move_speed = R2_Map_Speed::Base_character_speed
  end

  #Add custom dash bonus speed
  alias :old_real_move_speed :real_move_speed
  def real_move_speed
    old_real_move_speed
    return @move_speed + (dash? ? R2_Map_Speed::Dash_speed : 0)
  end

end

class Game_Player
  #Add custom movement speed to player Init
  alias :old_initialize :initialize
  def initialize
    old_initialize
    @move_speed = R2_Map_Speed::Player_speed
  end
  #--------------------------------------------------------------------------
  # * Execute Player Transfer
  #--------------------------------------------------------------------------
  def perform_transfer
    if transfer?
      set_direction(@new_direction)
      if @new_map_id != $game_map.map_id
        $game_map.setup(@new_map_id)
        $game_map.autoplay
      end
      moveto(@new_x, @new_y)
      @move_speed = R2_Map_Speed::Player_speed
      if $game_switches[R2_Map_Speed::SPEED_OFF] == true
        if R2_Map_Speed::MAP_SPEED[:crawl].include?($game_map.map_id)
          @move_speed -= 2
        elsif R2_Map_Speed::MAP_SPEED[:slow].include?($game_map.map_id)
          @move_speed -= 1
        elsif R2_Map_Speed::MAP_SPEED[:normal].include?($game_map.map_id)
          @move_speed = 4
        elsif R2_Map_Speed::MAP_SPEED[:fast].include?($game_map.map_id)
          @move_speed += 1
        elsif R2_Map_Speed::MAP_SPEED[:ultra].include?($game_map.map_id)
          @move_speed += 2
        end
      else
      end
      clear_transfer_info
    end
  end
  
  #The default get_off_vehicle method sets the player speed to 4...
  alias :old_get_off_vehicule :get_off_vehicle
  def get_off_vehicle
      old_get_off_vehicule
      @move_speed = R2_Map_Speed::Player_speed
      if $game_switches[R2_Map_Speed::SPEED_OFF] == true
        if R2_Map_Speed::MAP_SPEED[:crawl].include?($game_map.map_id)
          @move_speed -= 2
        elsif R2_Map_Speed::MAP_SPEED[:slow].include?($game_map.map_id)
          @move_speed -= 1
        elsif R2_Map_Speed::MAP_SPEED[:normal].include?($game_map.map_id)
          @move_speed = 4
        elsif R2_Map_Speed::MAP_SPEED[:fast].include?($game_map.map_id)
          @move_speed += 1
        elsif R2_Map_Speed::MAP_SPEED[:ultra].include?($game_map.map_id)
          @move_speed += 2
        end
      end
  end
end

class Game_Vehicle
  #Set custom Vehicle speeds
  alias r2_move_get_on_speed  get_on
  def get_on
    r2_move_get_on_speed
    @move_speed = R2_Map_Speed::Boat_speed if @type == :boat
    @move_speed = R2_Map_Speed::Ship_speed if @type == :ship
    @move_speed = R2_Map_Speed::Airship_speed if @type == :airship
        if $game_switches[R2_Map_Speed::SPEED_OFF] == true
            if R2_Map_Speed::MAP_SPEED[:crawl].include?(@map_id)
                @move_speed += R2_Map_Speed::Vehicle_bonus 
            elsif R2_Map_Speed::MAP_SPEED[:slow].include?(@map_id)
                @move_speed += R2_Map_Speed::Vehicle_bonus 
            elsif R2_Map_Speed::MAP_SPEED[:normal].include?(@map_id)
                @move_speed += R2_Map_Speed::Vehicle_bonus 
            elsif R2_Map_Speed::MAP_SPEED[:fast].include?(@map_id)
                @move_speed += R2_Map_Speed::Vehicle_bonus 
            elsif R2_Map_Speed::MAP_SPEED[:ultra].include?(@map_id)
                @move_speed += R2_Map_Speed::Vehicle_bonus 
            else
                @move_speed += R2_Map_Speed::Vehicle_bonus 
            end
        else
        end
  end
end
That won't work. The system will check if $game_map.map_id == n1 is true, or if n2 is true, or if n3 is true (which, if they are numbers, automatically result in true because of how Ruby determines truthiness). To do it the way you're intending, you would need to do $game_map.map_id == n1 || $game_map.map_id == n2 || $game_map.map_id == n3, or [n1, n2, n3].include?($game_map.map_id)
@A-Moonless-Night I always forget about it! 😅
Thanks for the correction!
Edit: I read the code again and understood hahaha

Original thread: https://forums.rpgmakerweb.com/threads/snippet-request-customizable-player-vehicle-speed-changer.124524/