RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
Swimming Script!

0 Members and 1 Guest are viewing this topic.

**
Rep: +0/-0Level 87
... nevermind... I think I can solve this whole problem by assigning two water autotiles with different labels.



EDIT: Hm... something's acting up, and I can't figure out what... I'm great with map layouts and programming, but not scripting...       does this script define which AUTOTILES are classified as water or can it change depending on the space?        Example... I have two of the same water autotiles on the same map. One of them (top of the tileset sheet) is defined with the terrain tag as water - the other isn't. However, the same problem occurs with the second, non-water assigned autotileset.
« Last Edit: June 16, 2007, 01:49:37 AM by DarkLordX »

**
Rep:
Level 87
lol I remember actually fixing the 1 tile bug now...but apparently it only works if drowning is off XD

np simple matter.  Try this:
Spoiler for :
Code: [Select]
#==============================================================================#
#  Swimming!  v 1.7.a                                                          #
#  By: ToriVerly @ hbgames.org                                                    #
#==============================================================================#
#  Intructions:                                                                #
#------------------------------------------------------------------------------#
=begin
 Paste this script above Main and below everything else.
 For each character you will have swimming, make a swimming sprite that has the
 same name as the character but ending with "_swim" and another with "_dive" if
 DIVE_GRAPHIC is true.
    Example: "001-Fighter01_swim.png"
 
 If TREAD_ANI = true, the character will be animated while in water when they are
 not moving.  Hence a treading water effect.  Set it to false if you don't want
 the effect.
 
 Set the WATER constant to the terrain tag ID of your water tiles or whatever tile
 you want to swim through.  When you place non water tiles over water tiles (in
 a higher layer), the non water tiles will need to have a terrain tag that is
 different than WATER and not 0 or else the characters is swim through it.
 
    IMPORTANT--->make sure your water tile is passable.
 
 If you want the ability to swim to depend on a switch, set SWIM_SWITCH to the ID
 of the game switch you're using. If you don't want to use a switch, set it to nil.
 Similarily, set SWIM_ITEM, SWIM_ARMOR or SWIM_WEAPON to the ID of the item, armor
 or weapon required for swimming and nil if there is none.  You can even set more
 than one condition!
 
 The SWIM_SE will play every time you jump into water.  If you don't want a sound,
 set DIVE_SOUND_OFF to true.
 
 The SNEAK_KEY and DASH_KEY functions can be set for Mr.Mo's ABS or an input
 letters script.  If you don't have such an input system but have another dashing
 and/or sneaking system/script, change them to Input::YourKey.
     Example: Input::X
              Input::Y
 If you don't have dashing or sneaking at all, set them to nil.
 WATER_DASHING is self explanitory.  If you want to dash in water, set it to true.
 If DROWNING is set to true, the player can jump in water if swimming is not
 available but they will get a gameover.
 Easy right? Enjoy!
=end
#------------------------------------------------------------------------------#
WATER = 1
SWIM_SWITCH = 1
SWIM_ITEM = nil
SWIM_ARMOR = nil
SWIM_WEAPON = nil
SNEAK_KEY = nil #Input::Letterres["Z"] for Mr.Mo's ABS or input letters script
DASH_KEY = nil #Input::Letters["X"] for Mr.Mo's ABS or input letters script
SWIM_SE = "022-Dive02"
DROWNING = true
WATER_DASHING = false
DIVE_SOUND_OFF = false
DIVE_GRAPHIC = true
TREAD_ANI = true
#------------------------------------------------------------------------------#

