The RPG Maker Resource Kit

RMRK RPG Maker Creation => RPG Maker General => General Scripting => Topic started by: Jakexxx on February 25, 2006, 08:00:30 PM

Title: A question...
Post by: Jakexxx on February 25, 2006, 08:00:30 PM
I'm no good at scripting what so ever, so I'm using Near_Frantastica's day and night script. The part I labled game_time, is this... #=======================================#
# â–  class Game_Title                   #
#    Written by Deke                    #
#    Rewritten by Near_Fantastica       #
#    Clock Added by Prexus              #
#---------------------------------------#
#=======================================#

# Search CLOCK PARAMETERS to adjust the size of the clock. Just change the
# height and width and the whole thing will adjust accordingly :)
#
# Search -Change File Name Here- without the - to change the background of the clock.

class Game_Time

attr_accessor :minute_length

def initialize
@minute_length=1.0      #length of game minute in real seconds
@hour_length= 60.0      #minute in an hour
@day_length=24.0        #hours in a day
@month_length=30.0    #days in a month
@year_length=12.0       #months in a year
@minutes=0                 #starting minute count
start_minute=0
add_minutes(start_minute)
start_hour=12               #starting hour count
add_hours(start_hour)
start_day=5                 #starting day count
add_days(start_day)
start_month=1              #starting month count
add_months(start_month-1)
start_year=129              #starting year count
add_years(start_year)
end

def add_minutes(minutes)
@minutes +=minutes
end

def add_hours(hours)
@minutes +=hours*@hour_length
end

def add_days(days)
@minutes += days*@hour_length*@day_length
end

def add_months(months)
@minutes +=months * @hour_length*@day_length*@month_length
end

def add_years(years)
@minutes += years * @hour_length*@day_length*@month_length * @year_length
end


def get_year
minutes=get_total_minutes
year=minutes / @hour_length / @day_length / @month_length  / @year_length
return year
end

def get_month
minutes=get_total_minutes
month=minutes / @hour_length / @day_length /  @month_length % @year_length + 1
return month
end

def get_day
minutes=get_total_minutes
day=minutes / @hour_length / @day_length % @month_length
return day
end

def get_hour
minutes=get_total_minutes
hour=minutes / @hour_length % @day_length
return hour
end

def get_total_minutes
total_sec=Graphics.frame_count / Graphics.frame_rate
minute=(total_sec/@minute_length+@minutes)
return minute
end

def get_minute
minutes=get_total_minutes % @hour_length
return minutes
end

def get_tone
period_length=Math::PI*(get_hour / @day_length)
red_shift=  -100+ 115*Math.sin(period_length)
green_shift=  -140+ 155*Math.sin(period_length)
blue_shift=  -150+ 165*Math.sin(period_length)
return Tone.new(red_shift, green_shift, blue_shift, 0)
end

end # of class Game_Time

#=======================================#
# â–  class Window_Time                                                            #
# written by Deke                                                                      #
#------------------------------------------------------------------------------#
#=======================================#
class Window_Time < Window_Base

#--------------------------------------------------------------------------
def initialize
super(0, 0, 160, 96)
self.contents = Bitmap.new(width - 32, height - 32)
self.contents.font.name = $fontface  # "Time" window font
self.contents.font.size = $fontsize
refresh
end

#--------------------------------------------------------------------------
def refresh
self.contents.clear
@total_sec = Graphics.frame_count / Graphics.frame_rate
@minute=$game_time.get_minute.floor
hour = $game_time.get_hour
pm_flag= hour >=12 ? true : false
hour= hour >= 12 ? hour-12 : hour
day=$game_time.get_day
month=$game_time.get_month
year=$game_time.get_year
if hour.floor==0
  text=sprintf("%02d:%02d",12,@minute)
else
  text=sprintf("%02d:%02d",hour,@minute)
end
if pm_flag
  text += " PM"
else
  text += " AM"
end
self.contents.font.color = normal_color
self.contents.draw_text(4, 0, 120, 32, text, 2)
text = sprintf("%02d-%02d-%02d", month, day, year)
self.contents.font.color=system_color
self.contents.draw_text(4,32,120,32,text)
end

