Help - Search - Members - Calendar
Full Version: Submission: Blue Magic
RPG RPG Revolution Forums > Scripting > Script Submissions > RGSS2-Submissions
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28
Prexus
I finally went back and made the edits to this code that were necessary for it to be a functional complete script.

Happy Hunting ^^

CODE
#-------------------------------#
# Blue Magic Script #
#-------------------------------#
# Written By: Prexus #
# http://prexus.rmxponline.com #
#-------------------------------#
# Instructions: #
# Read the comments and apply #
# changes where needed. #
#-------------------------------#

class Game_Battler
alias blm_game_battler_skill_effect skill_effect
def skill_effect(user, skill)
blm_game_battler_skill_effect(user, skill)
if user.is_a?(Game_Enemy) and self.is_a?(Game_Actor)
learn_chance = (rand(100) < 100) # X is the percentage chance (70, 20, etc.) Simply make x = 100 if you want it to work all the time.
if learn_chance == true
if self.class_id == 4 # Change this number with the class ID of your "Blue Mage"
#if skill.id == x or skill.id == y # etc. etc. replace x and y with ids of skills the mage can learn, if any skills just get rid of the line and the end, keep putting 'or skill.id = ' to add more.
self.learn_skill(skill.id, true) # Change true to false if you don't want a sound to play
#end
end
end
end
end
end

class Game_Actor < Game_Battler
def learn_skill(skill_id, play = false)
if skill_id > 0 and not skill_learn?(skill_id)
@skills.push(skill_id)
@skills.sort!
if play == true
Audio.me_play("Audio/ME/011-Item02") # Sound file to play when learning in battle.
end
end
end
end
Rpgx
What does Bluemagic do? It sounds cool!

Peace!
Gamerman1322
Blue Magic is the ability to use magic that was learned from other monsters. This type of mage was developed, and is still used, in Final Fantasy games. I'd love to implement this code in my stuff, but it would create more confusion for me with RPG Maker XP that I really don't need right now...
Rpgx
Oh yah! Oh ya! I remeber that. its great!
Jako Drako
Hey, this is my first script I'm posting here. It's just a simple icon based custom menu system with a window that shows the menu item you're selecting. Also shown in the screenshot are some simple bars that I might post later.

Screenshot:


Demos:
Custom Menu System HERE
Icon Command Window used in Battle HERE
(Added Window_Menu_Icon and Window_Menu_Icon_Reader classes, then modified Scene_Battle class. All changes in the Scene_Battle class are commented.)
Icon Command Window used in Title Screen HERE
(Added Window_Menu_Icon and Window_Menu_Icon_Reader classes, then modified Scene_Title class. All changes in the Scene_Title class are commented.)

Instructions for code numero uno: create a new script above Window_Help and call it Window_Menu_Icon. Paste the following code into this script.
CODE
#--------------------------------------------------------------
# CLASS: Window_Menu_Icon
# JAKO DRAKO
# Please give credit
# Summary: A command window with icons. To be used with class Window_Menu_Icon_Reader.
#--------------------------------------------------------------


class Window_Menu_Icon < Window_Selectable

attr_reader :disabled_items
attr_reader :commands

def initialize(x, y, commands)
  super(x, y, 32 * commands.size + 32, 64)
  @item_max = commands.size
  @commands = commands
  @column_max = commands.size
  self.contents = Bitmap.new(self.width - 32, self.height - 32)
  @disabled_items = Array.new(commands.size, false)
  self.index = 0
  refresh
end

#-------------------------------------------------------------
def refresh
  self.contents.clear
  for i in 0...@item_max
   draw_icon(i)
  end
end

#-------------------------------------------------------------
def draw_icon(index)
  temp_string = @commands[index]
  if temp_string.include? $data_system.words.item
   bitmap = RPG::Cache.icon("034-Item03")
  elsif temp_string.include? $data_system.words.skill
   bitmap = RPG::Cache.icon("044-Skill01")
  elsif temp_string.include? $data_system.words.attack or temp_string.include? $data_system.words.equip
   bitmap = RPG::Cache.icon("001-Weapon01")
  elsif temp_string.include? "Status" or temp_string.include? "New"
   bitmap = RPG::Cache.icon("050-Skill07")
  elsif temp_string.include? "Save"
   bitmap = RPG::Cache.icon("047-Skill04")
  elsif temp_string.include? "Quit" or temp_string.include? "End"
   bitmap = RPG::Cache.icon("046-Skill03")
  elsif temp_string.include? "Load" or temp_string.include? "Continue"
   bitmap = RPG::Cache.icon("048-Skill05")
  elsif temp_string.include? $data_system.words.guard
   bitmap = RPG::Cache.icon("009-Shield01")
  else
   bitmap = RPG::Cache.icon("049-Skill06")
  end
  
  x = 32 * index + 2
  self.contents.blt(x, 2, bitmap, Rect.new(0, 0, 24, 24))
end

#-------------------------------------------------------------
def update_cursor_rect
  if @index < 0
   self.cursor_rect.empty
   return
  end
  cursor_width = 28
  x = 32 * @index
  y = 0
  self.cursor_rect.set(x, y, cursor_width, 28)
end

#-------------------------------------------------------------
def disable_item(index)
  @disabled_items[index] = true
end
end


Instructions for code 2: create a new script below the previous one, name it Window_Menu_Icon_Reader, and paste the following code into it.
CODE
#--------------------------------------------------------------
# CLASS: Window_Menu_Icon_Reader
# Summary: Displays the command of the currently selected icon in a
# Window_Menu_Icon type object. The Window_Menu_Icon instance
# is supplied to the constructor method.
#--------------------------------------------------------------

class Window_Menu_Icon_Reader < Window_Base

def initialize(menu_window)
  @icon_window = menu_window
  @commands = @icon_window.commands
  super(@icon_window.x + @icon_window.width, @icon_window.y, 92, 64)
  self.contents = Bitmap.new(self.width - 32, self.height - 32)
  self.contents.font.name = $fontface
  self.contents.font.size = $fontsize
