Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Pokémon Essentials: Bumping [UPDATE]

boon

Sponsor

Yo.

In the Pokémon essentials, the bump sound repeats itself very fast when you bump into objects - there is no frame delay before it repeats.

How could I set this so it is the same as having a 5 frame gap between playing it again?
Thanks to BwdYeti.

How can I make it so the character keeps trying to walk into the wall (stop animation)?


Code:
#==============================================================================

# ** Game_Player

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

#  This class handles the player. Its functions include event starting

#  determinants and map scrolling. Refer to "$game_player" for the one

#  instance of this class.

#==============================================================================

 

def pbAddDependency(event)

  $PokemonTemp.dependentEvents.addEvent(event)

end

def pbRemoveDependency(event)

  $PokemonTemp.dependentEvents.removeEvent(event)

end

 

def pbAddDependency2(eventID, eventName, commonEvent)

  $PokemonTemp.dependentEvents.addEvent($game_map.events[eventID],eventName,commonEvent)

end

def pbRemoveDependency2(eventName)

  $PokemonTemp.dependentEvents.removeEventByName(eventName)

end

 

class Game_Player < Game_Character

  def map

    @map=nil

    return $game_map

  end

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

  # * Invariables

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

  def initialize(*arg)

    super(*arg)

    @lastdir=0

    @lastdirframe=0

  end

  def pbHasDependentEvents?

    return $PokemonGlobal.dependentEvents.length>0  

  end

  def move_down(turn_enabled = true)

    if turn_enabled

     turn_down

    end

    pbBridgeCheck(2)

    if passable?(@x, @y, 2)

      return if pbLedge(0,1)

      return if pbEndSurf(0,1)

      turn_down

      @y += 1

      $PokemonTemp.dependentEvents.pbMoveDependentEvents

      increase_steps

    else

      if !check_event_trigger_touch(@x, @y+1)

        bump_sound(2)

      end

    end

  end

  def move_left(turn_enabled = true)

    if turn_enabled

      turn_left

    end

    pbBridgeCheck(4)

    if passable?(@x, @y, 4)

      return if pbLedge(-1,0)

      return if pbEndSurf(-1,0)

      turn_left

      @x -= 1

      $PokemonTemp.dependentEvents.pbMoveDependentEvents

      increase_steps

    else

      if !check_event_trigger_touch(@x-1, @y)

        bump_sound(4)

      end

    end

  end

  def move_right(turn_enabled = true)

    if turn_enabled

      turn_right

    end

    pbBridgeCheck(6)

    if passable?(@x, @y, 6)

      return if pbLedge(1,0)

      return if pbEndSurf(1,0)

      turn_right

      @x += 1

      $PokemonTemp.dependentEvents.pbMoveDependentEvents

      increase_steps

    else

      if !check_event_trigger_touch(@x+1, @y)

        bump_sound(6)

      end

    end

  end

  def move_up(turn_enabled = true)

    if turn_enabled

      turn_up

    end

    pbBridgeCheck(8)

    if passable?(@x, @y, 8)

      return if pbLedge(0,-1)

      return if pbEndSurf(0,-1)

      turn_up

      @y -= 1

      $PokemonTemp.dependentEvents.pbMoveDependentEvents

      increase_steps

    else

      if !check_event_trigger_touch(@x, @y-1)

        bump_sound(8)

      end

    end

  end

  def pbTriggeredTrainerEvents(triggers,checkIfRunning=true)

    result = []

    # If event is running

    if checkIfRunning && $game_system.map_interpreter.running?

      return result

    end

    # All event loops

    for event in $game_map.events.values

      next if !event.name[/^Trainer\((\d+)\)$/]

      distance=$~[1].to_i

      # If event coordinates and triggers are consistent

      if pbEventCanReachPlayer?(event,self,distance) and triggers.include?(event.trigger)

          # If starting determinant is front event (other than jumping)

        if not event.jumping? and not event.over_trigger?

          result.push(event)

        end

      end

    end

    return result

  end

  def pbTriggeredCounterEvents(triggers,checkIfRunning=true)

    result = []

    # If event is running

    if checkIfRunning && $game_system.map_interpreter.running?

      return result

    end

    # All event loops

    for event in $game_map.events.values

      next if !event.name[/^Counter\((\d+)\)$/]

      distance=$~[1].to_i

      # If event coordinates and triggers are consistent

      if pbEventFacesPlayer?(event,self,distance) and triggers.include?(event.trigger)

          # If starting determinant is front event (other than jumping)

        if not event.jumping? and not event.over_trigger?

          result.push(event)

        end

      end

    end

    return result

  end

  def pbCheckEventTriggerAfterTurning

  end

  def pbCheckEventTriggerFromDistance(triggers)

    ret=pbTriggeredTrainerEvents(triggers)

    ret.concat(pbTriggeredCounterEvents(triggers))

    return false if ret.length==0

    for event in ret

      event.start

    end

    return true

  end

  def pbFacingEvent

   if $game_system.map_interpreter.running?

    return nil

   end

   new_x = @x + (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)

   new_y = @y + (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)

   for event in $game_map.events.values

    if event.x == new_x and event.y == new_y

     if not event.jumping? and not event.over_trigger?

      return event

     end

    end

   end

   if $game_map.counter?(new_x, new_y)

     new_x += (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)

     new_y += (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)

     for event in $game_map.events.values

      if event.x == new_x and event.y == new_y

       if not event.jumping? and not event.over_trigger?

        return event

       end

      end

     end

   end

   return nil

  end

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

  # * Passable Determinants

  #     x : x-coordinate

  #     y : y-coordinate

  #     d : direction (0,2,4,6,8)

  #         * 0 = Determines if all directions are impassable (for jumping)

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

  def passable?(x, y, d)

    # Get new coordinates

    new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)

    new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)

    # If coordinates are outside of map

    unless $game_map.validLax?(new_x, new_y)

      # Impassable

      return false

    end

    if !$game_map.valid?(new_x, new_y)

      return false if !$MapFactory

      return $MapFactory.isPassableFromEdge?(new_x, new_y)

    end

    # If debug mode is ON and ctrl key was pressed

    if $DEBUG and Input.press?(Input::CTRL)

      # Passable

      return true

    end

    super

  end

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

  # * Set Map Display Position to Center of Screen

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

  def center(x, y)

    center_x = (Graphics.width/2 - 16) * 4   # Center screen x-coordinate * 4

    center_y = (Graphics.height/2 - 16) * 4   # Center screen y-coordinate * 4

    max_x = ($game_map.width - Graphics.width/32.0) * 128

    max_y = ($game_map.height - Graphics.height/32.0) * 128

    $game_map.display_x = [0, [x * 128 - center_x, max_x].min].max

    $game_map.display_y = [0, [y * 128 - center_y, max_y].min].max

  end

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

  # * Move to Designated Position

  #     x : x-coordinate

  #     y : y-coordinate

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

  def moveto(x, y)

    super

    # Centering

    center(x, y)

    # Make encounter count

    make_encounter_count

  end

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

  # * Increase Steps

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

  def increase_steps

    super

  end

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

  # * Get Encounter Count

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

  def encounter_count

    return @encounter_count

  end

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

  # * Make Encounter Count

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

  def make_encounter_count

    # Image of two dice rolling

    if $game_map.map_id != 0

      n = $game_map.encounter_step

      @encounter_count = rand(n) + rand(n) + 1

    end

  end

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

  # * Refresh

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

  def refresh

    @opacity = 255

    @blend_type = 0

  end

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

  # * Same Position Starting Determinant

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

  def check_event_trigger_here(triggers,keypress=false)

    result = false

    # If event is running

    if $game_system.map_interpreter.running?

      return result

    end

    # All event loops

    for event in $game_map.events.values

      # If event coordinates and triggers are consistent

      if event.x == @x and event.y == @y and triggers.include?(event.trigger)

        # If starting determinant is same position event (other than jumping)

        if not event.jumping? and event.over_trigger?

          event.start(keypress)

          result = true

        end

      end

    end

    return result

  end

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

  # * Front Envent Starting Determinant

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

  def check_event_trigger_there(triggers,keypress=false)

    result = false

    # If event is running

    if $game_system.map_interpreter.running?

      return result

    end

    # Calculate front event coordinates

    new_x = @x + (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)

    new_y = @y + (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)

    # All event loops

    for event in $game_map.events.values

      # If event coordinates and triggers are consistent

      if event.x == new_x and event.y == new_y and

         triggers.include?(event.trigger)

        # If starting determinant is front event (other than jumping)

        if not event.jumping? and (keypress || !event.over_trigger?)

          event.start(keypress)

          result = true

        end

      end

    end

    # If fitting event is not found

    if result == false

      # If front tile is a counter

      if $game_map.counter?(new_x, new_y)

        # Calculate 1 tile inside coordinates

        new_x += (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)

        new_y += (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)

        # All event loops

        for event in $game_map.events.values

          # If event coordinates and triggers are consistent

          if event.x == new_x and event.y == new_y and

             triggers.include?(event.trigger)

            # If starting determinant is front event (other than jumping)

            if not event.jumping? and (keypress || !event.over_trigger?)

              event.start

              result = true

            end

          end

        end

      end

    end

    return result

  end

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

  # * Touch Event Starting Determinant

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

  def check_event_trigger_touch(x, y)

    result = false

    # If event is running

    if $game_system.map_interpreter.running?

      return result

    end

    # All event loops

    for event in $game_map.events.values

      if event.name[/^Trainer\((\d+)\)$/]

        distance=$~[1].to_i

        next if !pbEventCanReachPlayer?(event,self,distance)

      end

      if event.name[/^Counter\((\d+)\)$/]

        distance=$~[1].to_i

        next if !pbEventFacesPlayer?(event,self,distance)

      end

      # If event coordinates and triggers are consistent

      if event.x == x and event.y == y and [1,2].include?(event.trigger)

        # If starting determinant is front event (other than jumping)

        if not event.jumping? and not event.over_trigger?

          event.start

          result = true

        end

      end

    end

    return result

  end

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

  # * Frame Update

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

  def update

    # Remember whether or not moving in local variables

    last_moving = moving?

    # If moving, event running, move route forcing, and message window

    # display are all not occurring

    dir=Input.dir4

    unless moving? or $game_system.map_interpreter.running? or

           @move_route_forcing or $game_temp.message_window_showing or

           $PokemonTemp.miniupdate

      # Move player in the direction the directional button is being pressed

      if dir==@lastdir && Graphics.frame_count-@lastdirframe>2

       case dir

       when 2

         move_down

       when 4

         move_left

       when 6

         move_right

       when 8

         move_up

       end

      elsif dir!=@lastdir

       case dir

       when 2

         turn_down

       when 4

         turn_left

       when 6

         turn_right

       when 8

         turn_up

       end

      end

    end

    $PokemonTemp.dependentEvents.updateDependentEvents

    if dir!=@lastdir

     @lastdirframe=Graphics.frame_count

    end

    @lastdir=dir

    # Remember coordinates in local variables

    last_real_x = @real_x

    last_real_y = @real_y

    super

    center_x = (Graphics.width/2 - 16) * 4   # Center screen x-coordinate * 4

    center_y = (Graphics.height/2 - 16) * 4   # Center screen y-coordinate * 4

    # If character moves down and is positioned lower than the center

    # of the screen

    if @real_y > last_real_y and @real_y - $game_map.display_y > center_y

      # Scroll map down

      $game_map.scroll_down(@real_y - last_real_y)

    end

    # If character moves left and is positioned more let on-screen than

    # center

    if @real_x < last_real_x and @real_x - $game_map.display_x < center_x

      # Scroll map left

      $game_map.scroll_left(last_real_x - @real_x)

    end

    # If character moves right and is positioned more right on-screen than

    # center

    if @real_x > last_real_x and @real_x - $game_map.display_x > center_x

      # Scroll map right

      $game_map.scroll_right(@real_x - last_real_x)

    end

    # If character moves up and is positioned higher than the center

    # of the screen

    if @real_y < last_real_y and @real_y - $game_map.display_y < center_y

      # Scroll map up

      $game_map.scroll_up(last_real_y - @real_y)

    end

    # If not moving

    unless moving?

      # If player was moving last time

      if last_moving

        $PokemonTemp.dependentEvents.pbTurnDependentEvents

        result = pbCheckEventTriggerFromDistance([2])

        # Event determinant is via touch of same position event

        result |= check_event_trigger_here([1,2])

        # If event which started does not exist

        Kernel.pbOnStepTaken(result) # *Added function call

        if result == false

        end

      end

      # If C button was pressed

      if Input.trigger?(Input::C) && !$PokemonTemp.miniupdate

        # Same position and front event determinant

        check_event_trigger_here([0],true)

        check_event_trigger_there([0,2],true) # *Modified to prevent unnecessary triggers

      end

    end

  end

  # This number is the interval between bump sounds

  BUMP_INTERVAL = 18

  

  def bump_sound(dir)

    if dir != @last_bump or @bump_timer == 0

      @bump_timer = BUMP_INTERVAL

      Audio.se_play("Audio/SE/bump.wav")

    end

    @last_bump = dir

  end

  

  alias bwd_bump_gmplyr_update :update

  def update(*args)

    bwd_bump_gmplyr_update(*args)

    if @bump_timer == nil

     @bump_timer = 0

     @last_bump = 0

    end

    @bump_timer -= 1 if @bump_timer > 0

  end

