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.

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.


Code:
# Waterbound 1.0 (3/23/15)                                         -by avarisc #

# * Add a comment to an event containing "[waterbound]" (without quotes)

# The event will then be able to move on water, and unable to walk on land.

# License: Public Domain. Have a blast.

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

class Game_Event < Game_Character

  def check_waterbound(page)

    command_list = page.list

    (0..command_list.length - 2).each {|k|

      command = command_list[k]

      next if command.code != 108        

      @waterbound = true if command.parameters[0][/waterbound/]

    }

  end

  alias refresh_waterbound_game_character refresh

  def refresh

    refresh_waterbound_game_character

    @waterbound = false

    if @page then check_waterbound(@page) end

  end

end

class Game_CharacterBase

  def map_passable?(x, y, d)

    return $game_map.boat_passable?(x, y) if @waterbound

    return $game_map.passable?(x, y, d)

  end

end
 
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.
 
Princess Amy":24zmwhah said:
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?
Ruby:
WATER_TAG = 1 # change to whatever terrain tag you want to be water

 

class Game_CharacterBase

  def map_passable?(x, y, d)

    return true if $game_map.terrain_tag(x, y) == WATER_TAG and @waterbound

    return $game_map.passable?(x, y, d)

  end

end
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)

Code:
class Game_Character

    

    WATER_TERRAIN_TAG = 1 # change to whatever terrain tag you want to be water

    

    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.valid?(new_x, new_y)

      # impassable

      return false

    end

    # If through is ON

    if @through

      # passable

      return true

    end

    if(@waterbound)

      # If unable to leave first move tile in designated direction

      unless $game_map.terrain_tag(x, y) == WATER_TERRAIN_TAG

        # impassable

        return false

      end

      # If unable to enter move tile in designated direction

      unless $game_map.terrain_tag(new_x, new_y) == WATER_TERRAIN_TAG

        # impassable

        return false

      end  

    else

      # If unable to leave first move tile in designated direction

      unless $game_map.passable?(x, y, d, self)

        # impassable

        return false

      end

      # If unable to enter move tile in designated direction

      unless $game_map.passable?(new_x, new_y, 10 - d)

        # impassable

        return false

      end

    end

    # Loop all events

    for event in $game_map.events.values

      # If event coordinates are consistent with move destination

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

        # If through is OFF

        unless event.through

          # If self is event

          if self != $game_player

            # impassable

            return false

          end

          # With self as the player and partner graphic as character

          if event.character_name != ""

            # impassable

            return false

          end

        end

      end

    end

    # If player coordinates are consistent with move destination

    if $game_player.x == new_x and $game_player.y == new_y

      # If through is OFF

      unless $game_player.through

        # If your own graphic is the character

        if @character_name != ""

          # impassable

          return false

        end

      end

    end

    # passable

    return true

  end

end

class Game_Event < Game_Character

  def check_waterbound(page)

    command_list = page.list

    (0..command_list.length - 2).each {|k|

      command = command_list[k]

      next if command.code != 108        

      @waterbound = true if command.parameters[0][/waterbound/]

    }

  end

  alias refresh_waterbound_game_character refresh

  def refresh

    refresh_waterbound_game_character

    @waterbound = false

    if @page then check_waterbound(@page) end

  end

end

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.
 

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