end

#--------------------------------------------------------------
def update
  super
  self.contents.clear
  draw_text(@icon_window.index)
end

#--------------------------------------------------------------
def draw_text(index)
  self.contents.clear
  if @icon_window.disabled_items[index] == false
   self.contents.font.color = normal_color
   self.contents.draw_text(0, 0, 60, 32, @commands[index])
  elsif @icon_window.disabled_items[index] == true
   self.contents.font.color = disabled_color
   self.contents.draw_text(0, 0, 60, 32, @commands[index])
  end
end
end


Instructions for code #3: Create a new code after Window_Gold and name it Window_Gold2 or something. Copy and paste...
CODE
#==============================================================================
# ¦ Window_Gold
#------------------------------------------------------------------------------
#  ????????????????
#==============================================================================

class Window_Gold2 < Window_Base
#--------------------------------------------------------------------------
#  ????????
#--------------------------------------------------------------------------
def initialize()
  super(0, 0, 162, 64)
  self.contents = Bitmap.new(width - 32, height - 32)
  self.contents.font.name = $fontface
  self.contents.font.size = $fontsize
  refresh
end
#--------------------------------------------------------------------------
#  ?????
#--------------------------------------------------------------------------
def refresh
  self.contents.clear
  cx = contents.text_size($data_system.words.gold).width
  self.contents.font.color = normal_color
  self.contents.draw_text(4, 0, 120-cx-2, 32, $game_party.gold.to_s, 2)
  self.contents.font.color = system_color
  self.contents.draw_text(124-cx, 0, cx, 32, $data_system.words.gold, 2)
end
end