end

 
 
You'll need to have some variable handle the wait timing, and check it when you would normally play the bump sound. Try this

Replace the instances of Audio.se_play("Audio/SE/bump.wav") in the move_-direction- methods with bump_sound(-direction of movement here-), 2 for down, 6 for right, for example:

[rgss] 
  def move_left(turn_enabled = true)
    if turn_enabled
      turn_left
    end
    pbBridgeCheck(4)
    if passable?(@x, @y, 4)
      return if pbLedge(-1,0)
      return if pbEndSurf(-1,0)
      turn_left
      @x -= 1
      $PokemonTemp.dependentEvents.pbMoveDependentEvents
      increase_steps
    else
      if !check_event_trigger_touch(@x-1, @y)
        bump_sound(4) # Adding this
      end
    end
  end
 
[/rgss]
then add
[rgss] 
class Game_Player
  # This number is the interval between bump sounds
  BUMP_INTERVAL = 5
 
  alias_method :bwd_bump_gmplyr_initialize, :initialize
  def initialize(*args)
    bwd_bump_gmplyr_initialize(*args)
    @bump_timer = 0
    @last_bump = 0
  end
 
  def bump_sound(dir)
    if dir != @last_bump
      if @bump_timer == 0
        @bump_timer = BUMP_INTERVAL
        Audio.se_play("Audio/SE/bump.wav")
      end
    end
    @last_bump = dir
  end
 
  alias_method :bwd_bump_gmplyr_update, :update
  def update(*args)
    bwd_bump_gmplyr_update(*args)
    @bump_timer -= 1 if @bump_timer > 0
  end