#--------------------------------------------------------------------------
def update
if $game_time.get_minute.floor != @minute
  refresh
end
end
end # of class

# Window Clock by Prexus
class Window_Clock < Window_Base
def initialize(x, y, width, height)

  super(x, y, width, height)
  self.contents = Bitmap.new(width - 32, height - 32)
  self.opacity = 0
  @time = $game_time.get_minute.floor
  if self.contents.width > self.contents.height
    @radius = self.contents.height / 2
  else
    @radius = self.contents.width / 2
  end
  @center_x = self.contents.width / 2
  @center_y = self.contents.height / 2
  refresh
end
def update
  if @time != $game_time.get_minute.floor
    refresh
    @time = $game_time.get_minute.floor
  end
end
def refresh
  self.contents.clear
  if @face != nil
    @face.dispose
  end
  @face = Sprite.new
  @face.bitmap = RPG::Cache.picture("clock") # Change File Name Here
  @face.x = self.x + 16
  @face.y = self.y + 16
  #self.contents.fill_circle(@radius-1, @center_x, @center_y, Color.new(255,248,220,90), perfection = 1)
  #self.contents.draw_ring(@radius-1, @center_x, @center_y, 2, Color.new(0,0,0,255))
  self.contents.draw_clock($game_time.get_minute.floor, $game_time.get_hour.floor, @center_x, @center_y, @radius)
end
def dispose
  self.contents.clear
  @face.dispose
  super
end
end

#=======================================
class Game_Temp
#--------------------------------------------------------------------------
# ● Refer setup to Game Temp
#--------------------------------------------------------------------------
alias dns_game_temp_initalize initialize
#--------------------------------------------------------------------------
# ● Refer the Attr
#--------------------------------------------------------------------------
attr_reader    :map_infos  #Added Lines
attr_reader    :outside_array  #Added Lines
#--------------------------------------------------------------------------
# ● Refer setup to Scene Map
#--------------------------------------------------------------------------
def initialize
 dns_game_temp_initalize
 @outside_array = Array.new
 @map_infos = load_data("Data/MapInfos.rxdata")
 for key in @map_infos.keys
     @outside_array[key] = @map_infos[key].name.include?("*")
 end
end
end

#=======================================
class Scene_Map
#--------------------------------------------------------------------------
# ● Refer setup to Scene Map
#--------------------------------------------------------------------------
alias dns_scene_map_main main
alias dns_scene_map_update update
#--------------------------------------------------------------------------
# ● Main
#--------------------------------------------------------------------------
def main
  if $game_temp.outside_array[$game_map.map_id]
    tone=$game_time.get_tone
   @minute=$game_time.get_minute.floor
   $game_screen.start_tone_change(tone, 0)
 end
     # ã,¹ãƒ—ラã,¤ãƒˆã,»ãƒƒãƒˆã,'作成
 @spriteset = Spriteset_Map.new

 #CLOCK PARAMETERS (X POSITION, Y POSITION, WIDTH, HEIGHT)
  @clock = Window_Clock.new(640-82, 480-82, 82, 82)
 
 # メッã,»ãƒ¼ã,¸ã,¦ã,£ãƒ³ãƒ‰ã,¦ã,'作成
 @message_window = Window_Message.new
 # トランã,¸ã,·ãƒ§ãƒ³å®Ÿè¡Œ
 Graphics.transition
 # メã,¤ãƒ³ãƒ«ãƒ¼ãƒ—
 loop do
   $light_effects.refresh
   # ã,²ãƒ¼ãƒ ç"»é¢ã,'æ›´æ–°
   Graphics.update
   # å...¥åŠ›æƒ...å ±ã,'æ›´æ–°
   Input.update
   # フレーム更新
   update
   # ç"»é¢ãŒåˆ‡ã,Šæ›¿ã,ã£ãŸã,‰ãƒ«ãƒ¼ãƒ—ã,'中断
   if $scene != self
     break
   end
 end
 # トランã,¸ã,·ãƒ§ãƒ³æº–å,™
 Graphics.freeze
 # ã,¹ãƒ—ラã,¤ãƒˆã,»ãƒƒãƒˆã,'è§£æ"¾
 @spriteset.dispose
 @clock.dispose
 # メッã,»ãƒ¼ã,¸ã,¦ã,£ãƒ³ãƒ‰ã,¦ã,'è§£æ"¾
 @message_window.dispose
 # ã,¿ã,¤ãƒˆãƒ«ç"»é¢ã«åˆ‡ã,Šæ›¿ãˆä¸­ã®å ´åˆ
 if $scene.is_a?(Scene_Title)
   # ç"»é¢ã,'フã,§ãƒ¼ãƒ‰ã,¢ã,¦ãƒˆ
   Graphics.transition
   Graphics.freeze
 end
 $light_effects.hide
