FANDOM


Building better bridges
This tutorial is deprecated. It is no longer relevant to the latest version of Pokémon Essentials.

This tutorial was written by Maruno. Please give credit.

Click here for more tutorials!


This tutorial describes how to implement a new system for making bridges. It solves many of the problems with the existing bridge system, including all the limitations listed in the article Bridges.

A bridge built using the scripts in this tutorial can go over land, over water or over both at the same time.

Script changes

This tutorial requires a number of script changes, because it is a new system. Here they are.

Game_Map_

In the def passable? (line 149), add in the following highlighted lines:

for i in [2, 1, 0]
  tile_id = data[x, y, i]
  tilefront=$MapFactory.getFacingTile(d)
  if tile_id == nil
    return false
  # Make water tiles passable if player is surfing
  elsif pbIsPassableWaterTag?(@terrain_tags[tile_id]) &&
    $PokemonGlobal.surfing
    return true
  elsif $PokemonMap.bridge && @terrain_tags[tile_id]==PBTerrain::Bridge
    facing=false
    if $PokemonMap.bridge[1]==4 || $PokemonMap.bridge[1]==6
     facing=true if $game_player.direction==4 || $game_player.direction==6
    elsif $PokemonMap.bridge[1]==2 || $PokemonMap.bridge[1]==8
     facing=true if $game_player.direction==2 || $game_player.direction==8
    end
    return false if $MapFactory.getFacingTerrainTag!=PBTerrain::Bridge && facing==false
    return true
  elsif $PokemonMap.bridge && $MapFactory.getTerrainTag(tilefront[0],tilefront[1],tilefront[2])==PBTerrain::Bridge
    return true
  elsif @passages[tile_id] & bit != 0
    return false

Lower down, in the def terrain_tag (now around line 235), add in the highlighted lines/parts:

def terrain_tag(x, y, checkReflection=false)
  if @map_id != 0
    for i in [2, 1, 0]
      tile_id = data[x, y, i]
      if tile_id == nil
        return 0
      elsif @terrain_tags[tile_id] && @terrain_tags[tile_id] > 0
        next if i==2 && checkReflection && @terrain_tags[tile_id]==PBTerrain::Bridge && $PokemonGlobal.surfing
        next if i==2 && checkReflection && @terrain_tags[tile_id]==PBTerrain::Bridge && $PokemonMap.bridge
        return @terrain_tags[tile_id]
      end
    end
  end
  return 0
end

Game_Character_2_

At the very bottom of this section, add in the highlighted def:

  def increase_steps
    @stop_count = 0
    triggerLeaveTile()
  end
  def alwaysOnTop=(var)
    @always_on_top = var
  end
end

Game_Player

At the top of this section are four defs that move the player. In each of them, move the line highlighted in red to a new place (highlighted in yellow):

def move_down(turn_enabled = true)
  if turn_enabled
   turn_down
  end
  pbBridgeCheck(2)
  if passable?(@x, @y, 2)
    pbBridgeCheck(2)
    return if pbLedge(0,1)
    return if pbEndSurf(0,1)

Spriteset_Map

In the class ReflectedSprite at the top of this section, add the following highlighted parts into the def update:

while i<@rsprite.src_rect.height+Game_Map::TILEHEIGHT
   nextY=currentY+1+(i>>5)
   if @event.map.terrain_tag(@event.x,nextY,true)!=6
     limit= ((nextY * (4*Game_Map::TILEHEIGHT))-@event.map.display_y+3).to_i/4
     limit-=@rsprite.y
     break
   else
     shouldShow=true if !$PokemonMap.bridge
   end
   i+=Game_Map::TILEHEIGHT
end

PokemonField

In the class PBTerrain (around line 500), add in the following highlighted line:

 UnderwaterGrass=11
 Ice=12
 Neutral=13
 SootGrass=14
 Bridge=15
end

PokemonHiddenMoves

In the def pbEndSurf (line 422), add in the highlighted line:

currentTag=$game_map.terrain_tag(x,y)
facingTag=Kernel.pbFacingTerrainTag
return false if facingTag==PBTerrain::Bridge
if pbIsSurfableTag?(currentTag)&&!pbIsSurfableTag?(facingTag)
 if Kernel.pbJumpToward