end
 
[/rgss]

I didn't test it but it should work. Just say so if something goes wrong
 

boon

Sponsor

Alright, it doesn't play a bump sound now unfortunately. The code, so far:

Code:
<div id="{CB}" style="font-family: monospace;"><ol> 

#==============================================================================

# ** Game_Player

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

#  This class handles the player. Its functions include event starting

#  determinants and map scrolling. Refer to "$game_player" for the one

#  instance of this class.

#==============================================================================

 

def pbAddDependency(event)

  $PokemonTemp.dependentEvents.addEvent(event)

end

def pbRemoveDependency(event)

  $PokemonTemp.dependentEvents.removeEvent(event)

end

 

def pbAddDependency2(eventID, eventName, commonEvent)

  $PokemonTemp.dependentEvents.addEvent($game_map.events[eventID],eventName,commonEvent)

end

def pbRemoveDependency2(eventName)

  $PokemonTemp.dependentEvents.removeEventByName(eventName)

end

 

class Game_Player < Game_Character

  # This number is the interval between bump sounds

BUMP_INTERVAL = 5

  

alias_method :bwd_bump_gmplyr_initialize, :initialize

def initialize(*args)

     bwd_bump_gmplyr_initialize(*args)

     @bump_timer = 0

     @last_bump = 0

   end

  

   def bump_sound(dir)

     if dir != @last_bump

       if @bump_timer == 0

         @bump_timer = BUMP_INTERVAL

         Audio.se_play("Audio/SE/bump.wav")

       end

     end

     @last_bump = dir

   end

  