end
#--------------------------------------------------------------------------
# ● Update
#--------------------------------------------------------------------------
def update
 $light_effects.update
  conditional1 =$game_temp.outside_array[$game_map.map_id] and $game_time.get_minute.floor != @minute
  conditional2 =$game_temp.outside_array[$game_map.map_id] and @current_id != $game_map.map_id
  if conditional1 or conditional2
        tone=$game_time.get_tone
        $game_screen.start_tone_change(tone, 0)
        @minute = $game_time.get_minute.floor
        $game_map.need_refresh=true
        @current_id=$game_map.map_id
  end
  if $game_temp.outside_array[$game_map.map_id] == false and @current_id != $game_map.map_id
     $game_screen.start_tone_change(Tone.new(0,0,0,0),0)
     @current_id=$game_map.map_id
   end
   @clock.update
 dns_scene_map_update
end
end

#======================================================
class Scene_Title
#--------------------------------------------------------------------------
# ● Refer setup to Scene Map
#--------------------------------------------------------------------------
alias dns_scene_title_update update
#--------------------------------------------------------------------------
# ● Refer setup to Scene Map
#--------------------------------------------------------------------------
def update
$game_time=Game_Time.new
 #Dubealex Addition (from XRXS) to show Map Name on screen
dns_scene_title_update
end
end

#========================================================
class Scene_Load
def read_save_data(file)
characters = Marshal.load(file)
Graphics.frame_count = Marshal.load(file)
$game_system        = Marshal.load(file)
$game_switches      = Marshal.load(file)
$game_variables     = Marshal.load(file)
$game_self_switches = Marshal.load(file)
$game_screen        = Marshal.load(file)
$game_actors        = Marshal.load(file)
$game_party         = Marshal.load(file)
$game_troop         = Marshal.load(file)
$game_map           = Marshal.load(file)
$game_player        = Marshal.load(file)
$game_time           =Marshal.load(file) #Added Line
if $game_system.magic_number != $data_system.magic_number
  $game_map.setup($game_map.map_id)
  $game_player.center($game_player.x, $game_player.y)
end
$game_party.refresh
end
end # of Scene_Load updates

#=======================================================
class Scene_Save
def write_save_data(file)
characters = []
for i in 0...$game_party.actors.size
  actor = $game_party.actors[i]
  characters.push([actor.character_name, actor.character_hue])
end
Marshal.dump(characters, file)
Marshal.dump(Graphics.frame_count, file)
$game_system.save_count += 1
$game_system.magic_number = $data_system.magic_number
Marshal.dump($game_system, file)
Marshal.dump($game_switches, file)
Marshal.dump($game_variables, file)
Marshal.dump($game_self_switches, file)
Marshal.dump($game_screen, file)
Marshal.dump($game_actors, file)
Marshal.dump($game_party, file)
Marshal.dump($game_troop, file)
Marshal.dump($game_map, file)
Marshal.dump($game_player, file)
Marshal.dump($game_time,file) # Added Line
end
end # of Scene_Save updates

#========================================================

class Game_Map
#--------------------------------------------------------------------------
# ● Refer the attr
#--------------------------------------------------------------------------
attr_reader   :outside
attr_reader   :map_id
#--------------------------------------------------------------------------
# ● Outside
#--------------------------------------------------------------------------
def outside
  return $game_temp.outside_array[@map_id]
end
end

