#===========================
# VX Weather Script
# by Ccoa / Jan 15 2008
#===========================
# Weather Types:
# 1 - rain
# 2 - storm
# 3 - snow
# 4 - hail
# 5 - rain with thunder and lightning
# 6 - falling leaves (autumn)
# 7 - blowing leaves (autumn)
# 8 - swirling leaves (autumn)
# 9 - falling leaves (green)
# 10 - cherry blossom (sakura) petals
# 11 - rose petals
# 12 - feathers
# 13 - blood rain
# 14 - sparkles
# 15 - user defined
#
# Weather Power:
# An integer from 0-40. 0 = no weather, 40 = 400 sprites
#
# Usage:
# Create a call script with the following:
# $game_screen.weather(type, power, hue)
#
# Usage of user-defined weather:
# Look at the following globals:
$WEATHER_UPDATE = false # the $WEATHER_IMAGES array has changed, please update
$WEATHER_IMAGES = [] # the array of picture names to use
$WEATHER_X = 0 # the number of pixels the image should move horizontally (positive = right, negative = left)
$WEATHER_Y = 0 # the number of pizels the image should move vertically (positive = down, negative = up)
$WEATHER_FADE = 0 # how much the image should fade each update (0 = no fade, 255 = fade instantly)
$WEATHER_ANIMATED = false # whether or not the image should cycle through all the images
# take these out if you are using my screen resolution script!
HEIGHT = 416
WIDTH = 544
#==============================================================================
# ** Spriteset_Weather
#------------------------------------------------------------------------------
# Weather effect (rain, storm, snow) class. This class is used within the
# Spriteset_Map class.
#==============================================================================
for i in 1..500
sprite = Sprite.new(viewport)
sprite.visible = false
sprite.opacity = 0
@sprites.push(sprite)
@current_pose.push(0)
@info.push(rand(50))
@countarray.push(rand(15))
end
end
#--------------------------------------------------------------------------
# * Dispose
#--------------------------------------------------------------------------
def dispose
for sprite in @sprites
sprite.dispose
end
@rain_bitmap.dispose
@storm_bitmap.dispose
@snow_bitmap.dispose
@hail_bitmap.dispose
@petal_bitmap.dispose
@blood_rain_bitmap.dispose
for image in @autumn_leaf_bitmaps
image.dispose
end
for image in @green_leaf_bitmaps
image.dispose
end
for image in @rose_bitmaps
image.dispose
end
for image in @feather_bitmaps
image.dispose
end
for image in @sparkle_bitmaps
image.dispose
end
for image in @user_bitmaps
image.dispose
end
$WEATHER_UPDATE = true
end
#--------------------------------------------------------------------------
# * Set weather type
# type : new weather type
#--------------------------------------------------------------------------
def type=(type)
return if @type == type
@type = type
case @type
when 1
bitmap = @rain_bitmap
when 2
bitmap = @storm_bitmap
when 3
bitmap = @snow_bitmap
when 4 # hail
bitmap = @hail_bitmap
when 5 # rain w/ thunder and lightning
bitmap = @rain_bitmap
@thunder = true
when 6 # falling autumn leaves
bitmap = @autumn_leaf_bitmaps[0]
when 7 # blowing autumn leaves
bitmap = @autumn_leaf_bitmaps[0]
when 8 # swirling autumn leaves
bitmap = @autumn_leaf_bitmaps[0]
when 9 # falling green leaves
bitmap = @green_leaf_bitmaps[0]
when 10 # sakura petals
bitmap = @petal_bitmap
when 11 # rose petals
bitmap = @rose_bitmaps[0]
when 12 # feathers
bitmap = @feather_bitmaps[0]
when 13 # blood rain
bitmap = @blood_rain_bitmap
when 14 # sparkles
bitmap = @sparkle_bitmaps[0]
when 15 # user-defined
bitmap = @user_bitmaps[rand(@user_bitmaps.size)]
when 16 # blowing snow
bitmap = @snow_bitmap
when 17 # meteors
bitmap = @meteor_bitmap
when 18 # falling ash
bitmap = @ash_bitmaps[rand(@ash_bitmaps.size)]
when 19 # bubbles
bitmap = @bubble_bitmaps[rand(@bubble_bitmaps.size)]
when 21 # sparkles up
bitmap = @sparkle_bitmaps[0]
else
bitmap = nil
end
if @type != 5
@thunder = false
end
for i in 0...@sprites.size
sprite = @sprites[i]
sprite.visible = (i <= @max)
if @type == 19
sprite.bitmap = @bubble_bitmaps[rand(@bubble_bitmaps.size)]
elsif @type == 20
sprite.bitmap = @bubble2_bitmaps[rand(@bubble2_bitmaps.size)]
elsif @type == 3
r = rand(@snow_bitmaps.size)
@info[i] = r
sprite.bitmap = @snow_bitmaps[r]
else
sprite.bitmap = bitmap
end
end
end
#--------------------------------------------------------------------------
# * Set starting point X coordinate
# ox : starting point X coordinate
#--------------------------------------------------------------------------
def ox=(ox)
return if @ox == ox;
@ox = ox
for sprite in @sprites
sprite.ox = @ox
end
end
#--------------------------------------------------------------------------
# * Set starting point Y coordinate
# oy : starting point Y coordinate
#--------------------------------------------------------------------------
def oy=(oy)
return if @oy == oy;
@oy = oy
for sprite in @sprites
sprite.oy = @oy
end
end
#--------------------------------------------------------------------------
# * Set maximum number of sprites
# max : maximum number of sprites
#--------------------------------------------------------------------------
def max=(max)
return if @max == max;
@max = [[max, 0].max, 40].min
for i in 1..40
sprite = @sprites[i]
sprite.visible = (i <= @max) if sprite != nil
if @type == 19
sprite.bitmap = @bubble_bitmaps[rand(@bubble_bitmaps.size)]
elsif @type == 20
sprite.bitmap = @bubble2_bitmaps[rand(@bubble2_bitmaps.size)]
elsif @type == 3
r = rand(@snow_bitmaps.size)
@info[i] = r
sprite.bitmap = @snow_bitmaps[r]
end
end
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
return if @type == 0
for i in 1..@max
sprite = @sprites[i]
if @type == 1 or @type == 5 or @type == 13 # rain
if sprite.opacity <= 150
if @current_pose[i] == 0
sprite.y += @rain_bitmap.height
sprite.x -= @rain_bitmap.width
if @type == 1 or @type == 5
sprite.bitmap = @rain_splash
else
sprite.bitmap = @blood_rain_splash
end
@current_pose[i] = 1
end
else
if @current_pose[i] == 1
if @type == 1 or @type == 5
sprite.bitmap = @rain_bitmap
else
sprite.bitmap = @blood_rain_bitmap
end
@current_pose[i] = 0
end
sprite.x -= 2
sprite.y += 16
if @thunder and (rand(8000 - @max) == 0)
$game_map.screen.start_flash(Color.new(255, 255, 255, 255), 5)
Audio.se_play("Audio/SE/Thunder1")
end
end
sprite.opacity -= 8
end
if @type == 2 # storm
sprite.x -= 8
sprite.y += 16
sprite.opacity -= 12
end
if @type == 3 # snow
case @info[i]
when 0 # smallest flake, fall the slowest
sprite.y += 1
when 1
sprite.y += 3
when 2
sprite.y += 5
when 3
sprite.y += 7
end
sprite.opacity -= 3
end
if @type == 4 # hail
sprite.x -= 1
sprite.y += 18
sprite.opacity -= 15
end
if @type == 6 # falling autumn leaves
@count = rand(20)
if @count == 0
sprite.bitmap = @autumn_leaf_bitmaps[@current_pose[i]]
@current_pose[i] = (@current_pose[i] + 1) % @autumn_leaf_bitmaps.size
end
sprite.x -= 1
sprite.y += 1
end
if @type == 7 # blowing autumn leaves
@count = rand(20)
if @count == 0
sprite.bitmap = @autumn_leaf_bitmaps[@current_pose[i]]
@current_pose[i] = (@current_pose[i] + 1) % @autumn_leaf_bitmaps.size
end
sprite.x -= 10
sprite.y += (rand(4) - 2)
end
if @type == 8 # swirling autumn leaves
@count = rand(20)
if @count == 0
sprite.bitmap = @autumn_leaf_bitmaps[@current_pose[i]]
@current_pose[i] = (@current_pose[i] + 1) % @autumn_leaf_bitmaps.size
end
if @info[i] != 0
if @info[i] >= 1 and @info[i] <= 10
sprite.x -= 3
sprite.y -= 1
elsif @info[i] >= 11 and @info[i] <= 16
sprite.x -= 1
sprite.y -= 2
elsif @info[i] >= 17 and @info[i] <= 20
sprite.y -= 3
elsif @info[i] >= 21 and @info[i] <= 30
sprite.y -= 2
sprite.x += 1
elsif @info[i] >= 31 and @info[i] <= 36
sprite.y -= 1
sprite.x += 3
elsif @info[i] >= 37 and @info[i] <= 40
sprite.x += 5
elsif @info[i] >= 41 and @info[i] <= 46
sprite.y += 1
sprite.x += 3
elsif @info[i] >= 47 and @info[i] <= 58
sprite.y += 2
sprite.x += 1
elsif @info[i] >= 59 and @info[i] <= 64
sprite.y += 3
elsif @info[i] >= 65 and @info[i] <= 70
sprite.x -= 1
sprite.y += 2
elsif @info[i] >= 71 and @info[i] <= 81
sprite.x -= 3
sprite.y += 1
elsif @info[i] >= 82 and @info[i] <= 87
sprite.x -= 5
end
@info[i] = (@info[i] + 1) % 88
else
if rand(200) == 0
@info[i] = 1
end
sprite.x -= 5
sprite.y += 1
end
end
if @type == 9 # falling green leaves
if @countarray[i] == 0
@current_pose[i] = (@current_pose[i] + 1) % @green_leaf_bitmaps.size
sprite.bitmap = @green_leaf_bitmaps[@current_pose[i]]
@countarray[i] = rand(15)
end
@countarray[i] = (@countarray[i] + 1) % 15
sprite.y += 1
end
if @type == 10 # sakura petals
if @info[i] < 25
sprite.x -= 1
else
sprite.x += 1
end
@info[i] = (@info[i] + 1) % 50
sprite.y += 1
end
if @type == 11 # rose petals
@count = rand(20)
if @count == 0
sprite.bitmap = @rose_bitmaps[@current_pose[i]]
@current_pose[i] = (@current_pose[i] + 1) % @rose_bitmaps.size
end
if @info[i] % 2 == 0
if @info[i] < 10
sprite.x -= 1
elsif
sprite.x += 1
end
end
sprite.y += 1
end
if @type == 12 # feathers
if @countarray[i] == 0
@current_pose[i] = (@current_pose[i] + 1) % @feather_bitmaps.size
sprite.bitmap = @feather_bitmaps[@current_pose[i]]
end
@countarray[i] = (@countarray[i] + 1) % 15
if rand(100) == 0
sprite.x -= 1
end
if rand(100) == 0
sprite.y -= 1
end
if @info[i] < 50
if rand(2) == 0
sprite.x -= 1
else
sprite.y -= 1
end
else
if rand(2) == 0
sprite.x += 1
else
sprite.y += 1
end
end
@info[i] = (@info[i] + 1) % 100
end
if @type == 14 # sparkles
if @countarray[i] == 0
@current_pose[i] = (@current_pose[i] + 1) % @sparkle_bitmaps.size
sprite.bitmap = @sparkle_bitmaps[@current_pose[i]]
end
@countarray[i] = (@countarray[i] + 1) % 15
sprite.y += 1
sprite.opacity -= 1
end
if @type == 15 # user-defined
if $WEATHER_UPDATE
update_user_defined
$WEATHER_UPDATE = false
end
if $WEATHER_ANIMATED and @countarray[i] == 0
@current_pose[i] = (@current_pose[i] + 1) % @user_bitmaps.size
sprite.bitmap = @user_bitmaps[@current_pose[i]]
end
sprite.x += $WEATHER_X
sprite.y += $WEATHER_Y
sprite.opacity -= $WEATHER_FADE
end
if @type == 16 # blowing snow
sprite.x -= 10
sprite.y += 6
sprite.opacity -= 4
end
if @type == 17 # meteors
if @countarray[i] > 0
if rand(20) == 0
sprite.bitmap = @impact_bitmap
@countarray[i] = -5
else
sprite.x -= 6
sprite.y += 10
end
else
@countarray[i] += 1
if @countarray[i] == 0
sprite.bitmap = @meteor_bitmap
sprite.opacity = 0
@count_array = 1
end
end
end
if @type == 18 # ash
sprite.y += 2
case @countarray[i] % 3
when 0
sprite.x -= 1
when 1
sprite.x += 1
end
end
if @type == 19 or @type == 20 # bubbles
switch = rand(75) + rand(75) + 1
if @info[i] < switch / 2
sprite.x -= 1
else
sprite.x += 1
end
@info[i] = (@info[i] + 1) % switch
sprite.y -= 1
if switch % 2 == 0
sprite.opacity -= 1
end
end
if @type == 21 # sparkles up
if @countarray[i] == 0
@current_pose[i] = (@current_pose[i] + 1) % @sparkle_bitmaps.size
sprite.bitmap = @sparkle_bitmaps[@current_pose[i]]
end
@countarray[i] = (@countarray[i] + 1) % 15
sprite.y -= 1
sprite.opacity -= 1
end
x = sprite.x - @ox
y = sprite.y - @oy
if sprite.opacity < 64 or sprite.x > WIDTH or sprite.x < 0 or sprite.y > HEIGHT or sprite.y < 0
sprite.x = rand(800) - 100 + @ox
sprite.y = rand(600) - 200 + @oy
if [13, 14, 16, 5, 2, 1].include?(@type)
sprite.opacity = rand(100) + 155
else
sprite.opacity = 255
end
end
end
end
def update_user_defined
for image in @user_bitmaps
image.dispose
end
#user-defined bitmaps
for name in $WEATHER_IMAGES
@user_bitmaps.push(RPG::Cache.picture(name))
end
for sprite in @sprites
sprite.bitmap = @user_bitmaps[rand(@user_bitmaps.size)]
end
end
end
You can start and stop weather using the original event commands, however, you can start stronger and more varied weather using:
Code:
$game_screen.weather(type, strength, duration)
Where type is the type of weather (see above), strength is how strong it should be (a number between 1 and 50), and duration is how many frames it should take to transition in.
User-defined weather user images imported to the pictures folder. The controls are:
$WEATHER_UPDATE = false - change this one any time you're about to use user-defined weather
$WEATHER_IMAGES = [name, name, ...] - a list of the names of the images, separated by commas.
$WEATHER_X = 0 - the number of pixels the image should move horizontally (positive = right, negative = left)
$WEATHER_Y = 0 - the number of pizels the image should move vertically (positive = down, negative = up)
$WEATHER_FADE = 0 - how much the image should fade each update (0 = no fade, 255 = fade instantly)
$WEATHER_ANIMATED = true (or false) - whether or not each sprite in the weather should cycle between all the available images.
Editing speed if too fast
Anyway, if you look in the script, you'll see a section that looks like this:
Code:
if @type == 1 or @type == 5 or @type == 13 # rain
if sprite.opacity <= 150
if @current_pose[i] == 0
sprite.y += @rain_bitmap.height
sprite.x -= @rain_bitmap.width
if @type == 1 or @type == 5
sprite.bitmap = @rain_splash
else
sprite.bitmap = @blood_rain_splash
end
@current_pose[i] = 1
end
else
if @current_pose[i] == 1
if @type == 1 or @type == 5
sprite.bitmap = @rain_bitmap
else
sprite.bitmap = @blood_rain_bitmap
end
@current_pose[i] = 0
end
sprite.x -= 2
sprite.y += 16
if @thunder and (rand(8000 - @max) == 0)
$game_map.screen.start_flash(Color.new(255, 255, 255, 255), 5)
Audio.se_play("Audio/SE/Thunder1")
end
end
sprite.opacity -= 8
end
That controls how the rain falls. These two lines determin how fast it falls and how much it moves to the left as it falls.
Code:
sprite.x -= 2
sprite.y += 16
To slow it down, reduce the amount that is added to the y value each frame update by making the 16 a smaller number. If it's moving to fast to the left after that, try reducing the 2 to 1.
For the hail, this is the section of code you want (note that each is commented as the weather type):
Code:
if @type == 4 # hail
sprite.x -= 1
sprite.y += 18
sprite.opacity -= 15
end
Again, reduce the amount added to the y value to make it fall slower.
You might also want to reduce the amount that the opacity is lowered each frame by reducing the amount subtracted from the opacity (15 for the hail, 8 for the rain).
Same goes for any of the weather types, if you want to fiddle with the default settings for their movement, just make a backup copy of the script and play away.
Commercial License:
To use this in a commercial game, I only charge $10 for a single game license for this script. Just enough to make it legal, really. Whenever you're ready, contact me and I'll send you a copy of the license agreement for you to peruse.
W-w-wait a minute.
How does it work?
Do I just put it into the Script (starting a new script, just above Main) and it works? Or do I need something else, like download images?
You inserted a new script and pasted right? at the very bottom of the scripts? If the Game_Screen script is bellow then it will overwrite this script and make the game explode.