In the CanUseMove handler for Surf (around line 500), add in the highlighted part:

 if pbGetMetadata($game_map.map_id,MetadataBicycleAlways)
  Kernel.pbMessage(_INTL("Let's enjoy cycling!"))
  return false
 end
 if !pbIsWaterTag?(terrain) || $PokemonMap.bridge
  Kernel.pbMessage(_INTL("No surfing here!"))
  return false
 end
 return true
})

In the onAction procedure right below that, add in the highlighted part:

Events.onAction+=proc{|sender,e|
 terrain=Kernel.pbFacingTerrainTag
 if pbIsWaterTag?(terrain) && 
     !$PokemonGlobal.surfing && !$PokemonMap.bridge &&
     !pbGetMetadata($game_map.map_id,MetadataBicycleAlways)
  Kernel.pbSurf
  return
 end
}

PokemonDefaultItems

In the UseInField handler for each fishing rod item, add in the highlighted lines:

ItemHandlers::UseInField.add(:OLDROD,proc{|item|
  terrain=Kernel.pbFacingTerrainTag
  if !pbIsWaterTag?(terrain)
   Kernel.pbMessage(_INTL("Can't use that here."))
   next
  end
  if $MapFactory.getTerrainTag($game_player.map.map_id,$game_player.x,$game_player.y)==PBTerrain::Bridge
   Kernel.pbMessage(_INTL("Can't use that here."))
   next
  end
  encounter=$PokemonEncounters.hasEncounter?(4)
  if pbFishing(encounter)
    pbEncounter(4)
  end
})

PokemonMap

Replace the def pbBridgeFacing with this:

def pbBridgeFacing(direction)
 $PokemonMap.bridge=[0,direction]
 $game_player.alwaysOnTop=true
end

Add in these two new defs right below it:

def pbBridgeFacingUp
 pbBridgeFacing(8)
end

def pbBridgeFacingDown
 pbBridgeFacing(2)
end

Replace the def pbBridgeCheck with this:

def pbBridgeCheck(direction)
 bridge=$PokemonMap.bridge
 if bridge
  if bridge[0]==0
   if direction==bridge[1]
    if $MapFactory.getFacingTerrainTag==PBTerrain::Bridge
     $PokemonMap.bridge[0]=1
     return
    end
   end
   if bridge[1]==8
    if $MapFactory.getTerrainTag($game_player.map.map_id,$game_player.x,$game_player.y-1)==PBTerrain::Bridge
     return
    end
    if direction==4 || direction==6
     if $MapFactory.getTerrainTag($game_player.map.map_id,$game_player.x+direction-5,$game_player.y-1)==PBTerrain::Bridge
      return
     end
    elsif direction==8
     if $MapFactory.getTerrainTag($game_player.map.map_id,$game_player.x,$game_player.y-2)==PBTerrain::Bridge
      return
     end
    end
   end
   $PokemonMap.bridge=nil
   $game_player.alwaysOnTop=false
  end
 else
  facingEvent=nil
  if direction==4 || direction==6
   for event in $game_map.events.values
    if event.x==$game_player.x+direction-5 && event.y==$game_player.y
     facingEvent=event
     break
    end
   end
  elsif direction==8
   for event in $game_map.events.values
    if event.x==$game_player.x && event.y==$game_player.y-1
     facingEvent=event
     break
    end
   end
  end
  if facingEvent && facingEvent.name=="Bridge"
   $game_player.alwaysOnTop=true
   return
  end
  $game_player.alwaysOnTop=false
 end
end

Making bridges

Bridge tiles should be set up as follows:

  • Passable in all directions.
  • Have terrain tag 14.
  • Priority of 3 or higher.

Then draw the bridge in your map. The bridge tiles should be placed in the top layer.

At the ends of the bridges, on all the tiles where the player can then step onto a bridge tile, place an event. These events are as follows:

  • Called "Bridge" (without the quotes).
  • Contain a script command containing pbBridgeFacingLeft (if the bridge is to the left of this event) or similar.
  • Activate on Player Touch.

Notes

  • You can only have straight bridges. If you want to have a bridge go around a corner, you should have two separate bridges that do this.
  • The player's reflection is not shown in still water while they are on a bridge. This may be fixed later.
  • The player will appear on top of everything else (except fogs) while on or near a bridge. You should not put anything that should appear above the player in these places.
  • If the player has any dependent events, they will not display properly when going over the bridge. You should not have any multi-passable bridges in areas where the player can have a dependent event.

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.