#==============================================================================
# â–  Light Effect System
#------------------------------------------------------------------------------
#  By: Near Fantastica
#   Date: 13/2/05
#
#   Addes light Effects to the DNS so objects glow and have ground effect lighting...
#==============================================================================

class Light_Effect_System
#--------------------------------------------------------------------------
# ● Refer the attr
#--------------------------------------------------------------------------
attr_accessor    :picture_le
attr_accessor    :event_list
attr_accessor    :type_list
#--------------------------------------------------------------------------
# ● Initialization
#--------------------------------------------------------------------------
def initialize
 @event_counter = 0

 @picture_le = Array.new
 @event_list = Array.new
 @type_list = Array.new
end
#--------------------------------------------------------------------------
# ● Setup Light Effects on Map Change
#--------------------------------------------------------------------------
def setup
 # Setup Event Max
 @event_counter = 0
 for i in 1..999
   if $game_map.map.events[i].id > @event_counter
     @event_counter = $game_map.map.events[i].id
   end
 end
 #
 for i in 1..@event_counter
   if  $game_map.map.events[i] == nil
     next
   end
   case $game_map.map.events[i].name
   when "Ground"
     ground(i)
   when "Fire"
     fire(i)
   when "Lamp Post"
     lamp(i)
   when "Left Lantern"
     left_lantern(i)
   when "Right Lantern"
     right_lantern(i)
   end
 end
end
#--------------------------------------------------------------------------
# ● Updates the Array based on time of day
#--------------------------------------------------------------------------
def update
 if $game_time.get_hour > 7 and $game_time.get_hour < 14
   hide
 else
   show
 end
end
#--------------------------------------------------------------------------
# ● Updates the XY of the sprites
#--------------------------------------------------------------------------
def refresh
 for i in 0..$light_effects.picture_le.size - 1
   case $light_effects.type_list[i]
   when "Ground"
     $light_effects.picture_le[i].x = ($game_map.events[$light_effects.event_list[i]].real_x - 200 - $game_map.display_x) / 4
     $light_effects.picture_le[i].y = ($game_map.events[$light_effects.event_list[i]].real_y - 200 - $game_map.display_y) / 4
     $light_effects.picture_le[i].visible = true
   when "Fire"
     $light_effects.picture_le[i].x = ($game_map.events[$light_effects.event_list[i]].real_x - 300 - $game_map.display_x) / 4
     $light_effects.picture_le[i].y = ($game_map.events[$light_effects.event_list[i]].real_y - 300 - $game_map.display_y) / 4
     $light_effects.picture_le[i].visible = true
   when "Left Lamp Post"
     $light_effects.picture_le[i].x = (-0.25 * $game_map.display_x) + ($game_map.events[$light_effects.event_list[i]].x * 32) - 5
     $light_effects.picture_le[i].y = (-0.25 * $game_map.display_y) + ($game_map.events[$light_effects.event_list[i]].y * 32) - 15
   when "Right Lamp Post"
     $light_effects.picture_le[i].x = (-0.25 * $game_map.display_x) + ($game_map.events[$light_effects.event_list[i]].x * 32) - 25
     $light_effects.picture_le[i].y = (-0.25 * $game_map.display_y) + ($game_map.events[$light_effects.event_list[i]].y * 32) - 15
     $light_effects.picture_le[i].visible = true
   when "Left Lantern"
     $light_effects.picture_le[i].x = (-0.25 * $game_map.display_x) + ($game_map.events[$light_effects.event_list[i]].x * 32) - 20
       $light_effects.picture_le[i].y = (-0.25 * $game_map.display_y) + ($game_map.events[$light_effects.event_list[i]].y * 32) - 5
       $light_effects.picture_le[i].visible = true
   when "Right Lantern"
     $light_effects.picture_le[i].x = (-0.25 * $game_map.display_x) + ($game_map.events[$light_effects.event_list[i]].x * 32) - 10
     $light_effects.picture_le[i].y = (-0.25 * $game_map.display_y) + ($game_map.events[$light_effects.event_list[i]].y * 32) - 5
     $light_effects.picture_le[i].visible = true
   end
 end