(Yeah, I know it's almost exactly the same as Window_Gold, but if I said, "Copy the Window_Gold script and name the copy Window_Gold2. Then change the class definition line so that the class name is Window_Gold2. Now change the super method call under the constructor method so that the width local variable is 162." would you understand me?)

Another class that must be changed slightly: Window_Playtime. Paste this code into the Window_Playtime class.
CODE
#==============================================================================
# ¦ Window_PlayTime
#------------------------------------------------------------------------------
#  ????????????????????????
#==============================================================================

class Window_PlayTime < Window_Base
#--------------------------------------------------------------------------
#  ????????
#--------------------------------------------------------------------------
def initialize
  super(0, 0, 162, 64)
  self.contents = Bitmap.new(width - 32, height - 32)
  self.contents.font.name = $fontface
  self.contents.font.size = $fontsize
  refresh
end
#--------------------------------------------------------------------------
#  ?????
#--------------------------------------------------------------------------
def refresh
  self.contents.clear
  @total_sec = Graphics.frame_count / Graphics.frame_rate
  hour = @total_sec / 60 / 60
  min = @total_sec / 60 % 60
  sec = @total_sec % 60
  text = sprintf("%02d:%02d:%02d", hour, min, sec)
  self.contents.font.color = normal_color
  self.contents.draw_text(4, 0, 120, 32, text, 2)
end
#--------------------------------------------------------------------------
#  ?????
#--------------------------------------------------------------------------
def update
  super
  if Graphics.frame_count / Graphics.frame_rate != @total_sec
   refresh
  end
end
end


Okay, last script (sort of): Replace the code in your Window_MenuStatus script with this code:
CODE
#--------------------------------------------------------------
# CLASS: Winodw_MenuStatus
# Summary: Edited Window_MenuStatus class to be used with
# the Window_Menu_Icon class.
#--------------------------------------------------------------

class Window_MenuStatus < Window_Selectable

def initialize
  super(0, 0, 640, 416)
  self.contents = Bitmap.new(width - 32, height - 32)
  self.contents.font.name = $fontface
  self.contents.font.size = $fontsize
  refresh
  self.active = false
  self.index = -1
  @column_max = 4
end

#--------------------------------------------------------------
def refresh
  self.contents.clear
  @item_max = $game_party.actors.size
  for i in 0...$game_party.actors.size
   actor = $game_party.actors[i]
   text_x = 155 * i + 5
   text_y = 150
   bitmap = RPG::Cache.battler(actor.battler_name, actor.battler_hue)
   pic_x = 155 * i + (150 - bitmap.width) / 2
   pic_y = 5
   self.contents.blt(pic_x, pic_y, bitmap, Rect.new(0, 0, 150, bitmap.height))
   draw_actor_name(actor, text_x, text_y)
   draw_actor_class(actor, text_x, text_y + 32)
   draw_actor_level(actor, text_x - 1, text_y + 64)
   draw_actor_state(actor, text_x, text_y + 192)
   draw_actor_exp(actor, text_x - 1, text_y + 160)
   draw_actor_hp(actor, text_x, text_y + 96)
   draw_actor_sp(actor, text_x, text_y + 128)
  end
end

#--------------------------------------------------------------
def update_cursor_rect
  if @index < 0
   self.cursor_rect.empty
  else
   self.cursor_rect.set(155 * @index, 0, 148, 384)
  end
end
end


All right. Now to implement it. Open the Scene_Menu script. Replace all the code with this code:
CODE
#==============================================================================
# ¦ Scene_Menu
#------------------------------------------------------------------------------
#  ?????????????????
#==============================================================================

class Scene_Menu
#--------------------------------------------------------------------------
#  ????????
#   menu_index : ????????????
#--------------------------------------------------------------------------
def initialize(menu_index = 0)
  @menu_index = menu_index
end
#--------------------------------------------------------------------------
#  ????
#--------------------------------------------------------------------------
def main
  # ???????????
  s1 = $data_system.words.item
  s2 = $data_system.words.skill
  s3 = $data_system.words.equip
  s4 = "Status"
  s5 = "Save"
  s6 = "Quit"
  @command_window = Window_Menu_Icon.new(0, 0, [s1, s2, s3, s4, s5, s6])
  @command_window.index = @menu_index
  @command_window_text = Window_Menu_Icon_Reader.new(@command_window)
  # ?????? 0 ???
  if $game_party.actors.size == 0
   # ????????????????????
   @command_window.disable_item(0)
   @command_window.disable_item(1)
   @command_window.disable_item(2)
   @command_window.disable_item(3)
  end
  # ???????
  if $game_system.save_disabled
   # ????????
   @command_window.disable_item(4)
  end
  # ????????????
  @status_window = Window_MenuStatus.new
  @status_window.x = 0
  @status_window.y = 64
  @gold_window = Window_Gold2.new
  @gold_window.x = 316
  @gold_window.y = 0
  @time_window = Window_PlayTime.new
  @time_window.x = 478
  @time_window.y = 0
  # ????????
  Graphics.transition
  # ?????
  loop do
   # ???????
   Graphics.update
   # ??????
   Input.update
   # ?????
   update
   # ???????????????
   if $scene != self
    break
   end
  end
  # ????????
  Graphics.freeze
  # ???????
  @command_window.dispose
  @command_window_text.dispose
  @status_window.dispose
  @gold_window.dispose
  @time_window.dispose
end
#--------------------------------------------------------------------------
#  ?????
#--------------------------------------------------------------------------
def update
  # ???????
  @command_window.update
  @command_window_text.update
  @status_window.update
  @gold_window.update
  @time_window.update
  # ?????????????????: update_command ??
  if @command_window.active
   update_command
   return
  end
  # ??????????????????: update_status ??
  if @status_window.active
   update_status
   return
  end
end
#--------------------------------------------------------------------------
#  ????? (??????????????????)
#--------------------------------------------------------------------------
def update_command
  # B ?????????
  if Input.trigger?(Input::B)
   # ???? SE ??
   $game_system.se_play($data_system.cancel_se)
   # ?????????
   $scene = Scene_Map.new
   return
  end
  # C ?????????
  if Input.trigger?(Input::C)
   # ?????? 0 ?????????????????????
   if $game_party.actors.size == 0 and @command_window.index < 4
    # ?? SE ??
    $game_system.se_play($data_system.buzzer_se)
    return
   end
   # ??????????????????
   case @command_window.index
   when 0 # ???
    # ? SE ??
    $game_system.se_play($data_system.decision_se)
    # ??????????
    $scene = Scene_Item.new
   when 1 # ??
    # ? SE ??
    $game_system.se_play($data_system.decision_se)
    # ??????????????????
    @command_window.active = false
    @command_window_text.active = false
    @status_window.active = true
    @status_window.index = 0
   when 2 # ?
    # ? SE ??
    $game_system.se_play($data_system.decision_se)
    # ??????????????????
    @command_window.active = false
    @command_window_text.active = false
    @status_window.active = true
    @status_window.index = 0
   when 3 # ????
    # ? SE ??
    $game_system.se_play($data_system.decision_se)
    # ??????????????????
    @command_window.active = false
    @command_window_text.active = false
    @status_window.active = true
    @status_window.index = 0
   when 4 # ??
    # ???????
    if $game_system.save_disabled
     # ?? SE ??
     $game_system.se_play($data_system.buzzer_se)
     return
    end
    # ? SE ??
    $game_system.se_play($data_system.decision_se)
    # ?????????
    $scene = Scene_Save.new
   when 5
    # ? SE ??
    $game_system.se_play($data_system.decision_se)
    # "QUIT" CODE
    $scene = Scene_End.new()
   return
  end
end
#--------------------------------------------------------------------------
#  ????? (???????????????????)
#--------------------------------------------------------------------------
def update_status
  # B ?????????
  if Input.trigger?(Input::B)
   # ???? SE ??
   $game_system.se_play($data_system.cancel_se)
   # ?????????????????
   @command_window.active = true
   @command_window_text.active = true
   @status_window.active = false
   @status_window.index = -1
   return
  end
  # C ?????????
  if Input.trigger?(Input::C)
   # ??????????????????
   case @command_window.index
   when 1 # ??
    # ??????????? 2 ????
    if $game_party.actors[@status_window.index].restriction >= 2
     # ?? SE ??
     $game_system.se_play($data_system.buzzer_se)
     return
    end
    # ? SE ??
    $game_system.se_play($data_system.decision_se)
    # ?????????
    $scene = Scene_Skill.new(@status_window.index)
   when 2 # ?
    # ? SE ??
    $game_system.se_play($data_system.decision_se)
    # ????????
    $scene = Scene_Equip.new(@status_window.index)
   when 3 # ????
    # ? SE ??
    $game_system.se_play($data_system.decision_se)
    # ???????????
    $scene = Scene_Status.new(@status_window.index)
   end
   return
  end
end
end
end


Okay, you're done! Now when you call the menu in game, it will look something like the screenshot above.

If the experience text for the party members is a little off, replace the draw_actor_exp method in Window_Base with this:
CODE
def draw_actor_exp(actor, x, y)
self.contents.font.color = system_color
self.contents.draw_text(x, y, 40, 32, "Exp")
self.contents.font.color = normal_color
self.contents.draw_text(x , y, 84, 32, actor.exp_s, 2)  #x + 24
self.contents.draw_text(x + 85, y, 12, 32, "/", 1)  #x + 108
self.contents.draw_text(x + 97, y, 84, 32, actor.next_exp_s)  #x + 120
end


Added by Night_Runner
This script follows an archaic format, which allows custom font and custom fontsize. To run the code, you need to go into your script editor, along long the left scroll down to, and select, Main.
Just after begin, insert the code:
CODE
$fontface = Font.default_name
$fontsize = Font.default_size

Which sets the font & font size to follow default format.


For advanced scripters: You can use the Window_Menu_Icon and Window_Menu_Icon_Reader classes for any instance of Window_Command used in the script. If you need help implementing this, just PM me.
Examples:
In title screen (For script changes look in the demo)

In battle (Again, look in the demo for all the script changes)


Edited by Night_Runner - Fix all the ?'s in the code, and to append my footnote above..
Jako Drako
Okay, I fixed up some parts of the code, so it should work now (I don't know if anybody even noticed, lol). I also added a frew screenshots. I guess it always helps to see what's going on to decide if you want to try it out...
jens009
QUOTE
For advanced scripters: You can use the Window_Menu_Icon and Window_Menu_Icon_Reader classes for any instance of Window_Command used in the script. If you need help implementing this, just PM me.


Well, not exactly a advanced scripter but more like a script editor.. So yes I want to use the Window_Command used in your script to function in the battle system..

(Second example screen)
Jako Drako
To do that you'll want to add the Window_Menu_Icon and Window_Menu_Icon_Reader classes to your scripts. Then in the Scene_Battle scripts change the constructor for @actor_command_window to Window_Menu_Icon.new(0, 256, [s1, s2, s3, s4]) instead of Window_Command.new(160, [s1, s2, s3, s4])... er. It's too confusing to explain in writing. I uploaded a demo with it so you can just look at the script and copy it if you need to. All the changes to the scripts were commented. happy.gif
jens009
I understand it, dont worry.. its not really confusing since I understand scripts, but I cant write them though.. But perhaps the demo you stated would elaborate your explanation to other members better
UltimaDude
Nice menu,The colour i dont really like it though.
But nice idea
Jako Drako
The color depends on the window skin you pick, perhaps you are new and did not know that.
Bazoo
I really like this CMS, it's pretty and it was really easy to customize (in terms of fonts; I got it to work for Postality Knights in a minute smile.gif ).

Thanks, Jako. :Thumbup:
Bearrick
where do i add this script?
Ty
NECRO POST! Next time check the dates before posting. To answer your question simply add the script above 'Main' and follow the instructions.

CODE
#-------------------------------#
# ? ? ? Blue Magic Script ? ? ? #
#-------------------------------#
# Written By: Prexus ? ? ? ? ? ? #
# http://prexus.rmxponline.com #
#-------------------------------#
# Instructions: ? ? ? ? ? ? ? ? #
# Read the comments and apply ? #
# changes where needed. ? ? ? ? #
#-------------------------------#

class Game_Battler
alias blm_game_battler_skill_effect skill_effect
def skill_effect(user, skill)
blm_game_battler_skill_effect(user, skill)
if user.is_a?(Game_Enemy) and self.is_a?(Game_Actor)
learn_chance = (rand(100) < 100) # X is the percentage chance (70, 20, etc.) Simply make x = 100 if you want it to work all the time.
if learn_chance == true
if self.class_id == 1 # Change this number with the class ID of your "Blue Mage"
#if skill.id == x or skill.id == y # etc. etc. replace x and y with ids of skills the mage can learn, if any skills just get rid of the line and the end, keep putting 'or skill.id = ' to add more.
self.learn_skill(skill.id, true) # Change true to false if you don't want a sound to play
#end
end
end
end
end
end

class Game_Actor < Game_Battler
def learn_skill(skill_id, play = false)
if skill_id > 0 and not skill_learn?(skill_id)
@skills.push(skill_id)
@skills.sort!
if play == true
Audio.me_play("Audio/ME/011-Item02") # Sound file to play when learning in battle.
end
end
end
end


if you are lazy. Read the comments on each line to adjust the percent chance to learn a skill in battle. For example, it is set so class 1 has a certain chance to learn a skill if an enemy uses a skill on him/her.
Ty
Script Name: Maximum item Limits
Written by: Synthesize
Current Version: V.1.00
Release Date: August 15, 2007

What is it?
This script rewrites the gain_ methods in Game_Party allowing the designer to define maximum item, weapon and armor limits. Also, item IDs, weapon IDs, and Armor IDs can be defined allowing one to define custom item limits for specific items.

Screenshots
Look at the item screen, instead of '99' the value is x.

The Script
Place above Main
CODE
#============================================================================
#                            *Syn's Maximum Item Limits*
#----------------------------------------------------------------------------
# Written by Synthesize
# Version 1.00
# August 15, 2007
#============================================================================
#----------------------------------------------------------------------------
# Compatability
# Rewrites:
#   Game_Party::gain_item
#   Game_Party::gain_weapon
#   Game_Party::gain_armor
#----------------------------------------------------------------------------
# Begin Customization Section
#----------------------------------------------------------------------------
module SynItemMax
  # Format = {item_id => maximum amount}
  Max_item = {32 => 100}
  # Default Max Item Storage
  Max_item.default = 100
  # Format = {weapon_id => maximum amount}
  Max_weapon = {}
  # Maximum Weapon storage
  Max_weapon.default = 99
  # Format = {armor_id => maximum amount}
  Max_armor = {}
  # Maximum storage space
  Max_armor.default = 99
end
#----------------------------------------------------------------------------
# Begin Game_Party rewrite
#----------------------------------------------------------------------------
class  Game_Party
  #--------------------------------------------------------------------------
  # Rewrite gain_item
  #--------------------------------------------------------------------------
  def gain_item(item_id,n)
    if item_id > 0
      @items[item_id] = [[item_number(item_id) + n, 0].max, SynItemMax::Max_item[item_id]].min
    end
  end
  #--------------------------------------------------------------------------
  # Rewrite gain_weapon
  #--------------------------------------------------------------------------
  def gain_weapon(weapon_id,n)
    if weapon_id > 0
      @weapons[weapon_id] = [[weapon_number(weapon_id) + n, 0].max, SynItemMax::Max_weapon[weapon_id]].min
    end
  end
  #--------------------------------------------------------------------------
  # Rewrite gain_armor
  #--------------------------------------------------------------------------
  def gain_armor(armor_id,n)
    if armor_id > 0
      @armors[armor_id] = [[armor_number(armor_id) + n, 0].max, SynItemMax::Max_armor[armor_id]].min
    end
  end
end
#============================================================================
# Written by Synthesize
# Version 1.00
# August 15, 2007
#----------------------------------------------------------------------------
#                   *Syns Maximum Item Limits*
#============================================================================


Usage:
This script may be used in either a commercial project or a free ware project free of charge. However, credit must be present somewhere in the project.

Editing/Distribution:
Feel free to redistribute this post to other boards/websites. Just keep the wording the same. As for editing the script to suite your tastes feel free. Just keep the original header/footer in tact.

If you have any questions or you found a bug, please PM me or make a post with the following:
1.) SDK Version
2.) Other Scripts
3.) Factors of the bug (What did you do to make it happen?)
4.) version
5.) Error Line

