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:
Level 87
    Swimming
    Version: 1.7

    Introduction

    It seems to me that most swimming is done through event systems or Seph's vehicle script which is fine if you want to hop on a penguin to get across a river but we all know swimming isn't the same as riding a bike.  I saw a lot of requests for a swimming script so I thought I'd make one.  This is my first script that does something more interesting than displaying a window XD.

    The script will cause the following when the player approaches water:
    • The player will change to a diving graphic (optional)
    • The player will jump into a body of water (at least 2 tiles wide)
    • A sound is played (optional and customizable)
    • The player will change to a swimming graphic
    • The speed will change
    • The player will jump out of water onto land that is at least 2 tiles wide and walk onto land that is 1 tile wide
    • Swimming can be but doesn't have to be, controled by a switch
    • If swimming is not available (switch is off, doesn't have an item/armor/weapon), water will be impassable OR the player can drown

    Updates
    • Added more availability conditions
    • Fixed the problem that disabling swimming didn't really do anything XD
    • Removed custom dashing and sneaking animation suffixes.  They don't work. Sorry!
    • Fixed bug where player will jump right non water tiles if there is only one and water behind it
    • Added leveling up; you can swim faster if you swim more
    • Changed in water dashing speed and availability option
    • Added diving graphic change option
    • Added 'treading water' effect
    • Added Touch Swim
    • Added dashing and sneaking ability
    • Fixed the bug where the character gets trapped on an impassable tile after getting out of water
    Templates
    Diving Template: Edited from Mack's male

    It only needs 4 frames because it is only visible for a second.
    Swimming Template: Again from Mack's male


    Screenshots
    Before

    Diving (I thought I'd show off the side view :))

    In the water


    Script

    Spoiler for Swimming Script:
    [/list]
    Code: [Select]
    #==============================================================================#
    #  Swimming!  v 1.8                                                          #
    #  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 on, the player will have about three seconds to get out of water
     before they die (if swimming isn't available). If it is off, water will just be
     impassable.
     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"
    DROWN_SE = "021-Dive01"
    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 DROWNING == true
        return jump_in if facing?(WATER, 'any', 1) and !@swim and moving?
        # Drowns if it is not available
        drown if !swim_available? and on?(WATER)
        elsif DROWNING == false
        return jump_in if facing?(WATER, 'any', 1) and !@swim and moving? and swim_available?
        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)
       
        # Refreshes swimming state
         swim_refresh if swimming?
      swim_update
    end

        # Makes water impassable when swimming isn't available
      alias mrmo_swim_game_player_passable passable?
      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)
        # Check if it water tag
        return false if $game_map.terrain_tag(new_x,new_y) == WATER and !swim_available? and DROWNING == false
        # Old Method
        mrmo_swim_game_player_passable(x,y,d)
      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 , 80, 100)
             @play_sound = false
          end
             @swim = true
          if TREAD_ANI == true
             @step_anime = true
           end
         end
         
      # Drowning
      def drown
        @move_speed = 0.1
        if @drown_count <= 120
          #jump_in if !@swim
          @drown_count += 1
            if @drown_count %40 == 0
              Audio.se_play("Audio/SE/" + DROWN_SE, 80, 100)
            end
          elsif @drown_count >= 120
          @character_name = ""
          @drown_count = 0
          Audio.se_play("Audio/SE/" + SWIM_SE, 80, 100)
         $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
    # Thanks to Mr.Mo for help with my passability issues and to Chaosg1 for my intro
    # into scripting :)
    #------------------------------------------------------------------------------#

    Instructions

    See Script

    Compatibility

    According to an SDK user, this script is compatible.
    So far scripts that change actor graphics are buggy with this.  It can be easily fixed if you know what you're doing....:
    If using another script/system that changes actor graphic
    [INDENT]Find the line that changes the graphic and add to the conditions:
    Code: [Select]
    and if $game_player.terrain_tag != WATER
    Make sure that at the top of your script, outside commenting and before anything that starts with 'class', put
    Code: [Select]
    WATER = 1
    [or change 1 to whatever terrain tag you are using for water.]
    If none of that made sense, then for now it's not compatable with any script changing graphics.
    « Last Edit: June 21, 2007, 06:35:14 AM by toriverly »

    *****
    Ancient Mummy
    Rep:
    Level 90
    XD

    That's funny but still..
    I LOVE IT !!!
    good job :D

    **
    Rep:
    Level 87
    Thanks!

    but what's funny? lol

    ********
    EXA
    Rep:
    Level 92
    Pikachu on a toilet
    Project of the Month winner for April 2007
    Get King of Booze for Android, for iOS, for OUYA or for Windows!
    Visit our website.
    You can also love/hate us on Facebook or the game itself.


    Get DropBox, the best free file syncing service there is!


    *
    ? ? ? ? ? ? ? ? ? The nice kind of alien~
    Rep:
    Level 92
    Martian - Occasionally kind

    *
    Rep:
    Level 102
    2014 Biggest Narcissist Award2014 Biggest Forum Potato2014 Best Non-RM Creator2013 Best Game Creator (Non-RM)2013 Best IRC ChatterboxParticipant - GIAW 112012 Most Successful Troll2012 Funniest Member2012 Best Use Of Avatar and Signature space2012 Best IRC ChatterboxSecret Santa 2012 ParticipantProject of the Month winner for November 2009For being a noted contributor to the RMRK Wiki2010 Most Successful Troll2010 Biggest Forum Couch Potato2010 Best IRC Chatterbox
    I keep getting

    Code: [Select]
    ????? 'swimming'? 28??? NameError????????
    uninitialized constant Input::Letters


    Never mind. Blizzard fixed it. ;D
    « Last Edit: February 26, 2007, 07:25:49 PM by Irockman1 »

    ***
    Rep:
    Level 88
    Menu & Battle System Guru
    well thats useful, nice job.

    ********
    EXA
    Rep:
    Level 92
    Pikachu on a toilet
    Project of the Month winner for April 2007
    I keep getting

    Code: [Select]
    ????? 'swimming'? 28??? NameError????????
    uninitialized constant Input::Letters
    I changed it to nil.


    Nvm, I fixed it for him on AIM.
    Get King of Booze for Android, for iOS, for OUYA or for Windows!
    Visit our website.
    You can also love/hate us on Facebook or the game itself.


    Get DropBox, the best free file syncing service there is!

    **
    Rep:
    Level 87
    Thanks guys, i'm glad you like it :). This is my first script that does something more interesting than showing a window btw lol.  Anything you guys think I could add to it? Like I said, it probably won't happen this week because my mom is cracking the h/w whip over my head.

    EDIT: How many here would like the character to "tread water" and animate (while not moving) in water?
    « Last Edit: February 26, 2007, 11:17:28 PM by toriverly »

    *
    Rep:
    Level 102
    2014 Biggest Narcissist Award2014 Biggest Forum Potato2014 Best Non-RM Creator2013 Best Game Creator (Non-RM)2013 Best IRC ChatterboxParticipant - GIAW 112012 Most Successful Troll2012 Funniest Member2012 Best Use Of Avatar and Signature space2012 Best IRC ChatterboxSecret Santa 2012 ParticipantProject of the Month winner for November 2009For being a noted contributor to the RMRK Wiki2010 Most Successful Troll2010 Biggest Forum Couch Potato2010 Best IRC Chatterbox
    Thanks guys, i'm glad you like it :). This is my first script that does something more interesting than showing a window btw lol.  Anything you guys think I could add to it? Like I said, it probably won't happen this week because my mom is cracking the h/w whip over my head.

    EDIT: How many here would like the character to "tread water" and animate (while not moving) in water?
    Me! I would also like a good splash animation for when the hero jumps in.

    **
    Rep:
    Level 88
    Patriots all the way!!
    Awesome!!!!  ;D I LOVE IT!!! I am adding this to my favorites.
    Im to cool to have my own signature!!!

    pokeball :)OfflineMale
    ********
    Cheese
    Rep:
    Level 95
    ?
    This is very nice.

    *Script databse* ?
    Watch out for: HaloOfTheSun

    **
    Rep:
    Level 88
    Patriots all the way!!
    Ok...I know this is soon, but I am like the biggest noob and I dont know how to edit the sprites. Or add the stuff to the script.
    Im to cool to have my own signature!!!

    **
    Rep:
    Level 87
    I know I said I had homework...and I do...but it was so boring...and the script was calling me...so it's updated ;8
    @Valcos: What are you adding? My crappy sprite was just the regular one cut off at the armpits.  It actually looks good if you put a little bit of blue splash around them.
    @Nouman: Do I put it there? or a mod?
    @Irockman1: I'd love an animation also, but I don't know anything about them  :'(

    pokeball :)OfflineMale
    ********
    Cheese
    Rep:
    Level 95
    ?
    @Nouman: Do I put it there? or a mod?

    Once a mod sees fit to this they can move it to the database. I was just suggesting it. =D
    Watch out for: HaloOfTheSun

    *
    ? ? ? ? ? ? ? ? ? The nice kind of alien~
    Rep:
    Level 92
    Martian - Occasionally kind
    Nouman, just report the topic to a moderator and write something like "Should be moved to the Script Database" in the comment field.
    If you believe this topic belongs to the Script Database instead of Scripts it should be reported.
    I'll let you do the honors ;)

    ********
    EXA
    Rep:
    Level 92
    Pikachu on a toilet
    Project of the Month winner for April 2007
    I've seen this topic already and there's one flaw in the script which makes me think it's not ready for the database yet.
    I think you should find a way to use the usual character spriteset without the need for an extra cut-off sprite. It's rather easy, you only need to check out how the Sprite_Character class works (mainly def update where the bitmap gets cached). If you can change that in your script, I'll move it into the database, since I'm checking this topic daily. :)
    Get King of Booze for Android, for iOS, for OUYA or for Windows!
    Visit our website.
    You can also love/hate us on Facebook or the game itself.


    Get DropBox, the best free file syncing service there is!

    **
    Rep:
    Level 87
    You mean not to change the sprite or find a way to cut off the sprite without a new one?  I think most people will like the diving sprite change because that one will be totally different. (ei. cannonball or a jumpy/dashy one) I suppose the script works best with the cut off sprites, but it doesn't look right without the ripples around it...(I'll update the screen shot soon)and I was going to get a template for a sprite that does a sort of breast stroke.

    ********
    EXA
    Rep:
    Level 92
    Pikachu on a toilet
    Project of the Month winner for April 2007
    Well, I think that can work out as well. BTW, change the preconfig of the Dask and Sneak button to nil. Most people are not using Mr. Mo's ABS. I'll move it now into the database then and you update the script ASAP. :)
    Get King of Booze for Android, for iOS, for OUYA or for Windows!
    Visit our website.
    You can also love/hate us on Facebook or the game itself.


    Get DropBox, the best free file syncing service there is!

    **
    Rep:
    Level 88
    Patriots all the way!!
    Well, my problem is not the scirpt its just that I dont know how to add or edit sprites  ^-^ Can someone help me with that or should I search it? (im jut lazy)
    Im to cool to have my own signature!!!

    **
    Rep:
    Level 87
    There's a button that looks like a folder with three pages infront of it.  It's between the database and the script editor buttons.  It's the materials button.  Click it and you can import and export graphics for customization.  The sprites are in the Characters folder.  I reccommend Paint.net and Adobe Photoshop CS2 for editing.  Graphics Gale is supposed to be good too but I don't have it. Paint.net and Graphics Gale are free. Google them.

    **
    Rep:
    Level 88
    Patriots all the way!!
    Oh, ok. Thank  ;D
    Im to cool to have my own signature!!!

    **
    Rep:
    Level 88
    Patriots all the way!!
    I made the sprites but they dont activate when I go on the water?
    Im to cool to have my own signature!!!

    **
    Rep:
    Level 87
    that's extremely odd. Are you getting an error? are your sprites named properly? (they must be named in YourName_whatever format not just _swim or _Swim or _swims or Yournameswim) are they in the characters folder? (I personally mess that up a lot and dump them in the animations folder and get really mad about why it's not working lmho)

    EDIT: Another thing I forget, is to set the actor graphic to your new sprite (in the database under actors).  Did ya do that?
    « Last Edit: February 28, 2007, 06:03:38 PM by toriverly »