end
#--------------------------------------------------------------------------
# ● Redraws the Array
#--------------------------------------------------------------------------
def redraw
 if @picture_le != []
   for i in 0..@picture_le.size - 1
     @picture_le[i].bitmap.dispose
   end
   @picture_le = Array.new
   @event_list = Array.new
   @type_list = Array.new
 end
end
#--------------------------------------------------------------------------
# ● Shows Array
#--------------------------------------------------------------------------
def show
 if @picture_le != []
   for i in 0..@picture_le.size - 1
     @picture_le[i].visible = true
   end
 end
end
#--------------------------------------------------------------------------
# ● Hides Array
#--------------------------------------------------------------------------
def hide
 if @picture_le != []
   for i in 0..@picture_le.size - 1
      @picture_le[i].visible = false
   end
 end
end
#--------------------------------------------------------------------------
# ● Setup Light Effects for Ground
#--------------------------------------------------------------------------
def ground(event_index)
 light_effects = Sprite.new
 light_effects.bitmap = RPG::Cache.picture("LE.PNG")
 light_effects.zoom_x = 200 / 100.0
 light_effects.zoom_y = 200 / 100.0
 light_effects.z = 1000
 light_effects.opacity = 50
 light_effects.visible = false
 @picture_le.push(light_effects)
 @event_list.push(event_index)
 @type_list.push("Ground")
end
#--------------------------------------------------------------------------
# ● Setup Light Effects for Fire
#--------------------------------------------------------------------------
def fire(event_index)
 light_effects = Sprite.new
 light_effects.bitmap = RPG::Cache.picture("LE.PNG")
 light_effects.zoom_x = 300 / 100.0
 light_effects.zoom_y = 300 / 100.0
 light_effects.z = 1000
 light_effects.opacity = 100
 light_effects.visible = false
 @picture_le.push(light_effects)
 @event_list.push(event_index)
 @type_list.push("Fire")
end
#--------------------------------------------------------------------------
# ● Setup Light Effects for Lamp
#--------------------------------------------------------------------------
def lamp(event_index)
 light_effects = Sprite.new
 light_effects.bitmap = RPG::Cache.picture("LE.PNG")
 light_effects.z = 1000
 light_effects.opacity = 100
 light_effects.visible = false
 @picture_le.push(light_effects)
 @event_list.push(event_index)
 @type_list.push("Left Lamp Post")
 light_effects = Sprite.new
 light_effects.bitmap = RPG::Cache.picture("LE.PNG")
 light_effects.z = 1000
 light_effects.opacity = 100
 light_effects.visible = false
 @picture_le.push(light_effects)
 @event_list.push(event_index)
 @type_list.push("Right Lamp Post")
end
#--------------------------------------------------------------------------
# ● Setup Light Effects for Lantern
#--------------------------------------------------------------------------
def left_lantern(event_index)
 light_effects = Sprite.new
 light_effects.bitmap = RPG::Cache.picture("LE.PNG")
 light_effects.z = 1000
 light_effects.opacity = 150
 light_effects.visible = false
 @picture_le.push(light_effects)
 @event_list.push(event_index)
 @type_list.push("Left Lantern")
end
 #--------------------------------------------------------------------------
# ● Setup Light Effects for Lantern
#--------------------------------------------------------------------------
def right_lantern(event_index)
 light_effects = Sprite.new
 light_effects.bitmap = RPG::Cache.picture("LE.PNG")
 light_effects.z = 1000
 light_effects.opacity = 150
 light_effects.visible = false
 @picture_le.push(light_effects)
 @event_list.push(event_index)
 @type_list.push("Right Lantern")
end
end

#==============================================================================
# â–  Game_Map
#------------------------------------------------------------------------------
#  Add defenision of the names to Game Map Class
#==============================================================================

class Game_Map
#--------------------------------------------------------------------------
# ● Refer the attr
#--------------------------------------------------------------------------
attr_accessor :map
#--------------------------------------------------------------------------
# ● Refer setup to Game Map
#--------------------------------------------------------------------------
alias les_game_map_setup setup
#--------------------------------------------------------------------------
# ● Refers the Map Setup
#--------------------------------------------------------------------------
def setup(map_id)
 $light_effects.redraw
 les_game_map_setup(map_id)
 $light_effects.setup