Cheers,

Syn
Roderick
The script is good but if you say make the potion's limit to 5 and you buy ten you lose the money and the other 5 potions.
Ty
Find the following line in Scene_Shop:

number == 99

Change 99 to the number you want.
FlyingHamsta
How would you change "number == 99" in Scene Shop so that the limit is always equal to the item that you put on the item minus the number in your inventory.
Ty
SynItemMax::Max_item

Change Max_item to Max_weapon / Max_armor
Roderick
QUOTE (Synthesize @ Aug 16 2007, 12:45 PM) *
Find the following line in Scene_Shop:

number == 99

Change 99 to the number you want.


But if you make like that all the items maximum will be the number you will write is there a way(show me too because i'm not that good at scripting) so in shop all items get their limit value?
Ty
Punctuation please.

Look at the post above the post that you posted.
Roderick
Were do i need to put it?
Zeriab
Script Page here: http://www.rpgrevolution.com/script/24

I have tried to make a Dialog system which is intended to ease the creation of dialogs.
QUOTE (Dialog system)
CODE
#==============================================================================
# ** Dialog system
#------------------------------------------------------------------------------
# Zeriab
# Version 1.0
# 2007-11-07 (Year-Month-Day)
#------------------------------------------------------------------------------
# * Description :
#
#   A small framework like script for dialogs
#------------------------------------------------------------------------------
# * License :
#
#   Copyright (C) 2007  Zeriab
#
#   This program is free software: you can redistribute it and/or modify
#   it under the terms of the GNU Lesser Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU Lesser Public License for more details.
#
#   For the full license see <http://www.gnu.org/licenses/>
#   The GNU General Public License: http://www.gnu.org/licenses/gpl.txt
#   The GNU Lesser General Public License: http://www.gnu.org/licenses/lgpl.txt
#------------------------------------------------------------------------------
# * Instructions :
#
#   You can place this script pretty much anyway you like.
#   Place it above any other Dialogs you might be using.
#   Increase the STARTING_Z_VALUE if you have trouble with the dialog not
#   on top.
#==============================================================================
class Dialog
  STARTING_Z_VALUE = 1500 # Default value is 1500
  attr_accessor :value
  attr_writer :marked_to_close
  #--------------------------------------------------------------------------
  # * Getter with 'false' as default value
  #--------------------------------------------------------------------------
  def marked_to_close
    @marked_to_close = false  if @marked_to_close.nil?
    return @marked_to_close
  end
  #--------------------------------------------------------------------------
  # * Initialization
  #--------------------------------------------------------------------------
  def mark_to_close
    self.marked_to_close = true
  end
  #--------------------------------------------------------------------------
  # * Show the dialog
  #   Returns the value from the dialog
  #--------------------------------------------------------------------------
  def self.show(*args, &block)
    dialog = self.new(*args, &block)
    dialog.marked_to_close = false
    return dialog.main
  end
  #--------------------------------------------------------------------------
  # * Initialization
  #--------------------------------------------------------------------------
  def initialize(*args, &block)
    # For subclasses to overwrite
  end
  #--------------------------------------------------------------------------
  # * Main processing
  #--------------------------------------------------------------------------
  def main
    # Create the dimmed background
    create_background
    # Create Windows
    main_window
    # Main loop
    loop do
      # Update game screen
      Graphics.update
      # Update input information
      Input.update
      # Frame update
      update
      # Abort loop if the dialog should close
      if marked_to_close
        break
      end
    end
    # Dispose of windows
    main_dispose
    # Dispose of background
    dispose_background
    # Update input information
    Input.update
    # Returns the acquired value
    return self.value
  end
  #--------------------------------------------------------------------------
  # * Create the dimmed background
  #--------------------------------------------------------------------------
  def create_background
    bitmap = Bitmap.new(640,480)
    bitmap.fill_rect(0,0,640,480,Color.new(0,0,0,128))
    @background_sprite = Sprite.new
    @background_sprite.z = STARTING_Z_VALUE
    @background_sprite.bitmap = bitmap
  end
  #--------------------------------------------------------------------------
  # * Create the windows
  #--------------------------------------------------------------------------
  def main_window
    # For the subclasses to override
    # Remember to set their z.value to at least STARTING_Z_VALUE + 1
  end
  #--------------------------------------------------------------------------
  # * Dispose the background
  #--------------------------------------------------------------------------
  def dispose_background
    @background_sprite.dispose
  end
  #--------------------------------------------------------------------------
  # * Dispose the windows
  #--------------------------------------------------------------------------
  def main_dispose
    # For the subclasses to override
    # Dispose your windows here
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # For the subclasses to override
    if Input.trigger?(Input::B)
      mark_to_close
    end
  end
end


What is a dialog? You can consider it as a scene that runs on top of the current scene.
Here is an example of how the system can be used. It is a yes/no dialog.
QUOTE (An example - A Yes/No Dialog)
CODE
#============================================================================
# * A Simple Yes/No dialog
#============================================================================
class Dialog_YesNo < Dialog
  # self.value: false = No, true = Yes
  
  #--------------------------------------------------------------------------
  # * A show method
  #--------------------------------------------------------------------------
  def initialize(default_value = false, text = nil)
    # Sets the default value
    self.value = default_value
    @text = text
    # Sets the menu index
    if default_value
      @menu_index = 0
    else
      @menu_index = 1
    end
  end
  #--------------------------------------------------------------------------
  # * Create the windows
  #--------------------------------------------------------------------------
  def main_window
    @disposables = []
    
    # The command window
    @command_window = Window_Command.new(80, ['Yes', 'No'])
    @command_window.index = @menu_index
    @command_window.x = (640 - @command_window.width) / 2
    @command_window.y = (480 - @command_window.height) / 2
    @command_window.z = STARTING_Z_VALUE + 1
    @disposables << @command_window
    
    # The text window
    if @text.is_a?(String)
      @text_window = Window_Help.new
      @text_window.set_text(@text, 1)
      @text_window.z = STARTING_Z_VALUE + 1
      @disposables << @text_window
    end
  end
  #--------------------------------------------------------------------------
  # * Dispose the windows
  #--------------------------------------------------------------------------
  def main_dispose
    @disposables.each {|element| element.dispose}
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    @command_window.update
    if Input.trigger?(Input::B)
      mark_to_close
    end
    if Input.trigger?(Input::C)
      if @command_window.index == 0
        self.value = true
      else
        self.value = false
      end
      mark_to_close
    end
  end
end


The idea is that you can all this dialog anywhere with the code:
CODE
# Code before
var = Dialog_YesNo.show(default_value, text) # Calls the dialog
# Code after

The dialog should then be shown and the code after will only be executed after the player chooses yes or no. It will return false if No is selected and true if Yes is selected.
Then the code placed after the call will be executed. You can say it will freeze execution until the dialog is closed.
The principle is that you can call this code anyway. In script calls as well as in normal scripts.
Here is an example of a script call:
CODE
s = 'Do you want to open the chest?'
v = Dialog_YesNo.show(true, s)
$game_switches[5] = v

Here is an event using this:
QUOTE (Angry Chest)

I assume you know how to make page 2 and page 3 yourself.

I know. This can easily be done with the normal choice system in events. So what about an example where its use is more clear?
Did you know that if you try to save on a slot where there already is a savegame it does not ask if you want to overwrite? It simply just overwrites the savegame. Let us say we don't want that. The remedy?
CODE
class Scene_Save < Scene_File
  alias scene_save_overwrite_dialog_on_decision on_decision
  #--------------------------------------------------------------------------
  # * Decision Processing
  #--------------------------------------------------------------------------
  def on_decision(filename)
    if File.exist?(filename)
      var = Dialog_YesNo.show(false, 'Do you want to overwrite' +
                                     ' the old savegame?')
      unless var
        $game_system.se_play($data_system.buzzer_se)
        return
      end
    end
    scene_save_overwrite_dialog_on_decision(filename)
  end
end

Just paste this anywhere below the original Scene_Save.


I have tried to give dialogs the feeling of scenes.
When you create a dialog you will in most cases only have to overwrite 3-4 methods:

main_window
You should create the windows you are going to use in this method.
Please set the .z-values of the windows to at least STARTING_Z_VALUE + 1
This is what you put before the main loop when creating a normal scene.
You can consider it pretty much equivalent to the main_window method in the SDK.
Does nothing by default

main_dispose
Dispose of the windows you have created here and do any other clean up you find necessary.
Does nothing by default

update
The update method is pretty much equivalent to the update method in a normal scene.
Exits the scene when you press the B-button by default.

You end the dialog by calling the mark_to_close method. It will then exit just like if you normally change the scene.
Remember to set the value that will be returned. By default is nil returned.
Use self.value = ... to set the value. This value will not be frozen after you use the mark_to_close method, which means that you can change the value after you use that method if it happens later in the update method.

I am certain that I have messed something up or forgotten to tell something important. Please do tell if you run into any problems

*hugs*
- Zeriab
deadlydan
Hi guys, this is a little thing i added for custom fonts, putting it on here for the less knowledgeable people of RGSS.

This basically allows you to load fonts and check if they exist simply put.
  1. Open up the "Main" script, and put the following before the "begin" call.
    CODE
    def FontExist?
      unless Font.exist? ( Font.default_name )
        print "Unable to find #{Font.default_name} font."
        exit
      end
    end

    def FontLoad ( fontname, fontsize )
      Font.default_name = fontname
      Font.default_size = fontsize
      FontExist?
    end

  2. Before the line "$scene = Scene_Title.new" add the following:
    (Replace 15 with the font size you want and replace Comic Sans MS with the name of the font you want to use, for loading fonts from the "Fonts" folder in your project folder without installing it on windows, place the *.ttf file in the "Fonts" folder, and use the name which is stated when you view the font in windows. It is case sensitive by the way.


    CODE
    FontLoad ( "Comic Sans MS", 15 )
No credits needed, thanks smile.gif
deadlydan
Hey guys, by request, i changed the little snippet i made for turtleman, added in some checks also to fix some bugs. Here's the code, very simple to use:

CODE
#==============================================================================
# ■ DeadlyDan_MessageSound v2.0 by DeadlyDan
#------------------------------------------------------------------------------
#  Simple "typewriting" style sound when messages are displayed.
#==============================================================================
# Usage:
=begin
  
  Simply change:
  
  MS_SOUND = "Audio/SE/cursor"
  
  To what ever sound file you want, for example:
  
  MS_SOUND = "Audio/SE/cow"
  
  If you want to change how fast it sounds, change
  
  MS_FRAME_INTERVAL = 2
  
  To, for example, if you want longer:
  
  MS_FRAME_INTERVAL = 4

=end

class Window_Message < Window_Selectable
  
  MS_SOUND = "Audio/SE/cursor"
  MS_FRAME_INTERVAL = 2
  
  def update_message
    loop do
      c = @text.slice!(/./m)
      case c
      when nil
        finish_message
        break
      when "\x00"
        new_line
        if @line_count >= MAX_LINE
          unless @text.empty?
            self.pause = true
            break
          end
        end
      when "\x01"
        @text.sub!(/\[([0-9]+)\]/, "")
        contents.font.color = text_color($1.to_i)
        next
      when "\x02"
        @gold_window.refresh
        @gold_window.open
      when "\x03"
        @wait_count = 15
        break
      when "\x04"
        @wait_count = 60
        break
      when "\x05"
        self.pause = true
        break
      when "\x06"
        @line_show_fast = true
      when "\x07"
        @line_show_fast = false
      when "\x08"
        @pause_skip = true
      else
        if ( @line_show_fast == false and @show_fast == false )
          if ( Graphics.frame_count > ( @last_ms_sound_frame.to_i + MS_FRAME_INTERVAL ) )
            Audio.se_play ( MS_SOUND, 100, 100 )
            @last_ms_sound_frame = Graphics.frame_count
          end
        end
        contents.draw_text(@contents_x, @contents_y, 40, WLH, c)
        c_width = contents.text_size(c).width
        @contents_x += c_width
      end
      break unless @show_fast or @line_show_fast
    end
  end
  
end
jens009
Good job. ;-] Now it's user friendly.
Might I ask though, you said you fixed some bugs? What would they be?
turtleman
Yeah, I didn't notice any =P.

By the way, is there a way to prolong to beeb between letters, like 1 beep every other letter or something?
Just wondering.
deadlydan
QUOTE (jens009 @ Jan 31 2008, 07:30 PM) *
Good job. ;-] Now it's user friendly.
Might I ask though, you said you fixed some bugs? What would they be?


