Version: 0.1 beta. I want this tested, mostly.
Author: Alek, aka, jimmiejimmiecocopuff
Release date: March 25, oh-twelve
You know what? It's exclusive here. I don't visit any RM forums.
IntroductionThis is my first submission. Be gentle. I've been lurking these forums for, oh, about four years now, posting far and few between.
I jumped back in to RMVX and I remembered that I can program like a boss. So naturally, I decided "HEY I'LL MAKE A SCRIPT FOR SOMETHING."
This script is the lovechild of me and about four combined hours.
Before you post saying "herp derp there are other weather systems out there", I'm posting this because this is MY weather system. This is not anyone ELSE'S weather system. If you don't want to, you don't have to use it. If you do, more power to you.I made this script because I saw a lot of other scripts that said "WEATHER SYSTEM, USING SEASONS AND STUFF AND CURRENT TIME". That's all well and good, but... That's not what I wanted. The thing that concerned me most was that none of them used some sort of "regions", like northern areas will snow more and desert areas will have less rain and jungle areas will have more torrential downpours than clear weather. So here you go.
Based off of generating weather by region, rather than the time of the year.Features- All four weather types (rain, storm, snow, clear)
- Integrated with Kylock's Time System (required)
- Supports different user-defined "regions"
- Indoors and outdoors
I think that's it. Again, it's in beta.
ScriptCODE
=begin
Unlike most weather systems I've seen, this one does not operate on seasons from
some sort of time system. This one is just "Oh look, it's raining today."
It requires Kylock's Time System, available here:
http://www.rpgrevolution.com/forums/index.php?showtopic=13555
READ THIS:
In order to set a map to be "weather-available", you need to put [AWS] somewhere
in the map name.
Basic user settings start at line 112.
Advanced user settings start at line 134.
(Press Ctrl-G to go to those lines)
REGIONS:
If you want to set a specific region for the map to be in, instead of using just
[AWS] in the brackets, use this instead:
[AWS=region_name]
Where region_name is the type of region.
The default regions are:
normal - A region that experiences rain 26% of the time.
desert - A region that experiences rain 11% of the time.
tundra - A region that experiences rain 13% of the time and snow 25% of the time.
arctic - A region that experiences snow 50% of the time.
jungle - A region that experiences rain 50% of the time.
These are just examples, however. You can change them if you want below.
=end
module AWS
###################
# Weather regions #
###################
class AWS_region
attr_reader :name
attr_reader :clear_chance
attr_reader :rain_chance
attr_reader :storm_chance
attr_reader :snow_chance
# The different chances are relative.
# The chance that there will be clear weather is equal to
# rain_chance + snow_chance + storm_chance
def initialize(name, clear_chance, rain_chance, storm_chance, snow_chance, min_duration=1, max_duration=5)
@name = name
@rain_chance = rain_chance
@storm_chance = storm_chance
@snow_chance = snow_chance
@clear_chance = clear_chance
@min_duration = min_duration
@max_duration = max_duration
end
# Gets a random weather
def get_random_weather
total = @clear_chance + @snow_chance + @rain_chance + @storm_chance
rain_limit = @rain_chance
storm_limit = rain_limit + @storm_chance
snow_limit = storm_limit + @snow_chance
result = rand(total)
if result <= rain_limit && can_rain?
return 1
elsif result <= storm_limit && can_storm?
return 2
elsif result <= snow_limit && can_snow?
return 3
else
return 0
end
end
# generates a random number from min to max, both inclusive
def get_random_duration
result = @min_duration + rand(@max_duration - @min_duration + 1)
return result
end
def can_rain?
return @rain_chance > 0
end
def can_storm?
return @storm_chance > 0
end
def can_snow?
return @snow_chance > 0
end
end
# Weather IDs for easier reading
WEATHER_CLEAR = 0
WEATHER_RAINY = 1
WEATHER_STORM = 2
WEATHER_SNOWY = 3
# I totally didn't name those so that they would be the exact same width in
# the editor.
# ...okay, maybe.
# Weather names
WEATHER_NAMES = ["Clear", "Rainy", "Stormy", "Snowy"]
#######################
# Basic user settings #
#######################
# Set whether or not to use rain BGS when it rains.
# true for yes, false for no
USE_BGS = true
# Which variable to use (in-game)
WEATHER_VARIABLE = 81
# The number of seconds the weather takes to transition
TRANSITION_SECONDS = 5
##########################
# Advanced user settings #
##########################
# The weather regions.
# AWS_region.new(name, clear_chance, rain_chance, storm_chance, snow_chance, min_duration, max_duration)
# default values for min and max duration are 1 and 5, respectively
WEATHER_REGIONS = [
AWS_region.new("normal", 100, 50, 20, 0),
AWS_region.new("desert", 100, 30, 10, 0, 1, 3),
AWS_region.new("tundra", 100, 20, 0, 60, 1, 3),
AWS_region.new("arctic", 100, 0, 0, 100, 2, 6),
AWS_region.new("jungle", 100, 70, 70, 0, 2, 6)
]
# This time, it is definitely a coincidence that all of the region names are
# exactly the same length.
end
#################
# Weather class #
#################
class Alek_Weather
def initialize(target_seconds, weather_type)
@target_seconds = target_seconds
@weather_type = weather_type
@started = false
end
def is_done?
if $kts.get_total_seconds > @target_seconds
return true
else
return false
end
end
def target_seconds
return @target_seconds
end
def weather_type
return @weather_type
end
def started?
return @started
end
def start(v=true)
@started = v
end
end
######################
# The weather system #
######################
class Alek_Weather_System
def initialize
@current_weather = 0
@target_duration = 0
$aws_map_info = load_data("Data/MapInfos.rvdata")
@hold_bgs = false
# The list of weather
$aws_weathers = {}
end
# Updates the weather's state
def update
if $aws_map_info[$game_map.map_id].aws_weather?
map_id = $game_map.map_id
# check to see if the weather for the current map is registered
if $aws_weathers[map_id] == nil
$aws_weathers[map_id] = make_new_weather(map_id)
end
# check to see if the weather has expired yet
if $aws_weathers[map_id].is_done?
$aws_weathers[map_id] = make_new_weather(map_id)
update_weather
end
update_variables
update_weather
else
# otherwise, just update weather to NOT show
update_weather
end
end
# Updates the variables
def update_variables
$game_variables[AWS::WEATHER_VARIABLE] = $aws_weathers[$game_map.map_id].weather_type
end
# Updates the current weather in the map
def update_weather
map_id = $game_map.map_id
if $aws_map_info[map_id].aws_weather?
# Start the effect
if !$aws_weathers[map_id].started?
$game_map.screen.weather($aws_weathers[map_id].weather_type, 9, AWS::TRANSITION_SECONDS * 60)
$aws_weathers[map_id].start
end
# Start the BGS, if applicable
update_bgs
else
# Stop weather
$game_map.screen.weather(0, 0, 0)
Audio.bgs_fade(AWS::TRANSITION_SECONDS * 60)
end
end
def update_bgs
map_id = $game_map.map_id
if AWS::USE_BGS
if $aws_weathers[map_id].weather_type == 1 # rain
Audio.bgs_play("Audio/bgs/Rain", 70, 100)
elsif $aws_weathers[map_id].weather_type == 2 # storm
Audio.bgs_play("Audio/bgs/Storm", 70, 100)
else # none
Audio.bgs_fade(AWS::TRANSITION_SECONDS * 60)
end
end
if @hold_bgs
Audio.bgs_stop
end
end
def hold_bgs?
return @hold_bgs
end
def hold_bgs(v)
@hold_bgs = v
update_bgs
end
# make a new weather thing. Yeah, I'm tired.
def make_new_weather(map_id)
region = map_region(map_id)
weather = region.get_random_weather
duration = region.get_random_duration
target_seconds = $kts.get_total_seconds + (duration * 3600)
result = Alek_Weather.new(target_seconds, weather)
end
def map_region_name(map_id)
return $aws_map_info[map_id].aws_region
end
def current_map_region_name
return $aws_map_info[$game_map.map_id].aws_region
end
def map_region(map_id)
region_name = map_region_name(map_id)
for region in AWS::WEATHER_REGIONS
if region.name == region_name
return region
end
end
return AWS::WEATHER_REGIONS[0]
end
def current_map_region
region_name = current_map_region_name
for region in AWS::WEATHER_REGIONS
if region.name == region_name
return region
end
end
return AWS::WEATHER_REGIONS[0]
end
# Sets each weather's status to "not running" essentially
# It's called each time before a map is loaded.
def restart_weathers
$aws_weathers.each_pair do |map_id, weather|
weather.start(false)
end
end
#########################
# Functions for in-game #
#########################
def change_weather(weather_type, num_hours)
map_id = $game_map.map_id
if $aws_map_info[map_id].aws_weather?
target_time = $kts.get_total_seconds + (num_hours * 3600)
w = Alek_Weather.new(target_time, weather_type)
$aws_weathers.delete(map_id)
$aws_weathers[map_id] = w
end
end
# Gets the number of hours till the next weather occurrence
def hours_till_next
map_id = $game_map.map_id
if $aws_map_info[map_id].aws_weather?
target_seconds = $aws_weathers[map_id].target_seconds
current_time = $kts.get_total_seconds
hours = (target_seconds - current_time) / 3600
return hours
end
return -1
end
end
######################################
# Modify KTS (oh noes!) to our needs #
######################################
class Kylock_Time_System
def get_total_seconds
return @total_seconds
end
def hours_since_checkpoint(checkpoint)
result = @total_seconds / 3600
result -= checkpoint / 3600
return result
end
end
#########################################
# Scanning maps for which region to use #
#########################################
class RPG::MapInfo
def aws_weather?
if @name.scan(/\[AWS\]/).size > 0
return true
elsif @name.scan(/\[AWS=(\w+)\]/).size > 0
return true
end
return false
end
def aws_region
if @name.scan(/\[AWS=(\w+)\]/).size > 0
return @name.match(/\[AWS=(\w+)\]/)[1]
end
return ""
end
end
###########################################
# Set up weather as soon as map is loaded #
###########################################
class Game_Map
alias aws_setup setup
def setup(map_id)
aws_setup(map_id)
$aws.restart_weathers
$aws.update
end
end
###########################################
# Stopping the BGS when the battle starts #
###########################################
class Spriteset_Battle
alias aws_create_battleback create_battleback
def create_battleback
$aws.hold_bgs(true)
aws_create_battleback
end
alias aws_dispose_battleback dispose_battleback
def dispose_battleback
$aws.hold_bgs(false)
aws_dispose_battleback
end
end
######################################################
# Initializing the Alek Weather System at game start #
######################################################
class Game_System
# Initialize the Alek weather system
alias aws_initialize initialize
def initialize
aws_initialize
$aws = Alek_Weather_System.new
end
alias aws_update update
def update
aws_update
$aws.update
end
end
############################
# Loading and saving files #
############################
class Scene_File
alias aws_write_save_data write_save_data
def write_save_data(file)
aws_write_save_data(file)
Marshal.dump($aws, file)
end
alias aws_read_save_data read_save_data
def read_save_data(file)
aws_read_save_data(file)
$aws = Marshal.load(file)
end
end
CustomizationThere are some basic user settings and advanced user settings. I think that the basic ones are around line 112 and the advanced are right after that, line 126. If I'm wrong, they're close to there and clearly labelled.
Basic settingsUSE_BGS : whether or not the current weather will use a BGS (it is only used for the rain and storm weather types)
WEATHER_VARIABLE : where in the game variables the current weather will be stored. Default is 81.
TRANSITION_SECONDS : set how many seconds you want it to take for weather to change, and for BGS to fade out
Advanced settingsWEATHER_REGIONS : all of the defined weather regions. You can change them if you want. YOU MUST HAVE AT LEAST ONE.
CompatabilityTHIS SCRIPT REQUIRES KYLOCK'S TIME SYSTEM
THIS SCRIPT REQUIRES KYLOCK'S TIME SYSTEM
THIS SCRIPT REQUIRES KYLOCK'S TIME SYSTEM
THIS SCRIPT REQUIRES KYLOCK'S TIME SYSTEM
THIS SCRIPT REQUIRES KYLOCK'S TIME SYSTEMIt ties in a LOT with it. It's included with the demo game.
http://www.rpgrevolution.com/forums/index....showtopic=13555DemoDownload here:
http://www.mediafire.com/download.php?pjf0akzl29c2nrbInstallationJust grab the script and plop in its own section.
Use [AWS] in the name, or use [AWS=regionname]
FAQNone yet. Ask me the same question over and over and I'll add it here. Here's a few answers to clear up the more complicated parts.
Q: How do I make a new region?
A: What a handsome question. Scroll down to the part where it says "WEATHER_REGIONS = [". Just add a comma and a new line after the last region, and then add "AWS_region.new("region_name", clear_chance, rain_chance, storm_chance, snow_chance, min_time, max_time)"
Q: What do the chances mean?
A: The "chance" a type of weather will occur is like putting marbles in a bag. You put 100 clear weathers in the bag, 50 rain weathers in the bag, and 20 storm weathers in the bag. Draw one out, what do you get?
CreditsI, Alek, made this script. You didn't.
So there.
Terms and conditionsJust... don't go around blatantly plagiarizing this. I put a long and hard few hours in to this so that the community could enjoy it and benefit from it. Just remember that I made this script.
If you're making a "for-serious" game, I'm not going to require that you put me in the credits. I hate it when people require that.