Poulet Lv.1
Age : 29 Inscrit le : 25/01/2011 Messages : 7
| Sujet: [VX] Jour et Nuit Mer 26 Jan 2011 - 11:47 | |
| Bonjour ; Je viens de trouver un scripte pour jour et nuit - Code:
-
#_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_ #_/ ? Day-to-Night Phases - KGC_DayNight ? VX ? #_/ ? Last update : 2008/03/08 ? #_/ ? Translated by Mr. Anonymous ? #_/----------------------------------------------------------------------------- #_/ This script adds the concept of Day-to-Night phase shifting to your game. #_/ Events that only occur during certain phase shifts, such as night, can #_/ be created as well. #_/============================================================================= #_/ Note: The event command "Tint Screen" doesn't function normally while this #_/ script is running a phase shift. To use the Tint Screen function properly, #_/ please refer to the directions. #_/============================================================================= #_/ Installation: Insert above Main. #_/----------------------------------------------------------------------------- #_/ Terminology: Phase refers to the current state of the day, such as "Noon". #_/ ? Instructions For Usage ? #_/ #_/ ? Stop Day-to-Night ? #_/ When [DN_STOP] is inserted into a Map's name (after its given name), the #_/ Day-to-Night change stops, the timer does not stop however, and if a phase #_/ is currently active, such as "Night", the tint remains on the map. #_/ #_/ ? Stop Day-to-Night and Time, Cancel Phase ? #_/ #_/ When [DN_VOID] is inserted into a Map's name (after its given name), the #_/ Day-to-Night change stops, the timer is effectively frozen, and if a phase #_/ is currently active, such as "Night", the tint is reverted back to normal. #_/ #_/ ? Phase-Specific Encounters ? #_/ #_/ When [DN Phase#](Where Phase# refers to the phase. 0 = Noon, 1 = Evening, #_/ 2 = Night, 3 = Morning) is inserted into a specified Troop's "Notes" box #_/ in the Troops tab of the database, the specified Troop will only appear #_/ under those conditions. #_/ #_/ ? Event Script Functions ? #_/ The following commands are available using the "Script" item in events. #_/ #_/ * stop_daynight #_/ Day to Night change is stopped. #_/ #_/ * start_daynight #_/ Day to Night change is started. #_/ #_/ * get_daynight_name #_/ Name of present phase is acquired. This function only works in other #_/ scripts. #_/ #_/ * get_daynight_week (variable_id) #_/ Appoints the day of the week to the given variable. #_/ #_/ * get_daynight_week_name #_/ Name of the present day is aquired. This function only works in other #_/ scripts. #_/ #_/ * change_daynight_phase(phase, duration, pass_days) #_/ Changes the current phase to a new one. Handy for Inns and the like. #_/ Example: change_daynight_phase (3, 1, 1) #_/ This would make one day pass, change the phase to morning, with a #_/ duration of one frame. Duration must be set to a minimum of 1. #_/ #_/ * transit_daynight_phase(duration) #_/ Forces the phase to change at the very moment you call this. #_/ This appears to be bugged. No matter how I've called it, I get errors. #_/ #_/ * set_daynight_default(duration) #_/ Forces the tint of the current phase to reset to the initial phase. #_/ #_/ * restore_daynight_phase(duration) #_/ Forces the tint of the current phase to reset to its normal tint. #_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_
#==============================================================================# # ? Customization ? # #==============================================================================#
module KGC module DayNight # ? Day to Night Switch Method ? # 0. Time Lapse 1.Time passes with number of steps 2.Real Time METHOD = 2
# ? Phase Variable ? # The present phase (of day and night) is stored here. PHASE_VARIABLE = 11
# ? Passing Days Storage Variable ? # The passing days is stored here. PASS_DAYS_VARIABLE = 12
# ? Stop On Event Toggle ? # Stops the Day/Night Timer when an event is run by player. STOP_ON_EVENT = false
# ? Phases During Combat ? # true = Only the battleback is tinted. # false = Battleback and enemies are tinted. TONE_BACK_ONLY_IN_BATTLE = true
# ? Setting Individual Phases ? # Each phase makes use of the Tint Screen function. The format as follows: # ["Name", the color tone(Tint), time switch], # # [Name] # Name of Phase # *The name holds no significance. # [Tint] # The color tone of the entire screen. # Please don't alter this if you don't grasp color tints. # [Time Shift] # The amount of steps taken until the next phase shift occurs. # The following set up is for step-time change. (METHOD = 1) PHASE = [ ["Noon", Tone.new( 0, 0, 0), 300], # Phase 0 ["Evening", Tone.new( -32, -96, -96), 100], # Phase 1 ["Night", Tone.new(-128, -128, -32), 250], # Phase 2 ["Morning", Tone.new( -48, -48, -16), 100], # Phase 3 ]
# ? Real Time Setup ? # Replace the values in the about phase set-up if you wish to use real-time. # ["Noon", Tone.new( 0, 0, 0), 16], #Phase0 (16 o'clock [4:00PM]) # ["Evening", Tone.new( 0, -96, -96), 20], #Phase1 (20 o'clock [8:00PM]) # [ "Night", Tone.new(-96, -96, -64), 6], #Phase2 (6 o'clock [6:00AM]) # ["Morning", Tone.new(-48, -48, -16), 10], #Phase3 (10 o'clock [10:00AM])
# ? Day Change ? # The day changes on the value set here. # 0.Day 1.Evening 2.Night 3.Morning PASS_DAY_PHASE = 3
# ? Fade Time (by frame) ? # The amount of frames it takes to fade into the next phase. PHASE_DURATION = 60
# ? Day of the Week Names ? # This shouldn't be hard to figure out, I hope. # When using the Real-Time method (= 2), this must be seven days. # Values of these are 0, 1, 2, 3, 4, 5, 6 WEEK_NAME = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"] end end
#------------------------------------------------------------------------------#
$imported = {} if $imported == nil $imported["DayNight"] = true
if $data_mapinfos == nil $data_mapinfos = load_data("Data/MapInfos.rvdata") end
# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * # # Unless you know what you're doing, it's best not to alter anything beyond # # this point, as this only affects the tags used for the Map name. # # * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * #
module KGC::DayNight METHOD_TIME = 0 # Time Lapse METHOD_STEP = 1 # Time passes with number of steps METHOD_RTIME = 2 # Real Time
# Whatever word(s) in the following lines are what are used to determine # what is searched for in the Map Name or the "Notes" section of the database.
# Regular Expression Defined module Regexp # Base MapInfo Module module MapInfo # Day/Night Stop tag string DAYNIGHT_STOP = /\[DN_STOP\]/i # Day/Night Void tag string DAYNIGHT_VOID = /\[DN_VOID\]/i end
# Base Troop Module module Troop # Appearance Phase tag string APPEAR_PHASE = /\[DN((?:[ ]*[\-]?\d+(?:[ ]*,)?)+)\]/i end end
#-------------------------------------------------------------------------- # ? ????????? # troop : ?????????? # phase : ???????? #-------------------------------------------------------------------------- def self.troop_appear?(troop, phase = $game_system.daynight_phase) # ???? unless troop.appear_daynight_phase.empty? return false unless troop.appear_daynight_phase.include?(phase) end # ????? unless troop.nonappear_daynight_phase.empty? return false if troop.nonappear_daynight_phase.include?(phase) end
return true end end
#???????????????????????????????????????
#============================================================================== # ? KGC::Commands #==============================================================================
module KGC::Commands module_function #-------------------------------------------------------------------------- # ? ????????? #-------------------------------------------------------------------------- def stop_daynight $game_system.daynight_change_enabled = false end #-------------------------------------------------------------------------- # ? ????????? #-------------------------------------------------------------------------- def start_daynight $game_system.daynight_change_enabled = true end #-------------------------------------------------------------------------- # ? Preset Phase is aquired. #-------------------------------------------------------------------------- def get_daynight_name return KGC::DayNight::PHASE[get_daynight_phase][0] end #-------------------------------------------------------------------------- # ? Obtain DayNight Week and store it in a variable. # variable_id : Variable ID #-------------------------------------------------------------------------- def get_daynight_week(variable_id = 0) if KGC::DayNight::METHOD == KGC::DayNight::METHOD_RTIME week = Time.now.wday else days = $game_variables[KGC::DayNight::PASS_DAYS_VARIABLE] week = (days % KGC::DayNight::WEEK_NAME.size) end
if variable_id > 0 $game_variables[variable_id] = week end return week end #-------------------------------------------------------------------------- # ? Present Day of the Week is aquired. #-------------------------------------------------------------------------- def get_daynight_week_name return KGC::DayNight::WEEK_NAME[get_daynight_week] end #-------------------------------------------------------------------------- # ? Phase Shift # phase : Phase # duration : Shift Time(In Frames) # pass_days : Passing Days (When argument is omitted: 0) #-------------------------------------------------------------------------- def change_daynight_phase(phase, duration = KGC::DayNight::PHASE_DURATION, pass_days = 0) $game_temp.manual_daynight_duration = duration $game_system.daynight_counter = 0 $game_system.daynight_phase = phase $game_variables[KGC::DayNight::PASS_DAYS_VARIABLE] += pass_days $game_map.need_refresh = true end #-------------------------------------------------------------------------- # ? Transit Daynight Phase # duration : Shift Time(In Frames) #-------------------------------------------------------------------------- def transit_daynight_phase(duration = KGC::DayNight::PHASE_DURATION) $game_screen.transit_daynight_phase(duration) $game_map.need_refresh = true end #-------------------------------------------------------------------------- # ? ??????????? # duration : ??????(????) #-------------------------------------------------------------------------- def set_daynight_default(duration = KGC::DayNight::PHASE_DURATION) $game_screen.set_daynight_default(duration) $game_map.need_refresh = true end #-------------------------------------------------------------------------- # ? ?????????? # duration : ??????(????) #-------------------------------------------------------------------------- def restore_daynight_phase(duration = KGC::DayNight::PHASE_DURATION) $game_screen.restore_daynight_phase(duration) $game_map.need_refresh = true end end
class Game_Interpreter include KGC::Commands end
#???????????????????????????????????????
#============================================================================== # ¦ RPG::MapInfo #==============================================================================
class RPG::MapInfo #-------------------------------------------------------------------------- # ? ?????? #-------------------------------------------------------------------------- def name return @name.gsub(/\[.*\]/) { "" } end #-------------------------------------------------------------------------- # ? ??????????? #-------------------------------------------------------------------------- def original_name return @name end #-------------------------------------------------------------------------- # ? ???????? #-------------------------------------------------------------------------- def daynight_stop return @name =~ KGC::DayNight::Regexp::MapInfo::DAYNIGHT_STOP end #-------------------------------------------------------------------------- # ? ????????? #-------------------------------------------------------------------------- def daynight_void return @name =~ KGC::DayNight::Regexp::MapInfo::DAYNIGHT_VOID end end
#???????????????????????????????????????
#============================================================================== # ¦ RPG::Area #==============================================================================
unless $@ class RPG::Area #-------------------------------------------------------------------------- # ? ???????????? #-------------------------------------------------------------------------- alias encounter_list_KGC_DayNight encounter_list def encounter_list list = encounter_list_KGC_DayNight.clone
# ?????? list.each_index { |i| list[i] = nil unless KGC::DayNight.troop_appear?($data_troops[list[i]]) } return list.compact end end end
#???????????????????????????????????????
#============================================================================== # ¦ RPG::Troop #==============================================================================
class RPG::Troop #-------------------------------------------------------------------------- # ? Generate DayNight Cache #-------------------------------------------------------------------------- def create_daynight_cache @__appear_daynight_phase = [] @__nonappear_daynight_phase = []
# ???????? if @name =~ KGC::DayNight::Regexp::Troop::APPEAR_PHASE $1.scan(/[\-]?\d+/).each { |num| phase = num.to_i if phase < 0 # ????? @__nonappear_daynight_phase << phase.abs else # ???? @__appear_daynight_phase << phase end } end end #-------------------------------------------------------------------------- # ? ???????? #-------------------------------------------------------------------------- def appear_daynight_phase create_daynight_cache if @__appear_daynight_phase == nil return @__appear_daynight_phase end #-------------------------------------------------------------------------- # ? ????????? #-------------------------------------------------------------------------- def nonappear_daynight_phase create_daynight_cache if @__nonappear_daynight_phase == nil return @__nonappear_daynight_phase end end
#???????????????????????????????????????
#============================================================================== # ¦ Game_Temp #==============================================================================
class Game_Temp #-------------------------------------------------------------------------- # ? ?????????? #-------------------------------------------------------------------------- attr_accessor :manual_daynight_duration # ??????????? #-------------------------------------------------------------------------- # ? ????????? #-------------------------------------------------------------------------- alias initialize_KGC_DayNight initialize def initialize initialize_KGC_DayNight
@manual_daynight_duration = nil end end
#???????????????????????????????????????
#============================================================================== # ¦ Game_System #==============================================================================
class Game_System #-------------------------------------------------------------------------- # ? ?????????? #-------------------------------------------------------------------------- attr_writer :daynight_counter # ?????????? attr_writer :daynight_change_enabled # ???????? #-------------------------------------------------------------------------- # ? ????????? #-------------------------------------------------------------------------- alias initialize_KGC_DayNight initialize def initialize initialize_KGC_DayNight
@daynight_counter = 0 @daynight_change_enabled = true end #-------------------------------------------------------------------------- # ? ????????????? #-------------------------------------------------------------------------- def daynight_counter @daynight_counter = 0 if @daynight_counter == nil return @daynight_counter end #-------------------------------------------------------------------------- # ? ?????????? #-------------------------------------------------------------------------- def daynight_phase return $game_variables[KGC::DayNight::PHASE_VARIABLE] end #-------------------------------------------------------------------------- # ? ?????????? #-------------------------------------------------------------------------- def daynight_phase=(value) $game_variables[KGC::DayNight::PHASE_VARIABLE] = value end #-------------------------------------------------------------------------- # ? ?????????????? #-------------------------------------------------------------------------- def daynight_change_enabled @daynight_change_enabled = 0 if @daynight_change_enabled == nil return @daynight_change_enabled end #-------------------------------------------------------------------------- # ? ?????? #-------------------------------------------------------------------------- def progress_daynight_phase self.daynight_phase += 1 if self.daynight_phase >= KGC::DayNight::PHASE.size self.daynight_phase = 0 end $game_map.need_refresh = true end #-------------------------------------------------------------------------- # ? ???????????????? #-------------------------------------------------------------------------- def daynight_phase_object return KGC::DayNight::PHASE[daynight_phase] end #-------------------------------------------------------------------------- # ? ???????????????? #-------------------------------------------------------------------------- def previous_daynight_phase_object return KGC::DayNight::PHASE[daynight_phase - 1] end end
#???????????????????????????????????????
#============================================================================== # ¦ Game_Screen #==============================================================================
class Game_Screen #-------------------------------------------------------------------------- # ? ?????????? #-------------------------------------------------------------------------- attr_reader :daynight_tone # ????? #-------------------------------------------------------------------------- # ? ??? #-------------------------------------------------------------------------- alias clear_KGC_DayNight clear def clear clear_KGC_DayNight
clear_daynight end #-------------------------------------------------------------------------- # ? ????????????? #-------------------------------------------------------------------------- def clear_daynight @default_tone = Tone.new(0, 0, 0)
# ?????????? @daynight_x = 0 @daynight_y = 0
# ?????????????? @frame_count = Graphics.frame_count @daynight_tone_duration = 0
apply_daynight end #-------------------------------------------------------------------------- # ? ???????? #-------------------------------------------------------------------------- def apply_daynight return if $game_map == nil
# ???????????????? if $game_map.daynight_void? if @daynight_tone_changed # ???????? @tone = @default_tone.clone @daynight_tone_changed = false end @daynight_tone = @tone.clone return end
# ????????????? if $game_system.daynight_phase_object == nil $game_system.daynight_phase = 0 end
# ???????? @tone = $game_system.daynight_phase_object[1].clone @daynight_tone = @tone.clone
# ????????? if KGC::DayNight::METHOD == KGC::DayNight::METHOD_RTIME time = Time.now # ???????????? KGC::DayNight::PHASE.each_with_index { |phase, i| if phase[2] <= time.hour start_tone_change(phase[1], 1) $game_system.daynight_phase = i break end } end
@daynight_tone_changed = true end #-------------------------------------------------------------------------- # ? ????? #-------------------------------------------------------------------------- def tone if $game_temp.in_battle && KGC::DayNight::TONE_BACK_ONLY_IN_BATTLE return @default_tone else return @tone end end #-------------------------------------------------------------------------- # ? ??????? # tone : ?? # duration : ?? #-------------------------------------------------------------------------- alias start_tone_change_KGC_DayNight start_tone_change def start_tone_change(tone, duration) duration = [duration, 1].max start_tone_change_KGC_DayNight(tone, duration)
@daynight_tone_target = tone.clone @daynight_tone_duration = duration end #-------------------------------------------------------------------------- # ? ?????? #-------------------------------------------------------------------------- alias update_KGC_DayNight update def update update_KGC_DayNight
update_daynight_transit end #-------------------------------------------------------------------------- # ? ????? #-------------------------------------------------------------------------- alias update_tone_KGC_DayNight update_tone def update_tone update_tone_KGC_DayNight
if @daynight_tone_duration >= 1 d = @daynight_tone_duration target = @daynight_tone_target @daynight_tone.red = (@daynight_tone.red * (d - 1) + target.red) / d @daynight_tone.green = (@daynight_tone.green * (d - 1) + target.green) / d @daynight_tone.blue = (@daynight_tone.blue * (d - 1) + target.blue) / d @daynight_tone.gray = (@daynight_tone.gray * (d - 1) + target.gray) / d @daynight_tone_duration -= 1 end end #-------------------------------------------------------------------------- # ? ????????? #-------------------------------------------------------------------------- def update_daynight_transit # ????????????? if $game_temp.manual_daynight_duration start_tone_change($game_system.daynight_phase_object[1], $game_temp.manual_daynight_duration) $game_temp.manual_daynight_duration = nil @daynight_tone_changed = true end
return unless $game_system.daynight_change_enabled # ????? return if $game_map.daynight_stop? # ???
if KGC::DayNight::STOP_ON_EVENT interpreter = ($game_temp.in_battle ? $game_troop.interpreter : $game_map.interpreter) return if interpreter.running? # ??????? end
case KGC::DayNight::METHOD when KGC::DayNight::METHOD_TIME # ?? update_daynight_pass_time when KGC::DayNight::METHOD_STEP # ?? update_daynight_step when KGC::DayNight::METHOD_RTIME # ???? update_daynight_real_time end end #-------------------------------------------------------------------------- # ? ?? : ???? #-------------------------------------------------------------------------- def update_daynight_pass_time # ????????? inc_count = Graphics.frame_count - @frame_count # ????????????? if inc_count >= 100 @frame_count = Graphics.frame_count return end # ?????? $game_system.daynight_counter += inc_count @frame_count = Graphics.frame_count
# ?????? count = $game_system.daynight_counter / Graphics.frame_rate if count >= $game_system.daynight_phase_object[2] transit_daynight_next end end #-------------------------------------------------------------------------- # ? ?? : ?? #-------------------------------------------------------------------------- def update_daynight_step # ??????????? return if @daynight_x == $game_player.x && @daynight_y == $game_player.y
@daynight_x = $game_player.x @daynight_y = $game_player.y # ?????? $game_system.daynight_counter += 1 # ?????? count = $game_system.daynight_counter if count >= $game_system.daynight_phase_object[2] transit_daynight_next end end #-------------------------------------------------------------------------- # ? ?? : ???? #-------------------------------------------------------------------------- def update_daynight_real_time time = Time.now # ?????? time1 = $game_system.daynight_phase_object[2] transit = (time1 <= time.hour) if $game_system.previous_daynight_phase_object != nil time2 = $game_system.previous_daynight_phase_object[2] if time1 < time2 transit &= (time.hour < time2) end end
if transit transit_daynight_next end end #-------------------------------------------------------------------------- # ? ??????? # duration : ???? #-------------------------------------------------------------------------- def transit_daynight_next(duration = KGC::DayNight::PHASE_DURATION) $game_system.daynight_counter = 0 $game_system.progress_daynight_phase # ?????? if $game_system.daynight_phase == KGC::DayNight::PASS_DAY_PHASE $game_variables[KGC::DayNight::PASS_DAYS_VARIABLE] += 1 end # ?????? start_tone_change($game_system.daynight_phase_object[1], duration) @daynight_tone_changed = true end #-------------------------------------------------------------------------- # ? ????????(0, 0, 0)??? # duration : ???? #-------------------------------------------------------------------------- def set_daynight_default(duration) start_tone_change(@default_tone, duration) end #-------------------------------------------------------------------------- # ? ?????????? # duration : ???? #-------------------------------------------------------------------------- def restore_daynight_phase(duration) start_tone_change($game_system.daynight_phase_object[1], duration) @daynight_tone_changed = true end end
#???????????????????????????????????????
#============================================================================== # ¦ Game_Map #==============================================================================
class Game_Map #-------------------------------------------------------------------------- # ? ?????? # map_id : ??? ID #-------------------------------------------------------------------------- alias setup_KGC_DayNight setup def setup(map_id) setup_KGC_DayNight(map_id)
@screen.apply_daynight end #-------------------------------------------------------------------------- # ? ???????????? #-------------------------------------------------------------------------- def daynight_stop? info = $data_mapinfos[map_id] return false if info == nil return (info.daynight_stop || info.daynight_void) end #-------------------------------------------------------------------------- # ? ?????????? #-------------------------------------------------------------------------- def daynight_void? info = $data_mapinfos[map_id] return false if info == nil return info.daynight_void end #-------------------------------------------------------------------------- # ? ???????????? #-------------------------------------------------------------------------- alias encounter_list_KGC_DayNight encounter_list def encounter_list list = encounter_list_KGC_DayNight.clone
# ?????? list.each_index { |i| list[i] = nil unless KGC::DayNight.troop_appear?($data_troops[list[i]]) } return list.compact end end
#???????????????????????????????????????
#============================================================================== # ¦ Spriteset_Battle #==============================================================================
if KGC::DayNight::TONE_BACK_ONLY_IN_BATTLE class Spriteset_Battle #-------------------------------------------------------------------------- # ? ?????????????? #-------------------------------------------------------------------------- alias create_battleback_KGC_DayNight create_battleback def create_battleback create_battleback_KGC_DayNight
if @battleback_sprite.wave_amp == 0 @battleback_sprite.tone = $game_troop.screen.daynight_tone end end #-------------------------------------------------------------------------- # ? ?????????????? #-------------------------------------------------------------------------- alias create_battlefloor_KGC_DayNight create_battlefloor def create_battlefloor create_battlefloor_KGC_DayNight
@battlefloor_sprite.tone = $game_troop.screen.daynight_tone end end end
#???????????????????????????????????????
#============================================================================== # ¦ Scene_Map #==============================================================================
class Scene_Map < Scene_Base #-------------------------------------------------------------------------- # ? ???? #-------------------------------------------------------------------------- alias start_KGC_DayNight start def start $game_map.screen.clear_daynight
start_KGC_DayNight end end
#_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_ #_/ The original untranslated version of this script can be found here: # #_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_ |
|
Age : 134 Inscrit le : 14/04/2009 Messages : 1321
| Sujet: Re: [VX] Jour et Nuit Mer 26 Jan 2011 - 13:45 | |
| Cool. Mais, là tu postes pour poster ... Tu nous balances un script sans aucune explications, et les commentaires dans celui-ci sont en Anglais. Sacré aide ... De plus, des scripts du même type sont déjà présent sur le forum, ainsi que des systèmes en event, alors ...
Artyflash |
|