Well, if you pressed enter to skip the message writing it would still play an extra few sounds.

QUOTE (turtleman @ Jan 31 2008, 07:31 PM) *
Yeah, I didn't notice any =P.

By the way, is there a way to prolong to beeb between letters, like 1 beep every other letter or something?
Just wondering.


I'll script that in right now, hold on a few mins smile.gif

|EDIT|

Updated, to add the feature you desire smile.gif
Rory
Wow! Nice Script, and amazing idea.
Melkor Qc
Great idea for a script, I always liked the sound it makes in Zelda games when you read messages :]
Kuplex
Another nice script, DeadlyDan. smile.gif
Nathan
Can you turn on and off?
:/
X-Snake-X
Great Script as always Dann^^
turtleman
Thanks for updating timing in the sound for me. Setting it to 4 or 5 makes it sound perfect!

Again, thankyou, you've been so helpful.
Kuplex
I was inspired by NathanDug's thread to make this simple, but useful script.
It allows you to disable/enable the battle BGM (default is enabled). So your map BGM/BGS will continue uninterrupted into battle. This is useful for key battles where you don't want it change to battle music.

Game_System script
Add the following with the other attr_accessor near the top.
CODE
attr_accessor :battle_bgm_enabled


Directly below, you will see a section called def initialize
Add the following at the end of the others:
CODE
@battle_bgm_enabled = true

