SwimmingVersion: 1.7IntroductionIt 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
TemplatesDiving Template: Edited from Mack's male
(https://rmrk.net/proxy.php?request=http%3A%2F%2Fi78.photobucket.com%2Falbums%2Fj92%2Fchastity_belted%2Fswimming%2520script%2520pics%2FTemplate_dive-1.png&hash=9464a9fa475367f5d8bd1b4011f908606b882e56)
It only needs 4 frames because it is only visible for a second.
Swimming Template: Again from Mack's male
(https://rmrk.net/proxy.php?request=http%3A%2F%2Fi78.photobucket.com%2Falbums%2Fj92%2Fchastity_belted%2Fswimming%2520script%2520pics%2FTemplate_swim.png&hash=a50673f030b94b366370426d45ad2ef53982985d)
ScreenshotsBefore
(https://rmrk.net/proxy.php?request=http%3A%2F%2Fi78.photobucket.com%2Falbums%2Fj92%2Fchastity_belted%2Fswimming%2520script%2520pics%2FSwim_Screenie1.png&hash=42f57d2576a5a15c8470ef1f06a4ea97dccbdd2a)
Diving (I thought I'd show off the side view :))
(https://rmrk.net/proxy.php?request=http%3A%2F%2Fi78.photobucket.com%2Falbums%2Fj92%2Fchastity_belted%2Fswimming%2520script%2520pics%2FSwim_Screenie2.png&hash=4bfbf3317e898fe4c7759dfadc46b5b00d7e5131)
In the water
(https://rmrk.net/proxy.php?request=http%3A%2F%2Fi78.photobucket.com%2Falbums%2Fj92%2Fchastity_belted%2Fswimming%2520script%2520pics%2FSwim_Screenie3.png&hash=b769c9fd23b43aaab2ece6778c2eb772bcded8c1)
Script[spoiler=Swimming Script][/list]
#==============================================================================#
# 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 :)
#------------------------------------------------------------------------------#
[/spoiler]
InstructionsSee Script
CompatibilityAccording 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:
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
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.
XD
That's funny but still..
I LOVE IT !!!
good job :D
Thanks!
but what's funny? lol
Sweet! ;8
Quote from: toriverly on February 26, 2007, 05:16:52 PM
Thanks!
but what's funny? lol
A swimming script is funny :)
Nice :D
I keep getting
????? 'swimming'? 28??? NameError????????
uninitialized constant Input::Letters
Never mind. Blizzard fixed it. ;D
well thats useful, nice job.
Quote from: Irockman1 on February 26, 2007, 07:03:49 PM
I keep getting
????? 'swimming'? 28??? NameError????????
uninitialized constant Input::Letters
I changed it to nil.
Nvm, I fixed it for him on AIM.
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?
Quote from: toriverly on February 26, 2007, 07:52:33 PM
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.
Awesome!!!! ;D I LOVE IT!!! I am adding this to my favorites.
This is very nice.
*Script databse* ?
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.
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 :'(
Quote from: toriverly on February 27, 2007, 01:48:46 PM
@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
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 ;)
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. :)
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.
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. :)
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)
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.
Oh, ok. Thank ;D
I made the sprites but they dont activate when I go on the water?
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?
What you mean add it to your character?
sweeeeetness! nice update.
Quote from: Valcos on February 28, 2007, 09:25:32 PM
What you mean add it to your character?
you know...tools>database>actors double click the picture and select a new one?
Oh, you got to make a whole new character?
I know that as soon as I make sense, you're gonna say "oh yeah I did that." but I must post this anyway for the sake of helping and being sure.
1. Go to the Database
(https://rmrk.net/proxy.php?request=http%3A%2F%2Fi78.photobucket.com%2Falbums%2Fj92%2Fchastity_belted%2Fdatabase.png&hash=143d21fdf77083de7103563cbef67eae2cc90dfe)
2. Click the 'Actors' tab
(https://rmrk.net/proxy.php?request=http%3A%2F%2Fi78.photobucket.com%2Falbums%2Fj92%2Fchastity_belted%2Fdatabase-actors.png&hash=a8988f2396d9cba346447b2858d4e3a84fec9cb1)
3. Select your actor ^^Aluxes is highlighted there
4. Double-click on the little sprite guy under 'Character Graphic'
(https://rmrk.net/proxy.php?request=http%3A%2F%2Fi78.photobucket.com%2Falbums%2Fj92%2Fchastity_belted%2Fcharactergraphic.png&hash=c4e6bea52676fa833c8b359e2862e0335fe60eec)
5. Select your new graphic
(https://rmrk.net/proxy.php?request=http%3A%2F%2Fi78.photobucket.com%2Falbums%2Fj92%2Fchastity_belted%2Fselectgraphic.png&hash=1c35572bf70f519cb5bd835ab8998ede682a1ea0)
Now, all the other ones (name_swim, name_dive...etc) will be imported with the 'Materials' editor thingy i told you about before into the characters file. They should work as long as they are named GraphicThatYouJustSet_SwimOrWhatever (ei. 001-Fighter01_swim if your graphic is 001-Fighter01)
Ok, I'll try out what you said.
fixed two bugs (nobody else noticed them but anyway they're fixed :P) check the updated post.
Update:
Now you can (or I should say can't) swim if you don't have a certain item, weapon or armor. I don't know why you'd need a weapon...maybe you have the magic water rod...w/e it's up to you!
I've also fixed my weird looking template.
I just tried the script and for some reason it just wont work. ???
Be specific: what won't work? Is there an error? Is it frozen?
Also, did you follow the instructions? Remember that tiles must have the terrain tag WATER and must be passable.
Theres an error and yes I did follow the instrucions.
Awesome script and very unique! Rep +
~Winged
Okay...so what is the error?
It comes up saying that it's unaccessable. If it makes any difference I use Postality Knights.
As long as you have all the necessary pictures, i don't see what could be inaccessable?
It's prolly because of PK...I don't know anything about it so I don't know how to fix that error...sorry!
I encountered a problem too in this part of the script.
# Drowning
def drown
$game_screen.start_flash(Color.new(255,0,0,128), 20)
if @drown_count <= 10
swim if !@swim
@drown_count += 1
elsif @drown_count >=10
@drown_count = 0
$scene = Scene_Gameover.new
end
end
On this line @drown_count += 1 I had to delete the plus sign for it to work.
Just putting that out there for people to try if they are having trouble.
That can't be right. If you put =1 it will never =10 and you'll never get gameover?
I don't know if you're a scripter but += 1 means "add one" it's not a typo. You should have a second or so while @drown_count reaches 10 and then you get a gameover.
What happened exactly before and after you removed the +?
@zzboy---I d/l PK to test, but I'm not getting an error? What did you set the constants to?
WATER = 1
SWIM_SWITCH = nil
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 = false
WATER_DASHING = false
DIVE_SOUND_OFF = false
DIVE_GRAPHIC = false
TREAD_ANI = true
#---------------------------
These, what did you set them to?
Yep.
Oh, woops. I was reading through the whole thing and
I think found out what i did wrong. I don't think I made another character. Although I don't quite get how to do that.
Alright - dumb question, I'm sure, by I don't want to alter the script in any way I'll regret later: How exactly can I make the characters swim faster? I'm fairly certain it's with these lines -
# 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
But I'm not sure what's defined as the 'Swim count' or if I want to change it.
well, if you want a constant faster speed, just do this:
# Determines Speed (Swim Leveling)
def get_speed
@swim_speed = 4 #or any number from 1-6. 3 is walking pace.
end
[spoiler=if you want the characters to learn faster:]
# Determines Speed (Swim Leveling)
def get_speed
# Gets Swim Count
@swim_count += 0.05 # change this 0.05 to a bigger number to make them level up
# faster. Remember, just putting 0.5 would be 10 times
# faster.
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
[/spoiler]
Although I don't have rmxp on this computer and I haven't scripted in ages, i'm fairly certain that should work.
enjoy :)
Alright... one major problem with this script I can see so far... I'm using a caterpillar script for my party, so among the two options of drowning on or off -
If drowning is FALSE, then every time a character tries to go onto a water panel (and by the script, is immediately pushed one step backwards), the party member behind him goes onto the space where the leader just was - so you have the leader of the party unable to go into the water, yes, but all the other members are standing there on the water.
If drowning is TRUE, there are two concerns - every time you walk on a bridge over water or anything, the screen flashes red as if you were about to drown. Aside from that, if the water is only one panel wide and the character walks into it, the screen flashes red and the character jumps forward two panels - OVER the water into an area that should be inaccessible, at least for the time being. ;/
Sorry about the caterpillar script, I don't get how they work at all *scripting noob here* I haven't had a lot of time recently in fact I have a math exam in a couple of hours and history tomorrow -_-
Anyway, the bridge is about terrain tags. If a terrain tag is 0, the scripts reading them just phase through it and it will behave like the one under it. It should work if you set it to 2 or w/e is not water or 0. I can't remember if it's supposed to be a higher # than water though.
Alright, thanks for the second one... but even if I did use the drowning now, they would still be jumping over 1-tile-wide streams of water.
Caterpillar script - these program it so that your party members trail behind you, or rather, they follow your exact move pattern one panel behind eachother. For example, Bob is the party leader and Joe is the second member in the party. If Bob tries to step onto a water panel, this script pushes him a step back, meaning that the last panel he was on - and coincidingly the one Joe is left on - is the water panel. So, you've got Bob unable to walk on the water, yes, but Joe is left there standing on top of it.
The only way I know could prevent this would be setting a tile as impassible based on its Terrain flag... but alas, I have no idea how or if this is possible. ;/
The script calls upon the terrain tag the player is already standing on. He won't jump until he's already on the water but it looks like he jumps into it. I suppose I can take another look at it some time, but I'm way too busy right now with exams and well life. There isn't really much point to swimming across a single tile anyway is there? You can always just use a second tile there with another terrain tag for "shallow water" and he'll walk over it. Anyway, I know what a caterpillar script is, but I don't know how to manipulate them.
... 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.
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=]#==============================================================================#
# 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 #
#------------------------------------------------------------------------------#
[/spoiler]
Alright.. what exactly should this update do? :P
shouldn't drown on a single water tile.
.. 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
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=This should work]#==============================================================================#
# 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 #
#------------------------------------------------------------------------------#
[/spoiler]
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
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.)
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:
# 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. :(
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?
Supposedly, you cant put @wait_count = whatever, but it doesn't seem to work for me so I do stuff like
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?
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.
can you give me a DEMO
nice script old, wish i wouldve found this earlier wouldve came in handy for my first game i made
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