alias_method :bwd_bump_gmplyr_update, :update

def update(*args)

bwd_bump_gmplyr_update(*args)

@bump_timer -= 1 if @bump_timer > 0

end

 

  def map

    @map=nil

    return $game_map

  end

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

  # * Invariables

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

  def initialize(*arg)

    super(*arg)

    @lastdir=0

    @lastdirframe=0

  end

  def pbHasDependentEvents?

    return $PokemonGlobal.dependentEvents.length>0   

  end

  def move_down(turn_enabled = true)

    if turn_enabled

     turn_down

    end

    pbBridgeCheck(2)

    if passable?(@x, @y, 2)

      return if pbLedge(0,1)

      return if pbEndSurf(0,1)

      turn_down

      @y += 1

      $PokemonTemp.dependentEvents.pbMoveDependentEvents

      increase_steps

    else

      if !check_event_trigger_touch(@x, @y+1)

        bump_sound(4)

      end

    end

  end

  def move_left(turn_enabled = true)

    if turn_enabled

      turn_left

    end

    pbBridgeCheck(4)

    if passable?(@x, @y, 4)

      return if pbLedge(-1,0)

      return if pbEndSurf(-1,0)

      turn_left

      @x -= 1

      $PokemonTemp.dependentEvents.pbMoveDependentEvents

      increase_steps

    else

      if !check_event_trigger_touch(@x-1, @y)

        bump_sound(4)

      end

    end

  end

  def move_right(turn_enabled = true)

    if turn_enabled

      turn_right

    end

    pbBridgeCheck(6)

    if passable?(@x, @y, 6)

      return if pbLedge(1,0)

      return if pbEndSurf(1,0)

      turn_right

      @x += 1

      $PokemonTemp.dependentEvents.pbMoveDependentEvents

      increase_steps

    else

      if !check_event_trigger_touch(@x+1, @y)

        bump_sound(4)

      end

    end

  end

  def move_up(turn_enabled = true)

    if turn_enabled

      turn_up

    end

    pbBridgeCheck(8)

    if passable?(@x, @y, 8)

      return if pbLedge(0,-1)

      return if pbEndSurf(0,-1)

      turn_up

      @y -= 1

      $PokemonTemp.dependentEvents.pbMoveDependentEvents

      increase_steps

    else

      if !check_event_trigger_touch(@x, @y-1)

        bump_sound(4)

      end

    end

  end

  def pbTriggeredTrainerEvents(triggers,checkIfRunning=true)

    result = []

    # If event is running

    if checkIfRunning && $game_system.map_interpreter.running?

      return result

    end

    # All event loops

    for event in $game_map.events.values

      next if !event.name[/^Trainer\((\d+)\)$/]

      distance=$~[1].to_i

      # If event coordinates and triggers are consistent

      if pbEventCanReachPlayer?(event,self,distance) and triggers.include?(event.trigger)

          # If starting determinant is front event (other than jumping)

        if not event.jumping? and not event.over_trigger?

          result.push(event)

        end

      end

    end

    return result

  end

  def pbTriggeredCounterEvents(triggers,checkIfRunning=true)

    result = []

    # If event is running

    if checkIfRunning && $game_system.map_interpreter.running?

      return result

    end

    # All event loops

    for event in $game_map.events.values

      next if !event.name[/^Counter\((\d+)\)$/]

      distance=$~[1].to_i

      # If event coordinates and triggers are consistent

      if pbEventFacesPlayer?(event,self,distance) and triggers.include?(event.trigger)

          # If starting determinant is front event (other than jumping)

        if not event.jumping? and not event.over_trigger?

          result.push(event)

        end

      end

    end

    return result

  end

  def pbCheckEventTriggerAfterTurning

  end

  def pbCheckEventTriggerFromDistance(triggers)

    ret=pbTriggeredTrainerEvents(triggers)

    ret.concat(pbTriggeredCounterEvents(triggers))

    return false if ret.length==0

    for event in ret

      event.start

    end

    return true

  end

  def pbFacingEvent

   if $game_system.map_interpreter.running?

    return nil

   end

   new_x = @x + (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)

   new_y = @y + (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)

   for event in $game_map.events.values

    if event.x == new_x and event.y == new_y

     if not event.jumping? and not event.over_trigger?

      return event

     end

    end

   end

   if $game_map.counter?(new_x, new_y)

     new_x += (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)

     new_y += (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)

     for event in $game_map.events.values

      if event.x == new_x and event.y == new_y

       if not event.jumping? and not event.over_trigger?

        return event

       end

      end

     end

   end

   return nil

  end

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

  # * Passable Determinants

  #     x : x-coordinate

  #     y : y-coordinate

  #     d : direction (0,2,4,6,8)

  #         * 0 = Determines if all directions are impassable (for jumping)

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

  def passable?(x, y, d)

    # Get new coordinates

    new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)

    new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)

    # If coordinates are outside of map

    unless $game_map.validLax?(new_x, new_y)

      # Impassable

      return false

    end

    if !$game_map.valid?(new_x, new_y)

      return false if !$MapFactory

      return $MapFactory.isPassableFromEdge?(new_x, new_y)

    end

    # If debug mode is ON and ctrl key was pressed

    if $DEBUG and Input.press?(Input::CTRL)

      # Passable

      return true

    end

    super

  end

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

  # * Set Map Display Position to Center of Screen

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

  def center(x, y)

    center_x = (Graphics.width/2 - 16) * 4   # Center screen x-coordinate * 4

    center_y = (Graphics.height/2 - 16) * 4   # Center screen y-coordinate * 4

    max_x = ($game_map.width - Graphics.width/32.0) * 128

    max_y = ($game_map.height - Graphics.height/32.0) * 128

    $game_map.display_x = [0, [x * 128 - center_x, max_x].min].max

    $game_map.display_y = [0, [y * 128 - center_y, max_y].min].max

  end

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

  # * Move to Designated Position

  #     x : x-coordinate

  #     y : y-coordinate

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

  def moveto(x, y)

    super

    # Centering

    center(x, y)

    # Make encounter count

    make_encounter_count

  end

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

  # * Increase Steps

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

  def increase_steps

    super

  end

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

  # * Get Encounter Count

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

  def encounter_count

    return @encounter_count

  end

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

  # * Make Encounter Count

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

  def make_encounter_count

    # Image of two dice rolling

    if $game_map.map_id != 0

      n = $game_map.encounter_step

      @encounter_count = rand(n) + rand(n) + 1

    end

  end

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

  # * Refresh

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

  def refresh

    @opacity = 255

    @blend_type = 0

  end

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

  # * Same Position Starting Determinant

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

  def check_event_trigger_here(triggers,keypress=false)

    result = false

    # If event is running

    if $game_system.map_interpreter.running?

      return result

    end

    # All event loops

    for event in $game_map.events.values

      # If event coordinates and triggers are consistent

      if event.x == @x and event.y == @y and triggers.include?(event.trigger)

        # If starting determinant is same position event (other than jumping)

        if not event.jumping? and event.over_trigger?

          event.start(keypress)

          result = true

        end

      end

    end

    return result

  end

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

  # * Front Envent Starting Determinant

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

  def check_event_trigger_there(triggers,keypress=false)

    result = false

    # If event is running

    if $game_system.map_interpreter.running?

      return result

    end

    # Calculate front event coordinates

    new_x = @x + (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)

    new_y = @y + (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)

    # All event loops

    for event in $game_map.events.values

      # If event coordinates and triggers are consistent

      if event.x == new_x and event.y == new_y and

         triggers.include?(event.trigger)

        # If starting determinant is front event (other than jumping)

        if not event.jumping? and (keypress || !event.over_trigger?)

          event.start(keypress)

          result = true

        end

      end

    end

    # If fitting event is not found

    if result == false

      # If front tile is a counter

      if $game_map.counter?(new_x, new_y)

        # Calculate 1 tile inside coordinates

        new_x += (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)

        new_y += (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)

        # All event loops

        for event in $game_map.events.values

          # If event coordinates and triggers are consistent

          if event.x == new_x and event.y == new_y and

             triggers.include?(event.trigger)

            # If starting determinant is front event (other than jumping)

            if not event.jumping? and (keypress || !event.over_trigger?)

              event.start

              result = true

            end

          end

        end

      end

    end

    return result

  end

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

  # * Touch Event Starting Determinant

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

  def check_event_trigger_touch(x, y)

    result = false

    # If event is running

    if $game_system.map_interpreter.running?

      return result

    end

    # All event loops

    for event in $game_map.events.values

      if event.name[/^Trainer\((\d+)\)$/]

        distance=$~[1].to_i

        next if !pbEventCanReachPlayer?(event,self,distance)

      end

      if event.name[/^Counter\((\d+)\)$/]

        distance=$~[1].to_i

        next if !pbEventFacesPlayer?(event,self,distance)

      end

      # If event coordinates and triggers are consistent

      if event.x == x and event.y == y and [1,2].include?(event.trigger)

        # If starting determinant is front event (other than jumping)

        if not event.jumping? and not event.over_trigger?

          event.start

          result = true

        end

      end

    end

    return result

  end

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

  # * Frame Update

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

  def update

    # Remember whether or not moving in local variables

    last_moving = moving?

    # If moving, event running, move route forcing, and message window

    # display are all not occurring

    dir=Input.dir4

    unless moving? or $game_system.map_interpreter.running? or

           @move_route_forcing or $game_temp.message_window_showing or

           $PokemonTemp.miniupdate

      # Move player in the direction the directional button is being pressed

      if dir==@lastdir && Graphics.frame_count-@lastdirframe>2

       case dir

       when 2

         move_down

       when 4

         move_left

       when 6

         move_right

       when 8

         move_up

       end

      elsif dir!=@lastdir

       case dir

       when 2

         turn_down

       when 4

         turn_left

       when 6

         turn_right

       when 8

         turn_up

       end

      end

    end

    $PokemonTemp.dependentEvents.updateDependentEvents

    if dir!=@lastdir

     @lastdirframe=Graphics.frame_count

    end

    @lastdir=dir

    # Remember coordinates in local variables

    last_real_x = @real_x

    last_real_y = @real_y

    super

    center_x = (Graphics.width/2 - 16) * 4   # Center screen x-coordinate * 4

    center_y = (Graphics.height/2 - 16) * 4   # Center screen y-coordinate * 4

    # If character moves down and is positioned lower than the center

    # of the screen

    if @real_y > last_real_y and @real_y - $game_map.display_y > center_y

      # Scroll map down

      $game_map.scroll_down(@real_y - last_real_y)

    end

    # If character moves left and is positioned more let on-screen than

    # center

    if @real_x < last_real_x and @real_x - $game_map.display_x < center_x

      # Scroll map left

      $game_map.scroll_left(last_real_x - @real_x)

    end

    # If character moves right and is positioned more right on-screen than

    # center

    if @real_x > last_real_x and @real_x - $game_map.display_x > center_x

      # Scroll map right

      $game_map.scroll_right(@real_x - last_real_x)

    end

    # If character moves up and is positioned higher than the center

    # of the screen

    if @real_y < last_real_y and @real_y - $game_map.display_y < center_y

      # Scroll map up

      $game_map.scroll_up(last_real_y - @real_y)

    end

    # If not moving

    unless moving?

      # If player was moving last time

      if last_moving

        $PokemonTemp.dependentEvents.pbTurnDependentEvents

        result = pbCheckEventTriggerFromDistance([2])

        # Event determinant is via touch of same position event

        result |= check_event_trigger_here([1,2])

        # If event which started does not exist

        Kernel.pbOnStepTaken(result) # *Added function call

        if result == false

        end

      end

      # If C button was pressed

      if Input.trigger?(Input::C) && !$PokemonTemp.miniupdate

        # Same position and front event determinant

        check_event_trigger_here([0],true)

        check_event_trigger_there([0,2],true) # *Modified to prevent unnecessary triggers

      end

    end

  end