If you want it to be disabled by default, change the value to FALSE.

======================

Scene_Map script

This is the original code for def Call_Battle
CODE
def call_battle
    @spriteset.update
    Graphics.update
    $game_player.make_encounter_count
    $game_player.straighten
    $game_temp.map_bgm = RPG::BGM.last
    $game_temp.map_bgs = RPG::BGS.last
    RPG::BGM.stop
    RPG::BGS.stop    
    Sound.play_battle_start    
    $game_system.battle_bgm.play
    $game_temp.next_scene = nil
    $scene = Scene_Battle.new
  end


Replace it with this:
CODE
def call_battle
    @spriteset.update
    Graphics.update
    $game_player.make_encounter_count
    $game_player.straighten
    $game_temp.map_bgm = RPG::BGM.last
    $game_temp.map_bgs = RPG::BGS.last
    
    if $game_system.battle_bgm_enabled
      RPG::BGM.stop
      RPG::BGS.stop    
      Sound.play_battle_start    
      $game_system.battle_bgm.play
    end
    
    $game_temp.next_scene = nil
    $scene = Scene_Battle.new
  end


======================

Scene Battle script

This is the original code for def process_victory:
CODE
def process_victory
    @info_viewport.visible = false
    @message_window.visible = true    
    RPG::BGM.stop
    $game_system.battle_end_me.play    
    unless $BTEST
      $game_temp.map_bgm.play
      $game_temp.map_bgs.play
    end
    display_exp_and_gold
    display_drop_items
    display_level_up
    battle_end(0)
  end