#==============================================================================#
# Game_Player                                                                  #
#------------------------------------------------------------------------------#
# Modifies the Game_Player class initialization and updating                   #
#==============================================================================#
class Game_Player < Game_Character
  attr_reader   :swim
  attr_reader   :swimming?
  attr_reader   :swim_count
  alias swim_init initialize
  def initialize
    @swim = false
    @drown_count = 0
    @swim_count = 0
    swim_init
  end
  alias swim_update update
  def update

    # Checks if swimming is triggered
    if swim_available? and on?(WATER) and !@swim
      return jump_in if facing?(WATER, 'any', 1)
    end
    # Determines if swimming and sets up the character appropriately
    if swimming?
     swim_refresh
    end
    # Drowns or prevents swimming if it is not available
    if facing?(WATER, 'any', 1) and !swim_available? and on?(WATER)
      if DROWNING == true
       drown
      elsif DROWNING == false
       move_backward
      end
    end
   # Jumps out of water at shore
    jump_forward if !on?(WATER) and !facing?(WATER, 'any', 1) and !facing?(WATER, 'any', 2) and @swim and moving?
    # Returns original settings when out of water
    revert if @swim and !on?(WATER)
  swim_update
 end
#------------------------------------------------------------------------------#
# Custom Methods                                                               #
#------------------------------------------------------------------------------#
  # Checks swimming availability
  def swim_available?
     if SWIM_SWITCH != nil
      return true if $game_switches[SWIM_SWITCH]
      return false if !$game_switches[SWIM_SWITCH]
     end
     if SWIM_ITEM != nil
       return true if $game_party.item_number(SWIM_ITEM) != 0
       return false if $game_party.item_number(SWIM_ITEM) == 0
     end
     if SWIM_ARMOR != nil
       return true if $game_party.actors[0].armor1_id == SWIM_ARMOR
       return true if $game_party.actors[0].armor2_id == SWIM_ARMOR
       return true if $game_party.actors[0].armor3_id == SWIM_ARMOR
       return true if $game_party.actors[0].armor4_id == SWIM_ARMOR
       return false
     end
     if SWIM_WEAPON != nil
       return true if $game_party.actors[0].weapon_id == SWIM_WEAPON
       return false
     end
     return true
   end
   
  # Jumps in the water if swimming is triggered
  def jump_in
    @swim = true
    unless DIVE_SOUND_OFF
     @play_sound = true
    end
   if DIVE_GRAPHIC == true
    @character_name = $game_party.actors[0].character_name
    @character_name = $game_party.actors[0].character_name + "_dive"
   end
   jump_forward
  end
 
  # Swimming setup
  def swim_refresh
      get_speed if moving?
      if !moving?
        @character_name = $game_party.actors[0].character_name
        @character_name = $game_party.actors[0].character_name + "_swim"
      end
      if @play_sound and !moving?
         Audio.se_play("Audio/SE/" + SWIM_SE + ".ogg", 80, 100)
         @play_sound = false
      end
         @swim = true
      if TREAD_ANI == true
         @step_anime = true
       end
     end
     
  # Drowning
  def drown
    $game_screen.start_flash(Color.new(255,0,0,128), 20)
    if @drown_count <= 10
      jump_in if !@swim and facing?(WATER, 'any', 1)
      @drown_count += 1
    elsif @drown_count >= 10
      @drown_count = 0
     $scene = Scene_Gameover.new
    end
  end
 
  # Reverts original settings when out of water
  def revert
      @character_name = $game_party.actors[0].character_name
      @swim = false
      @drown_count = 0
        unless dashing? or sneaking?
         @move_speed = 4
         @move_frequency = 6
        end
       if TREAD_ANI == true
       @step_anime = false
     end
   end
   
  # Determines Speed (Swim Leveling)
  def get_speed
    # Gets Swim Count
      @swim_count += 0.05
    case @swim_count
    when 0.05
      @swim_speed = 1
      @move_frequency = 1
    when 100
      @swim_speed =  2
      @move_frequency = 1
    when 250
      @swim_speed = 3
      @move_frequency = 1
    when 750
      @swim_speed = 4
      @move_frequency = 1
    when 2000
      @swim_speed = 5
      @move_frequency = 1
    end
    @move_speed = @swim_speed
      if WATER_DASHING == true
          if DASH_KEY != nil and Input.press?(DASH_KEY) and !sneaking?
           @move_speed = @swim_speed + 1
           @move_frequency = 6
          end
          if SNEAK_KEY != nil and Input.press?(SNEAK_KEY) and !dashing?
           @move_speed = @swim_speed -1
           @move_frequency = 2
         end
       end
     end
 