end

 
 
That part at the end of my post need to go at the bottom of Game_Player, not at the top.

EDIT

I messed up some, and also Pokemon Essentials is scripted a bit differently than I expected. This works though:
[rgss] 
#==============================================================================
# ** Game_Player
#------------------------------------------------------------------------------
#  This class handles the player. Its functions include event starting
#  determinants and map scrolling. Refer to "$game_player" for the one
#  instance of this class.
#==============================================================================
 
def pbAddDependency(event)
  $PokemonTemp.dependentEvents.addEvent(event)
end
def pbRemoveDependency(event)
  $PokemonTemp.dependentEvents.removeEvent(event)
end
 
def pbAddDependency2(eventID, eventName, commonEvent)
  $PokemonTemp.dependentEvents.addEvent($game_map.events[eventID],eventName,commonEvent)
end
def pbRemoveDependency2(eventName)
  $PokemonTemp.dependentEvents.removeEventByName(eventName)
end
 
class Game_Player < Game_Character
  def map
    @map=nil
    return $game_map
  end
  #--------------------------------------------------------------------------
  # * Invariables
  #--------------------------------------------------------------------------
  def initialize(*arg)
    super(*arg)
    @lastdir=0
    @lastdirframe=0
  end
  def pbHasDependentEvents?
    return $PokemonGlobal.dependentEvents.length>0  
  end
  def move_down(turn_enabled = true)
    if turn_enabled
     turn_down
    end
    pbBridgeCheck(2)
    if passable?(@x, @y, 2)
      return if pbLedge(0,1)
      return if pbEndSurf(0,1)
      turn_down
      @y += 1
      $PokemonTemp.dependentEvents.pbMoveDependentEvents
      increase_steps
    else
      if !check_event_trigger_touch(@x, @y+1)
        bump_sound(2)
      end
    end
  end
  def move_left(turn_enabled = true)
    if turn_enabled
      turn_left
    end
    pbBridgeCheck(4)
    if passable?(@x, @y, 4)
      return if pbLedge(-1,0)
      return if pbEndSurf(-1,0)
      turn_left
      @x -= 1
      $PokemonTemp.dependentEvents.pbMoveDependentEvents
      increase_steps
    else
      if !check_event_trigger_touch(@x-1, @y)
        bump_sound(4)
      end
    end
  end
  def move_right(turn_enabled = true)
    if turn_enabled
      turn_right
    end
    pbBridgeCheck(6)
    if passable?(@x, @y, 6)
      return if pbLedge(1,0)
      return if pbEndSurf(1,0)
      turn_right
      @x += 1
      $PokemonTemp.dependentEvents.pbMoveDependentEvents
      increase_steps
    else
      if !check_event_trigger_touch(@x+1, @y)
        bump_sound(6)
      end
    end
  end
  def move_up(turn_enabled = true)
    if turn_enabled
      turn_up
    end
    pbBridgeCheck(8)
    if passable?(@x, @y, 8)
      return if pbLedge(0,-1)
      return if pbEndSurf(0,-1)
      turn_up
      @y -= 1
      $PokemonTemp.dependentEvents.pbMoveDependentEvents
      increase_steps
    else
      if !check_event_trigger_touch(@x, @y-1)
        bump_sound(8)
      end
    end
  end
  def pbTriggeredTrainerEvents(triggers,checkIfRunning=true)
    result = []
    # If event is running
    if checkIfRunning && $game_system.map_interpreter.running?
      return result
    end
    # All event loops
    for event in $game_map.events.values
      next if !event.name[/^Trainer\((\d+)\)$/]
      distance=$~[1].to_i
      # If event coordinates and triggers are consistent
      if pbEventCanReachPlayer?(event,self,distance) and triggers.include?(event.trigger)
          # If starting determinant is front event (other than jumping)
        if not event.jumping? and not event.over_trigger?
          result.push(event)
        end
      end
    end
    return result
  end
  def pbTriggeredCounterEvents(triggers,checkIfRunning=true)
    result = []
    # If event is running
    if checkIfRunning && $game_system.map_interpreter.running?
      return result
    end
    # All event loops
    for event in $game_map.events.values
      next if !event.name[/^Counter\((\d+)\)$/]
      distance=$~[1].to_i
      # If event coordinates and triggers are consistent
      if pbEventFacesPlayer?(event,self,distance) and triggers.include?(event.trigger)
          # If starting determinant is front event (other than jumping)
        if not event.jumping? and not event.over_trigger?
          result.push(event)
        end
      end
    end
    return result
  end
  def pbCheckEventTriggerAfterTurning
  end
  def pbCheckEventTriggerFromDistance(triggers)
    ret=pbTriggeredTrainerEvents(triggers)
    ret.concat(pbTriggeredCounterEvents(triggers))
    return false if ret.length==0
    for event in ret
      event.start
    end
    return true
  end
  def pbFacingEvent
   if $game_system.map_interpreter.running?
    return nil
   end
   new_x = @x + (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
   new_y = @y + (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
   for event in $game_map.events.values
    if event.x == new_x and event.y == new_y
     if not event.jumping? and not event.over_trigger?
      return event
     end
    end
   end
   if $game_map.counter?(new_x, new_y)
     new_x += (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
     new_y += (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
     for event in $game_map.events.values
      if event.x == new_x and event.y == new_y
       if not event.jumping? and not event.over_trigger?
        return event
       end
      end
     end
   end
   return nil
  end
  #--------------------------------------------------------------------------
  # * Passable Determinants
  #     x : x-coordinate
  #     y : y-coordinate
  #     d : direction (0,2,4,6,8)
  #         * 0 = Determines if all directions are impassable (for jumping)
  #--------------------------------------------------------------------------
  def passable?(x, y, d)
    # Get new coordinates
    new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
    new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
    # If coordinates are outside of map
    unless $game_map.validLax?(new_x, new_y)
      # Impassable
      return false
    end
    if !$game_map.valid?(new_x, new_y)
      return false if !$MapFactory
      return $MapFactory.isPassableFromEdge?(new_x, new_y)
    end
    # If debug mode is ON and ctrl key was pressed
    if $DEBUG and Input.press?(Input::CTRL)
      # Passable
      return true
    end
    super
  end
  #--------------------------------------------------------------------------
  # * Set Map Display Position to Center of Screen
  #--------------------------------------------------------------------------
  def center(x, y)
    center_x = (Graphics.width/2 - 16) * 4   # Center screen x-coordinate * 4
    center_y = (Graphics.height/2 - 16) * 4   # Center screen y-coordinate * 4
    max_x = ($game_map.width - Graphics.width/32.0) * 128
    max_y = ($game_map.height - Graphics.height/32.0) * 128
    $game_map.display_x = [0, [x * 128 - center_x, max_x].min].max
    $game_map.display_y = [0, [y * 128 - center_y, max_y].min].max
  end
  #--------------------------------------------------------------------------
  # * Move to Designated Position
  #     x : x-coordinate
  #     y : y-coordinate
  #--------------------------------------------------------------------------
  def moveto(x, y)
    super
    # Centering
    center(x, y)
    # Make encounter count
    make_encounter_count
  end
  #--------------------------------------------------------------------------
  # * Increase Steps
  #--------------------------------------------------------------------------
  def increase_steps
    super
  end
  #--------------------------------------------------------------------------
  # * Get Encounter Count
  #--------------------------------------------------------------------------
  def encounter_count
    return @encounter_count
  end
  #--------------------------------------------------------------------------
  # * Make Encounter Count
  #--------------------------------------------------------------------------
  def make_encounter_count
    # Image of two dice rolling
    if $game_map.map_id != 0
      n = $game_map.encounter_step
      @encounter_count = rand(n) + rand(n) + 1
    end
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    @opacity = 255
    @blend_type = 0
  end
  #--------------------------------------------------------------------------
  # * Same Position Starting Determinant
  #--------------------------------------------------------------------------
  def check_event_trigger_here(triggers,keypress=false)
    result = false
    # If event is running
    if $game_system.map_interpreter.running?
      return result
    end
    # All event loops
    for event in $game_map.events.values
      # If event coordinates and triggers are consistent
      if event.x == @x and event.y == @y and triggers.include?(event.trigger)
        # If starting determinant is same position event (other than jumping)
        if not event.jumping? and event.over_trigger?
          event.start(keypress)
          result = true
        end
      end
    end
    return result
  end
  #--------------------------------------------------------------------------
  # * Front Envent Starting Determinant
  #--------------------------------------------------------------------------
  def check_event_trigger_there(triggers,keypress=false)
    result = false
    # If event is running
    if $game_system.map_interpreter.running?
      return result
    end
    # Calculate front event coordinates
    new_x = @x + (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
    new_y = @y + (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
    # All event loops
    for event in $game_map.events.values
      # If event coordinates and triggers are consistent
      if event.x == new_x and event.y == new_y and
         triggers.include?(event.trigger)
        # If starting determinant is front event (other than jumping)
        if not event.jumping? and (keypress || !event.over_trigger?)
          event.start(keypress)
          result = true
        end
      end
    end
    # If fitting event is not found
    if result == false
      # If front tile is a counter
      if $game_map.counter?(new_x, new_y)
        # Calculate 1 tile inside coordinates
        new_x += (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
        new_y += (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
        # All event loops
        for event in $game_map.events.values
          # If event coordinates and triggers are consistent
          if event.x == new_x and event.y == new_y and
             triggers.include?(event.trigger)
            # If starting determinant is front event (other than jumping)
            if not event.jumping? and (keypress || !event.over_trigger?)
              event.start
              result = true
            end
          end
        end
      end
    end
    return result
  end
  #--------------------------------------------------------------------------
  # * Touch Event Starting Determinant
  #--------------------------------------------------------------------------
  def check_event_trigger_touch(x, y)
    result = false
    # If event is running
    if $game_system.map_interpreter.running?
      return result
    end
    # All event loops
    for event in $game_map.events.values
      if event.name[/^Trainer\((\d+)\)$/]
        distance=$~[1].to_i
        next if !pbEventCanReachPlayer?(event,self,distance)
      end
      if event.name[/^Counter\((\d+)\)$/]
        distance=$~[1].to_i
        next if !pbEventFacesPlayer?(event,self,distance)
      end
      # If event coordinates and triggers are consistent
      if event.x == x and event.y == y and [1,2].include?(event.trigger)
        # If starting determinant is front event (other than jumping)
        if not event.jumping? and not event.over_trigger?
          event.start
          result = true
        end
      end
    end
    return result
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # Remember whether or not moving in local variables
    last_moving = moving?
    # If moving, event running, move route forcing, and message window
    # display are all not occurring
    dir=Input.dir4
    unless moving? or $game_system.map_interpreter.running? or
           @move_route_forcing or $game_temp.message_window_showing or
           $PokemonTemp.miniupdate
      # Move player in the direction the directional button is being pressed
      if dir==@lastdir && Graphics.frame_count-@lastdirframe>2
       case dir
       when 2
         move_down
       when 4
         move_left
       when 6
         move_right
       when 8
         move_up
       end
      elsif dir!=@lastdir
       case dir
       when 2
         turn_down
       when 4
         turn_left
       when 6
         turn_right
       when 8
         turn_up
       end
      end
    end
    $PokemonTemp.dependentEvents.updateDependentEvents
    if dir!=@lastdir
     @lastdirframe=Graphics.frame_count
    end
    @lastdir=dir
    # Remember coordinates in local variables
    last_real_x = @real_x
    last_real_y = @real_y
    super
    center_x = (Graphics.width/2 - 16) * 4   # Center screen x-coordinate * 4
    center_y = (Graphics.height/2 - 16) * 4   # Center screen y-coordinate * 4
    # If character moves down and is positioned lower than the center
    # of the screen
    if @real_y > last_real_y and @real_y - $game_map.display_y > center_y
      # Scroll map down
      $game_map.scroll_down(@real_y - last_real_y)
    end
    # If character moves left and is positioned more let on-screen than
    # center
    if @real_x < last_real_x and @real_x - $game_map.display_x < center_x
      # Scroll map left
      $game_map.scroll_left(last_real_x - @real_x)
    end
    # If character moves right and is positioned more right on-screen than
    # center
    if @real_x > last_real_x and @real_x - $game_map.display_x > center_x
      # Scroll map right
      $game_map.scroll_right(@real_x - last_real_x)
    end
    # If character moves up and is positioned higher than the center
    # of the screen
    if @real_y < last_real_y and @real_y - $game_map.display_y < center_y
      # Scroll map up
      $game_map.scroll_up(last_real_y - @real_y)
    end
    # If not moving
    unless moving?
      # If player was moving last time
      if last_moving
        $PokemonTemp.dependentEvents.pbTurnDependentEvents
        result = pbCheckEventTriggerFromDistance([2])
        # Event determinant is via touch of same position event
        result |= check_event_trigger_here([1,2])
        # If event which started does not exist
        Kernel.pbOnStepTaken(result) # *Added function call
        if result == false
        end
      end
      # If C button was pressed
      if Input.trigger?(Input::C) && !$PokemonTemp.miniupdate
        # Same position and front event determinant
        check_event_trigger_here([0],true)
        check_event_trigger_there([0,2],true) # *Modified to prevent unnecessary triggers
      end
    end
  end
  # This number is the interval between bump sounds
  BUMP_INTERVAL = 15
 
  def bump_sound(dir)
    if dir != @last_bump or @bump_timer == 0
      @bump_timer = BUMP_INTERVAL
      Audio.se_play("Audio/SE/bump.wav")
    end
    @last_bump = dir
  end
 
  alias bwd_bump_gmplyr_update :update
  def update(*args)
    bwd_bump_gmplyr_update(*args)
    if @bump_timer == nil
     @bump_timer = 0
     @last_bump = 0
    end
    @bump_timer -= 1 if @bump_timer > 0
  end
end
 
[/rgss]
5 seemed too fast so I changed the interval to 15, but I think even that is faster than in actual Pokemon games
 

boon

Sponsor

Thanks. One more thing, is there a way to make the player keep trying to walk into the wall (so its legs are moving, but it doesn't walk through the wall).

Thanks, boon.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top