Replace it with this:
CODE
def process_victory
    @info_viewport.visible = false
    @message_window.visible = true
    
    if $game_system.battle_bgm_enabled
      RPG::BGM.stop
      $game_system.battle_end_me.play
    end
    
    unless $BTEST
      $game_temp.map_bgm.play
      $game_temp.map_bgs.play
    end
    display_exp_and_gold
    display_drop_items
    display_level_up
    battle_end(0)
  end


======================

To use this, just create an event script call and use the following line:
CODE
$game_system.battle_bgm_enabled = true/false



If anyone has an easier way to implement this or critique, you're more than welcome. I'm still new to RGSS2. wink.gif
Rory
I made a new "Click" sound which fits perfectly.
SeeYouAlways
Share? biggrin.gif
Rory
Okay, its not that fancy, just sounds like words are coming out. smile.gif



Try using intervals of 1 or 2, it sounds cool
neclords
Great!!
user3k
thanks
Nechi
CODE
#========================================
# Edit Character Color For RMVX
# By Nechigawara Sanzenin
#========================================
=begin
Edit Charater Color in Map
How to Use : Add these text to comment in the event page
[r.....] For Red Channal ( -255 to 255 )
[g....] For Green Channal ( -255 to 255 )
[b....] For Blue Channal ( -255 to 255 )
[al...] For Alpha Channal ( 0 to 255 )
[hue...] For Hue Changer ( 0 to 360 )
=end

module Cache
def self.character(filename , hue=0)
    load_bitmap("Graphics/Characters/", filename , hue)
  end
end

class Game_Character
  attr_accessor :tone
  attr_accessor :hue
  #--------------------------------------------------------------------------
  # - Object initialization
  #--------------------------------------------------------------------------
  alias inc_initialize initialize
  def initialize
    inc_initialize
    @tone = [0,0,0,0]
    @hue = 0
  end
end

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