# Jumps forward
  def jump_forward
  case @direction
      when 2
        jump(0, 1)
      when 4
        jump(-1, 0)
      when 6
        jump(1, 0)
      when 8
        jump(0, -1)
      end
    end
  # Jumps backward
  def jump_backward
    case @direction
      when 2
        jump(0, -1)
      when 4
        jump(1, 0)
      when 6
        jump(-1, 0)
      when 8
        jump(0, 1)
      end
    end

  # Checks if dashing
  def dashing?
    return true if DASH_KEY != nil and Input.press?(DASH_KEY)
    return false if SNEAK_KEY != nil and Input.press?(SNEAK_KEY)
  end
  # Checks if sneaking
  def sneaking?
    return true if SNEAK_KEY != nil and Input.press?(SNEAK_KEY)
    return false if DASH_KEY != nil and Input.press?(DASH_KEY)
  end
  # Checks if swimming
  def swimming?
    return true if on?(WATER) and @swim
  end
  # Checks if player is on a terrain tag
  def on?(tag)
    return true if $game_map.terrain_tag($game_player.x, $game_player.y) == tag
  end
  # Checks if player is facing a terrain tag
  def facing?(tag, dir, dist)
    case dir
     when 2
       if $game_player.direction == 2
        tag_x = $game_player.x
        tag_y = $game_player.y + dist
      end
     when 4
       if $game_player.direction == 4
        tag_x = $game_player.x - dist
        tag_y = $game_player.y
       end
     when 6
       if $game_player.direction == 6
        tag_x = $game_player.x + dist
        tag_y = $game_player.y
       end
     when 8
       if $game_player.direction == 8
        tag_x = $game_player.x
        tag_y = $game_player.y - dist
      end
     when 'any'
       if $game_player.direction == 2
        tag_x = $game_player.x
        tag_y = $game_player.y + dist
      end
       if $game_player.direction == 4
        tag_x = $game_player.x - dist
        tag_y = $game_player.y
      end
       if $game_player.direction == 6
        tag_x = $game_player.x + dist
        tag_y = $game_player.y
      end
      if $game_player.direction == 8
        tag_x = $game_player.x
        tag_y = $game_player.y - dist
      end
    end
   return false if tag_x == nil or tag_y == nil
   return true if $game_map.terrain_tag(tag_x, tag_y) == tag
 end
end
#------------------------------------------------------------------------------#
# By ToriVerly                                                                 #
#------------------------------------------------------------------------------#

« Last Edit: June 16, 2007, 03:08:31 PM by toriverly »

**
Rep: +0/-0Level 87
Alright.. what exactly should this update do? :P

**
Rep:
Level 87
shouldn't drown on a single water tile.

**
Rep: +0/-0Level 87
.. as in it won't jump? The problem isn't that they don't drown, (and they don't) it's that the jump as if they were about to drown.. ? :-X

**
Rep:
Level 87
Okaaaaaaaaay...so, the character is supposed to drown on a single tile of water, but all that happens is the screen flashes and they jump over it unscathed?
Spoiler for This should work:
Code: [Select]
#==============================================================================#
#  Swimming!  v 1.7.b                                                          #
#  By: ToriVerly @ hbgames.org                                                    #
#==============================================================================#
#  Intructions:                                                                #
#------------------------------------------------------------------------------#
=begin
 Paste this script above Main and below everything else.
 For each character you will have swimming, make a swimming sprite that has the
 same name as the character but ending with "_swim" and another with "_dive" if
 DIVE_GRAPHIC is true.
    Example: "001-Fighter01_swim.png"
 
 If TREAD_ANI = true, the character will be animated while in water when they are
 not moving.  Hence a treading water effect.  Set it to false if you don't want
 the effect.
 
 Set the WATER constant to the terrain tag ID of your water tiles or whatever tile
 you want to swim through.  When you place non water tiles over water tiles (in
 a higher layer), the non water tiles will need to have a terrain tag that is
 different than WATER and not 0 or else the characters is swim through it.
 
    IMPORTANT--->make sure your water tile is passable.
 
 If you want the ability to swim to depend on a switch, set SWIM_SWITCH to the ID
 of the game switch you're using. If you don't want to use a switch, set it to nil.
 Similarily, set SWIM_ITEM, SWIM_ARMOR or SWIM_WEAPON to the ID of the item, armor
 or weapon required for swimming and nil if there is none.  You can even set more
 than one condition!
 
 The SWIM_SE will play every time you jump into water.  If you don't want a sound,
 set DIVE_SOUND_OFF to true.
 
 The SNEAK_KEY and DASH_KEY functions can be set for Mr.Mo's ABS or an input
 letters script.  If you don't have such an input system but have another dashing
 and/or sneaking system/script, change them to Input::YourKey.
     Example: Input::X
              Input::Y
 If you don't have dashing or sneaking at all, set them to nil.
 WATER_DASHING is self explanitory.  If you want to dash in water, set it to true.
 If DROWNING is set to true, the player can jump in water if swimming is not
 available but they will get a gameover.
 Easy right? Enjoy!
