avarisc's Waterbound Events

avarisc's Waterbound Events


A quick and dirty script for something that I am stunned is not a builtin feature.
Very simple, this allows you to make waterbound events.
Add a comment to any event containing [waterbound] and it will become able to move on water, and unable to move on land.

That's it; doesn't really need screenshots or jazz. It's public domain, so don't worry about credit or permission or anything. Go nuts.


  1. # Waterbound 1.0 (3/23/15)                                         -by avarisc #
  2. # * Add a comment to an event containing "[waterbound]" (without quotes)
  3. # The event will then be able to move on water, and unable to walk on land.
  4. # License: Public Domain. Have a blast.
  5. #==============================================================================#
  6. class Game_Event < Game_Character
  7.   def check_waterbound(page)
  8.     command_list = page.list
  9.     (0..command_list.length - 2).each {|k|
  10.       command = command_list[k]
  11.       next if command.code != 108        
  12.       @waterbound = true if command.parameters[0][/waterbound/]
  13.     }
  14.   end
  15.   alias refresh_waterbound_game_character refresh
  16.   def refresh
  17.     refresh_waterbound_game_character
  18.     @waterbound = false
  19.     if @page then check_waterbound(@page) end
  20.   end
  21. end
  22. class Game_CharacterBase
  23.   def map_passable?(x, y, d)
  24.     return $game_map.boat_passable?(x, y) if @waterbound
  25.     return $game_map.passable?(x, y, d)
  26.   end
  27. end
Expand to see the code.
I was going to ask how you determine if it's water but I see you're using the boat check. This is a great thing...for random move events I guess since otherwise you have total control of events and can just make them pass through everything anyway.
Cool, I needed this about seven years ago. :thumb:
Princess Amy wrote:
Cool, I needed this about seven years ago. :thumb:

VXA only, you're not missing out on anything.

Although didn't RMXP have zone tagging in the tileset database editor? Couldn't that be used to achieve the same effect? I guess that would work by testing zone tag in stead of boat_passable

EDIT: Also, noob question probably, but when is game character refresh called?

EDIT2: Would this convert it to XP?
  1. WATER_TAG = 1 # change to whatever terrain tag you want to be water
  2.  
  3. class Game_CharacterBase
  4.   def map_passable?(x, y, d)
  5.     return true if $game_map.terrain_tag(x, y) == WATER_TAG and @waterbound
  6.     return $game_map.passable?(x, y, d)
  7.   end
  8. end
Expand to see the code.

If this does work, would it be possible to make it so you could add the desired terrain tag number that the event considers as water to the event comment?
Here's an XP version, based on Xilef's suggestion (needed a few other changes)

  1. class Game_Character
  2.    
  3.     WATER_TERRAIN_TAG = 1 # change to whatever terrain tag you want to be water
  4.    
  5.     def passable?(x, y, d)
  6.     # Get new coordinates
  7.     new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
  8.     new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
  9.     # If coordinates are outside of map
  10.     unless $game_map.valid?(new_x, new_y)
  11.       # impassable
  12.       return false
  13.     end
  14.     # If through is ON
  15.     if @through
  16.       # passable
  17.       return true
  18.     end
  19.     if(@waterbound)
  20.       # If unable to leave first move tile in designated direction
  21.       unless $game_map.terrain_tag(x, y) == WATER_TERRAIN_TAG
  22.         # impassable
  23.         return false
  24.       end
  25.       # If unable to enter move tile in designated direction
  26.       unless $game_map.terrain_tag(new_x, new_y) == WATER_TERRAIN_TAG
  27.         # impassable
  28.         return false
  29.       end  
  30.     else
  31.       # If unable to leave first move tile in designated direction
  32.       unless $game_map.passable?(x, y, d, self)
  33.         # impassable
  34.         return false
  35.       end
  36.       # If unable to enter move tile in designated direction
  37.       unless $game_map.passable?(new_x, new_y, 10 - d)
  38.         # impassable
  39.         return false
  40.       end
  41.     end
  42.     # Loop all events
  43.     for event in $game_map.events.values
  44.       # If event coordinates are consistent with move destination
  45.       if event.x == new_x and event.y == new_y
  46.         # If through is OFF
  47.         unless event.through
  48.           # If self is event
  49.           if self != $game_player
  50.             # impassable
  51.             return false
  52.           end
  53.           # With self as the player and partner graphic as character
  54.           if event.character_name != ""
  55.             # impassable
  56.             return false
  57.           end
  58.         end
  59.       end
  60.     end
  61.     # If player coordinates are consistent with move destination
  62.     if $game_player.x == new_x and $game_player.y == new_y
  63.       # If through is OFF
  64.       unless $game_player.through
  65.         # If your own graphic is the character
  66.         if @character_name != ""
  67.           # impassable
  68.           return false
  69.         end
  70.       end
  71.     end
  72.     # passable
  73.     return true
  74.   end
  75. end
  76. class Game_Event < Game_Character
  77.   def check_waterbound(page)
  78.     command_list = page.list
  79.     (0..command_list.length - 2).each {|k|
  80.       command = command_list[k]
  81.       next if command.code != 108        
  82.       @waterbound = true if command.parameters[0][/waterbound/]
  83.     }
  84.   end
  85.   alias refresh_waterbound_game_character refresh
  86.   def refresh
  87.     refresh_waterbound_game_character
  88.     @waterbound = false
  89.     if @page then check_waterbound(@page) end
  90.   end
  91. end
Expand to see the code.


And refresh is called when the character is setup to be displayed on the map. It works for random movement, and more importantly to me, for approach movement.

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=78591