class Game_Event < Game_Character
    
  alias inc_update update
  def update
    # check Code
    for i in 0...@list.size
      next if @list[i].code != 108
      # For Red Channel
      if @list[i].parameters[0].include?("[r")
        text = @list[i].parameters[0].scan(/\[r([-,0-9]+)\]/)
        red = $1.to_i
        if red > 255
          red = 255
        elsif red < -255
          red = -255
        end
        @tone[0] = red
      end
      # For Green Channel
      if @list[i].parameters[0].include?("[g")
        text = @list[i].parameters[0].scan(/\[g([-,0-9]+)\]/)
        green = $1.to_i
        if green > 255
          green = 255
        elsif green < -255
          green = -255
        end
        @tone[1] = green
      end
      # For Blue Channel
      if @list[i].parameters[0].include?("[b")
        text = @list[i].parameters[0].scan(/\[b([-,0-9]+)\]/)
        blue = $1.to_i
        if blue > 255
          blue = 255
        elsif blue < -255
          blue = -255
        end
        @tone[2] = blue
      end
      # For Alpha Channel
      if @list[i].parameters[0].include?("[al")
        text = @list[i].parameters[0].scan(/\[al([0-9]+)\]/)
        alpha = $1.to_i
        if alpha > 255
          alpha = 255
        elsif alpha < 0
          alpha = 0
        end
        @tone[3] = alpha
      end
      # For Hue
      if @list[i].parameters[0].include?("[hue")
        text = @list[i].parameters[0].scan(/\[hue([0-9]+)\]/)
        hue = $1.to_i
        if hue > 360
          hue = 360
        elsif hue < 0
          hue = 0
        end
        @hue = hue
      end
    end
    #Load Orginal Update
    inc_update
  end
  #--------------------------------------------------------------------------
end

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

class Sprite_Character < Sprite_Base
  #--------------------------------------------------------------------------
  # - Frame renewal
  #--------------------------------------------------------------------------
  def update_bitmap
    @character.update
    self.tone.set(@character.tone[0],@character.tone[1],@character.tone[2],@character.tone[3])
    if @tile_id != @character.tile_id or
       @character_name != @character.character_name or
       @character_index != @character.character_index or
       @hue != @character.hue
      @tile_id = @character.tile_id
      @character_name = @character.character_name
      @character_index = @character.character_index
      @hue = @character.hue
      if @tile_id > 0
        sx = (@tile_id / 128 % 2 * 8 + @tile_id % 8) * 32;
        sy = @tile_id % 256 / 8 % 16 * 32;
        self.bitmap = tileset_bitmap(@tile_id)
        self.src_rect.set(sx, sy, 32, 32)
        self.ox = 16
        self.oy = 32
      else
        self.bitmap = Cache.character(@character_name,@character.hue)
        sign = @character_name[/^[\!\$]./]
        if sign != nil and sign.include?('$')
          @cw = bitmap.width / 3
          @ch = bitmap.height / 4
        else
          @cw = bitmap.width / 12
          @ch = bitmap.height / 8
        end
        self.ox = @cw / 2
        self.oy = @ch
      end
    end
  end
  
end


Edit Charater Color in Map
How to Use : Add these text to comment in the event page
[r.....] For Red Channal ( -255 to 255 )
[g....] For Green Channal ( -255 to 255 )
[b....] For Blue Channal ( -255 to 255 )
[al...] For Alpha Channal ( 0 to 255 )
[hue...] For Hue Changer ( 0 to 360 )

Demo : http://www.mediafire.com/?oypmynnl9rx

Screen Shot :
woratana
Nice Script~^^ Nechi

It should be good if you have some picture for example of script.
neclords
This Gonna be cool.
neclords
That's will solve our problem.
Thanks
Nechi
Good Tutorial!!
I thinks it 's great for me.
woratana
Random Title Screen
Version 1.0
by Woratana
Release Date: 07/02/2008


Introduction
This script will random your tile screen.
To make player not get bored every time they start game. smile.gif


Features
Version 1.0
- Random title screen from pictures as much as you want


Script
Place it above main.
if you have problem with codebox, you can download script in text file here:
Version 1.0
Click to view attachment

CODE
#======================================================================
========
# ■ [RMVX] +Random Title Screen+
#------------------------------------------------------------------------------
# Version 1.0
# by Woratana [woratana@hotmail.com]
# Release Date: 07/02/2008
#
# This scrip will random title screen
#
# You can set title screen pictures to be random at line:
# Title = ["filename","filename2","filename3",...]
# title screen picture must be in folder "System"
#
# For example, Title = ["Screenfire","Title1"]
# >> Title Screen will random between pictures "Screenfire" and "Title1".
#=============================================================================
class Scene_Title < Scene_Base
Title = Array.new

# Set Title Screen Pictures for random here!
Title = ["Title","Title10","Title25","Title50","Title80"]

def create_title_graphic
@sprite = Sprite.new
title_random = rand(Title.size)
@sprite.bitmap = Cache.system(Title[title_random].to_s)
end
end



Instruction
You can set the pictures that will be in random list for title screen at this line:
CODE
Title = ["filename","filename2","filename3",...]

put your file's name in double quote "filename", and seperate pictures with ,
The file name don't need file type (e.g. .jpg,.png), and must be in folder "System"

For Example,
CODE
Title = ["ice","water","fire","earth"]

The title screen will random between the files "ice" or "water" or "fire" or "earth".

You can add pictures to be random as much as you want laugh.gif


Author's Notes
Free for use in your non-commercial work if credit included. If your project is commercial, please contact me.

Please do not redistribute this script without permission. If you want to post it on any forum, please link to this topic.
neclords
Yay...
this is cool...

biggrin.gif
OrigamiRose
Hey, nice script you got here^^. Altough, I rather sticking with just one title picture tongue.gif
jasonicus
That was quick. This will be nice to use if you want some variety in the title. Especially if you want to show a pic of different characters.
jens009
Hey woratana, excellent script.

I have a few suggestions that might be worth considering when you make future upgrades for this script:
1) Make the title change if a certain actor in the party gain x amount of levels (Of course, other variation of level checks should be considered)
2) If a certain weapon/item/armor/switch/event/ etc. was obtained then change the title screen to something else.


Just some ideas might be worth thinking about.

EDIT: I just realized that you have made a highest level title screen script. I apologize for making this post.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2013 Invision Power Services, Inc.