=end
#------------------------------------------------------------------------------#
WATER = 1
SWIM_SWITCH = 1
SWIM_ITEM = nil
SWIM_ARMOR = nil
SWIM_WEAPON = nil
SNEAK_KEY = nil #Input::Letterres["Z"] for Mr.Mo's ABS or input letters script
DASH_KEY = nil #Input::Letters["X"] for Mr.Mo's ABS or input letters script
SWIM_SE = "022-Dive02"
DROWNING = true
WATER_DASHING = false
DIVE_SOUND_OFF = false
DIVE_GRAPHIC = true
TREAD_ANI = true
#------------------------------------------------------------------------------#

#==============================================================================#
# Game_Player                                                                  #
#------------------------------------------------------------------------------#
# Modifies the Game_Player class initialization and updating                   #
#==============================================================================#
class Game_Player < Game_Character
  attr_reader   :swim
  attr_reader   :swimming?
  attr_reader   :swim_count
  alias swim_init initialize
  def initialize
    @swim = false
    @drown_count = 0
    @swim_count = 0
    swim_init
  end
  alias swim_update update
  def update

    # Checks if swimming is triggered
    return jump_in if facing?(WATER, 'any', 1) and !@swim and moving?
    # Determines if swimming and sets up the character appropriately
     swim_refresh if swimming?
    # Drowns or prevents swimming if it is not available
    if !swim_available? and on?(WATER)
      if DROWNING == true
       drown
      elsif DROWNING == false
       move_backward
      end
    end
   # Jumps out of water at shore
    jump_forward if !on?(WATER) and !facing?(WATER, 'any', 1) and !facing?(WATER, 'any', 2) and @swim and moving?
    # Returns original settings when out of water
    revert if @swim and !on?(WATER)
  swim_update
 end