end
end

#==============================================================================
# â–  Scene_Title
#------------------------------------------------------------------------------
#  It is the class which processes the title picture
#==============================================================================

class Scene_Title
#--------------------------------------------------------------------------
# ● Refer setup to Scene Title
#--------------------------------------------------------------------------
alias les_scene_title_update update
#--------------------------------------------------------------------------
# ● Sets up the ABS
#--------------------------------------------------------------------------
def update
$light_effects = Light_Effect_System.new
les_scene_title_update
end
end





My question is how would I go about making an event change the hour of the time of the day with the call script? I have no idea how to work it so any help would be awesome :)


EDIT : This isnt the full script, so dont try it if you want to use it. Tell me and I'll post the whole thing.
Title: A question...
Post by: Blaze on February 25, 2006, 08:27:59 PM
Is that ...?
Could that be the script I'm looking for ?

The day and night script ?
If so I wanna know how to do certain events at night and certain events in the morning.
Title: A question...
Post by: Jakexxx on February 26, 2006, 02:20:57 AM
^^^ I would like to know that too. I should post the full script I guess
Title: A question...
Post by: Blaze on February 26, 2006, 02:37:55 PM
Yeah, I need that script. You know like every 7-8 minutes it changes from morning to night. I'd like that.
Title: A question...
Post by: blueXx on February 26, 2006, 02:48:13 PM
you are just proving just by how far event clocks and day/night system are better than script ones...

if you are slow and didn't figure it out on your own- freaking use events... -.-
Title: A question...
Post by: Nightwolf on February 26, 2006, 02:58:04 PM
Blue is right, your script doesn't work(you posted in troubleshooting) so events are better
Title: A question...
Post by: blueXx on February 26, 2006, 03:40:39 PM
even if the script did work.. and it  should work...
if they want things to only happen at day or night time, it's alot easier to use events
Title: A question...
Post by: Blaze on February 26, 2006, 03:43:30 PM
Ok cool, But I don't know what buttons to hit day and what buttons to hit night. I also need to put different events during night and morning. That all sounds really hard and it sounds like it could take hours!
Title: A question...
Post by: Nightwolf on February 26, 2006, 03:45:31 PM
Blaze you need to plan n all, an rpg game can't just be finished in 12 minutes.
I thought that once, now i'm very patient, take time.
The more the time, the better the game.
THE MORE(time) THE MERRIER(members who download it)
Title: A question...
Post by: blueXx on February 26, 2006, 03:50:01 PM
blaze wants the game to be made for him
he doesn't understand that beyond knowladge there is a need for basic common sense...

you can tell him how to make switches all you want but when asked to trigger a flag that will show an event was done he wouldn't know what you are talking about
Title: A question...
Post by: Jakexxx on February 27, 2006, 04:44:50 AM
could we read my question? the script i posted is only part of it. that one i posted wont work alone, i only posted the part with my question in it. if you can see that the script changes time, I was wondering how I could make a event changing the hour variable, for things such as in a cutscene. this script works perfectly, I'll post the whole thing soon.
Title: A question...
Post by: Jakexxx on March 01, 2006, 03:35:46 AM
*terribly sorry for double post*
All I need here is to know how to call a script changing a local variable (In this case hours..) in the game with a event. (Ex. Change the time with a event...)
Title: A question...
Post by: Tsunokiette on March 01, 2006, 03:51:41 AM
Quote from: blueXxblaze wants the game to be made for him
he doesn't understand that beyond knowladge there is a need for basic common sense...

you can tell him how to make switches all you want but when asked to trigger a flag that will show an event was done he wouldn't know what you are talking about

The sad thing? Common sense isn't as common as it used to be.

[I'm pretty sure I learned that phrase from a member here...]

I could try to make one, starting tomorrow, probably thursday.

But it'll take a while.
Title: A question...
Post by: Jakexxx on March 01, 2006, 03:58:21 AM
*still doesnt answer my question.

In the script provided there is a variable in it called "hours". This determines the hour that the day is on. Is there a way to use a event, call the script, and change the hour variable? (I dont know if you answer this tho, srry.)