#------------------------------------------------------------------------------#
# Custom Methods                                                               #
#------------------------------------------------------------------------------#
  # Checks swimming availability
  def swim_available?
     if SWIM_SWITCH != nil
      return true if $game_switches[SWIM_SWITCH]
      return false if !$game_switches[SWIM_SWITCH]
     end
     if SWIM_ITEM != nil
       return true if $game_party.item_number(SWIM_ITEM) != 0
       return false if $game_party.item_number(SWIM_ITEM) == 0
     end
     if SWIM_ARMOR != nil
       return true if $game_party.actors[0].armor1_id == SWIM_ARMOR
       return true if $game_party.actors[0].armor2_id == SWIM_ARMOR
       return true if $game_party.actors[0].armor3_id == SWIM_ARMOR
       return true if $game_party.actors[0].armor4_id == SWIM_ARMOR
       return false
     end
     if SWIM_WEAPON != nil
       return true if $game_party.actors[0].weapon_id == SWIM_WEAPON
       return false
     end
     return true
   end
   
  # Jumps in the water if swimming is triggered
  def jump_in
    @swim = true
    unless DIVE_SOUND_OFF
     @play_sound = true
    end
   if DIVE_GRAPHIC == true
    @character_name = $game_party.actors[0].character_name
    @character_name = $game_party.actors[0].character_name + "_dive"
   end
   jump_forward if facing?(WATER, 'any', 1)
  end
 
  # Swimming setup
  def swim_refresh
      get_speed if moving?
      if !moving?
        @character_name = $game_party.actors[0].character_name
        @character_name = $game_party.actors[0].character_name + "_swim"
      end
      if @play_sound and !moving?
         Audio.se_play("Audio/SE/" + SWIM_SE + ".ogg", 80, 100)
         @play_sound = false
      end
         @swim = true
      if TREAD_ANI == true
         @step_anime = true
       end
     end
     
  # Drowning
  def drown
    $game_screen.start_flash(Color.new(255,0,0,128), 20)
    if @drown_count <= 50
      #jump_in if !@swim
      @drown_count += 1
    elsif @drown_count >= 50
      @drown_count = 0
     $scene = Scene_Gameover.new
    end
  end
 
  # Reverts original settings when out of water
  def revert
      @character_name = $game_party.actors[0].character_name
      @swim = false
      @drown_count = 0
        unless dashing? or sneaking?
         @move_speed = 4
         @move_frequency = 6
        end
       if TREAD_ANI == true
       @step_anime = false
     end
   end
   
  # Determines Speed (Swim Leveling)
  def get_speed
    # Gets Swim Count
      @swim_count += 0.05
    case @swim_count
    when 0.05
      @swim_speed = 1
      @move_frequency = 1
    when 100
      @swim_speed =  2
      @move_frequency = 1
    when 250
      @swim_speed = 3
      @move_frequency = 1
    when 750
      @swim_speed = 4
      @move_frequency = 1
    when 2000
      @swim_speed = 5
      @move_frequency = 1
    end
    @move_speed = @swim_speed
      if WATER_DASHING == true
          if DASH_KEY != nil and Input.press?(DASH_KEY) and !sneaking?
           @move_speed = @swim_speed + 1
           @move_frequency = 6
          end
          if SNEAK_KEY != nil and Input.press?(SNEAK_KEY) and !dashing?
           @move_speed = @swim_speed -1
           @move_frequency = 2
         end
       end
     end
 
# Jumps forward
  def jump_forward
  case @direction
      when 2
        jump(0, 1)
      when 4
        jump(-1, 0)
      when 6
        jump(1, 0)
      when 8
        jump(0, -1)
      end
    end
  # Jumps backward
  def jump_backward
    case @direction
      when 2
        jump(0, -1)
      when 4
        jump(1, 0)
      when 6
        jump(-1, 0)
      when 8
        jump(0, 1)
      end
    end

  # Checks if dashing
  def dashing?
    return true if DASH_KEY != nil and Input.press?(DASH_KEY)
    return false if SNEAK_KEY != nil and Input.press?(SNEAK_KEY)
  end
  # Checks if sneaking
  def sneaking?
    return true if SNEAK_KEY != nil and Input.press?(SNEAK_KEY)
    return false if DASH_KEY != nil and Input.press?(DASH_KEY)
  end
  # Checks if swimming
  def swimming?
    return true if on?(WATER) and @swim
  end
  # Checks if player is on a terrain tag
  def on?(tag)
    return true if $game_map.terrain_tag($game_player.x, $game_player.y) == tag
  end
  # Checks if player is facing a terrain tag
  def facing?(tag, dir, dist)
    case dir
     when 2
       if $game_player.direction == 2
        tag_x = $game_player.x
        tag_y = $game_player.y + dist
      end
     when 4
       if $game_player.direction == 4
        tag_x = $game_player.x - dist
        tag_y = $game_player.y
       end
     when 6
       if $game_player.direction == 6
        tag_x = $game_player.x + dist
        tag_y = $game_player.y
       end
     when 8
       if $game_player.direction == 8
        tag_x = $game_player.x
        tag_y = $game_player.y - dist
      end
     when 'any'
       if $game_player.direction == 2
        tag_x = $game_player.x
        tag_y = $game_player.y + dist
      end
       if $game_player.direction == 4
        tag_x = $game_player.x - dist
        tag_y = $game_player.y
      end
       if $game_player.direction == 6
        tag_x = $game_player.x + dist
        tag_y = $game_player.y
      end
      if $game_player.direction == 8
        tag_x = $game_player.x
        tag_y = $game_player.y - dist
      end
    end
   return false if tag_x == nil or tag_y == nil
   return true if $game_map.terrain_tag(tag_x, tag_y) == tag
 end
end
#------------------------------------------------------------------------------#
# By ToriVerly                                                                 #
#------------------------------------------------------------------------------#
Now the player should jump from a square away from the water's edge so they land right in the narrow streams and will drown. If the RGSS would allow me to make the player jump straight up, it'd look better but at least it works....i think...give me feed back

**
Rep: +0/-0Level 87
Yes, exactly. The previous problem is gone now, but....   although it may seem insignificant, there is a pause between the red flash and the Game Over scene call. The pause is long enough for a character to jump right out again on the other side. ;/

Don't want to be a pest... just trying to get this script all working through. ;/ (Also... for some reason, the other party members' swim animations aren't appearing now... they're just walking across the water... but I don't know if this is something to do with the swimming script or if it's just a deficiency of the Caterpillar script I'm using.)

**
Rep:
Level 87
Okay
#1 I fixed the water passability issue.  No more followers walking on water.
#2 I have no idea how to change all party's characters' sprites and back...one way operation as far as I know...I think there's something I can do with the  .gsub! command, but so far I don't get it and the game ends up saying crap like "can't find hero_dive_swim_swim.png"...I think I should have mentioned that when you told me you were using a caterpiller but it slipped my mind XD.
#3 I like the pause giving the player a chance to save himself.  if you don't like it, change "def drown" to this:
Code: [Select]
  # Drowning
  def drown
        $game_screen.start_flash(Color.new(255,0,0,128), 20)
        $scene = Scene_Gameover.new
  end
I apologize about the party members' graphics.  The script changes the $game_player graphic but leaves the $game_party.actor graphic the same.  To change the other guys' graphics, I'd have to change $game_party.actors graphics...and I wouldn't know how to change them back once you're out the water.  :(

**
Rep: +0/-0Level 87
Alright, thanks. :) Water passability thing's doing something REAL weird now... but it works great with drowning.

... quick question though: What's the scripting to add a short pause between script commands?

**
Rep:
Level 87
Supposedly, you cant put @wait_count = whatever, but it doesn't seem to work for me so I do stuff like
Code: [Select]
if variable < desired ammount
variable +=1
elsif variable > desired ammount
do whatever
end
and then I have the update or refresh thing go through it whenever the right conditions are met.

what's wrong with the passability?

**
Rep: +0/-0Level 87
Well... until further notice, I can't even use this. By now I've just decided against it. ;/

When drowning is off, and you go near a water tile, (within 1 space) the lead member goes into the Dive animation, shakes like mad, spazzes out with the other party members following suit, and does all sorts of crazy things before finally stopping in front of the water. With drowning on, I can't go within 1 tile of the water without drowning, so the Stream Hop thing would then be obsolete.

**
Rep:
Level 84
im coolz
can you give me a DEMO

****
Rep:
Level 83
nice script old, wish i wouldve found this earlier wouldve came in handy for my first game i made
Spoiler for:
METALFRESH is a paint contractor that specializes in refinishing metal and vinyl siding. We paint metal buildings as well as siding on homes.

We also

    Refinish decks
    Do custom interior painting
    Strip wallpaper
    Refinish cedar siding
    Metal front doors and sidelights
    Metal garage and service doors
    Grained fiberglass doors

    If your structure is *RUSTED *FADED *CHALKING *IN NEED OF COLOR CHANGE, we can fix it with a guarentee!

northern Illinois and southern Wisconsin.

http://metalfreshcoatings.com


*
Rep: +0/-0Level 81
I still donĀ“t understand how to put the swiming availity in a Armor. I want it to bo the armor 36 or 37 or 38 or 39 or 40. Can you explain? Pls