Advertisement
LiTTleDRAgo

[RGSS2] Drago Simple Mission Script Ver 1

Apr 18th, 2012
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 19.30 KB | None | 0 0
  1. #==============================================================================
  2. # Drago Simple Mission Script
  3. # Version 1.00
  4. # Author : LiTTleDRAgo
  5. #==============================================================================
  6. module LiTTleDRAgo
  7.  
  8.   MISSION = []
  9.  
  10.   # icon = icon index dari iconset
  11.   # Judul = judul dari mission
  12.   # switch = switch yang perlu dinyalakan untuk memunculkan mission
  13.   # variable = [id, result],
  14.   #            kalau value dari variable >= (result) maka mission completed
  15.   #            kalau value dari variable <= (-result) maka mission failed
  16.   # deskripsi = yaa tau sendiri lah
  17.   # commonevent = Common Event yang akan dieksekusi kalau claim reward
  18.  
  19.   MISSION[1] = { "icon"     => 234,  
  20.                  "judul"    => "Find the cat",
  21.                  "switch"   => 4,
  22.                  "variable" => [1,4],
  23.                  "deskripsi" => ["Kucingku hilang, tolong bantu aku mencarinya",
  24.                                  "2nd line",
  25.                                  "3rd line",
  26.                                  "4th line",
  27.                                  "5th line",
  28.                                  "From : Lea"],
  29.                 "commonevent" => 1, }
  30.                  
  31.   MISSION[4] = { "icon"     => 234,
  32.                  "judul"    => "Find the dog",
  33.                  "switch"   => 8,
  34.                  "variable" => [1,4],
  35.                  "deskripsi" => ["Cari anjing sialan itu, hidup atau mati !!",
  36.                                  "Bila ketemu langsung pancung saja kepalanya",
  37.                                  "---",
  38.                                  "",
  39.                                  "",
  40.                                  "From : Kakek penjaga toko"],
  41.                 "commonevent" => 2, }
  42.                                  
  43.   # cara panggil =
  44.   # $scene = Scene_Mission.new
  45.   #
  46.   # cara merubah Available / Accepted di game pakai script
  47.   # $game_self_switches[["MissionAccept",JUDUL DARI MISSION]] = true / false
  48.   #
  49.   # Dibawah cuma konfigurasi string doang, pasti ngerti lah
  50.  
  51.   MISSION_VOCAB = "Silahkan Pilih Mission"
  52.   TEXT_VOCAB    = ["Available", "Accepted", "Completed" , "Failed"]
  53.   COMMAND_VOCAB = ["Accept?"  ,"Abort?", "Claim Reward?"]
  54.  
  55. end
  56.  
  57. #==============================================================================
  58. # ** Dialog system
  59. #------------------------------------------------------------------------------
  60. #  credit to Zeriab
  61. #==============================================================================
  62. class Dialog
  63.   STARTING_Z_VALUE = 1500 # Default value is 1500
  64.   attr_accessor :value
  65.   attr_writer :marked_to_close
  66.   #--------------------------------------------------------------------------
  67.   # * Getter with 'false' as default value
  68.   #--------------------------------------------------------------------------
  69.   def marked_to_close
  70.     @marked_to_close = false  if @marked_to_close.nil?
  71.     return @marked_to_close
  72.   end
  73.   #--------------------------------------------------------------------------
  74.   # * Initialization
  75.   #--------------------------------------------------------------------------
  76.   def mark_to_close
  77.     self.marked_to_close = true
  78.   end
  79.   #--------------------------------------------------------------------------
  80.   # * Show the dialog
  81.   #   Returns the value from the dialog
  82.   #--------------------------------------------------------------------------
  83.   def self.show(*args, &block)
  84.     dialog = self.new(*args, &block)
  85.     dialog.marked_to_close = false
  86.     return dialog.main
  87.   end
  88.   #--------------------------------------------------------------------------
  89.   # * Initialization
  90.   #--------------------------------------------------------------------------
  91.   def initialize(*args, &block)
  92.     # For subclasses to overwrite
  93.   end
  94.   #--------------------------------------------------------------------------
  95.   # * Main processing
  96.   #--------------------------------------------------------------------------
  97.   def main
  98.     # Create the dimmed background
  99.     create_background
  100.     # Create Windows
  101.     main_window
  102.     # Main loop
  103.     loop do
  104.       # Update game screen
  105.       Graphics.update
  106.       # Update input information
  107.       Input.update
  108.       # Frame update
  109.       update
  110.       # Abort loop if the dialog should close
  111.       if marked_to_close
  112.         break
  113.       end
  114.     end
  115.     # Dispose of windows
  116.     main_dispose
  117.     # Dispose of background
  118.     dispose_background
  119.     # Update input information
  120.     Input.update
  121.     # Returns the acquired value
  122.     return self.value
  123.   end
  124.   #--------------------------------------------------------------------------
  125.   # * Create the dimmed background
  126.   #--------------------------------------------------------------------------
  127.   def create_background
  128.     bitmap = Bitmap.new(640,480)
  129.     bitmap.fill_rect(0,0,640,480,Color.new(0,0,0,128))
  130.     @background_sprite = Sprite.new
  131.     @background_sprite.z = STARTING_Z_VALUE
  132.     @background_sprite.bitmap = bitmap
  133.   end
  134.   #--------------------------------------------------------------------------
  135.   # * Create the windows
  136.   #--------------------------------------------------------------------------
  137.   def main_window
  138.     # For the subclasses to override
  139.     # Remember to set their z.value to at least STARTING_Z_VALUE + 1
  140.   end
  141.   #--------------------------------------------------------------------------
  142.   # * Dispose the background
  143.   #--------------------------------------------------------------------------
  144.   def dispose_background
  145.     @background_sprite.dispose
  146.   end
  147.   #--------------------------------------------------------------------------
  148.   # * Dispose the windows
  149.   #--------------------------------------------------------------------------
  150.   def main_dispose
  151.     # For the subclasses to override
  152.     # Dispose your windows here
  153.   end
  154.   #--------------------------------------------------------------------------
  155.   # * Frame Update
  156.   #--------------------------------------------------------------------------
  157.   def update
  158.     # For the subclasses to override
  159.     if Input.trigger?(Input::B)
  160.       mark_to_close
  161.     end
  162.   end
  163. end
  164. #==============================================================================
  165. # * A Simple Yes/No dialog
  166. #----------------------------------------------------------------------------
  167. #  credit to Zeriab
  168. #==============================================================================
  169. class Dialog_YesNo < Dialog
  170.   # self.value: false = No, true = Yes
  171.  
  172.   #--------------------------------------------------------------------------
  173.   # * A show method
  174.   #--------------------------------------------------------------------------
  175.   def initialize(default_value = false, text = nil)
  176.     # Sets the default value
  177.     self.value = default_value
  178.     @text = text
  179.     # Sets the menu index
  180.     if default_value
  181.       @menu_index = 0
  182.     else
  183.       @menu_index = 1
  184.     end
  185.   end
  186.   #--------------------------------------------------------------------------
  187.   # * Create the windows
  188.   #--------------------------------------------------------------------------
  189.   def main_window
  190.     @disposables = []
  191.    
  192.     # The command window
  193.     @command_window = Window_Command.new(80, ['Yes', 'No'])
  194.     @command_window.index = @menu_index
  195.     @command_window.x = (640 - @command_window.width) / 2
  196.     @command_window.y = (480 - @command_window.height) / 2
  197.     @command_window.z = STARTING_Z_VALUE + 1
  198.     @disposables << @command_window
  199.    
  200.     # The text window
  201.     if @text.is_a?(String)
  202.       @text_window = Window_Help.new
  203.       @text_window.set_text(@text, 1)
  204.       @text_window.z = STARTING_Z_VALUE + 1
  205.       @disposables << @text_window
  206.     end
  207.   end
  208.   #--------------------------------------------------------------------------
  209.   # * Dispose the windows
  210.   #--------------------------------------------------------------------------
  211.   def main_dispose
  212.     @disposables.each {|element| element.dispose}
  213.   end
  214.   #--------------------------------------------------------------------------
  215.   # * Frame Update
  216.   #--------------------------------------------------------------------------
  217.   def update
  218.     @command_window.update
  219.     if Input.trigger?(Input::B)
  220.       mark_to_close
  221.     end
  222.     if Input.trigger?(Input::C)
  223.       if @command_window.index == 0
  224.         self.value = true
  225.       else
  226.         self.value = false
  227.       end
  228.       mark_to_close
  229.     end
  230.   end
  231. end
  232. #==============================================================================
  233. # ** Window_Item
  234. #------------------------------------------------------------------------------
  235. #  This window displays a list of inventory items for the item screen, etc.
  236. #==============================================================================
  237.  
  238. class Window_Mission < Window_Selectable
  239.  
  240.   #--------------------------------------------------------------------------
  241.   # * Object Initialization
  242.   #     x      : window x-coordinate
  243.   #     y      : window y-coordinate
  244.   #     width  : window width
  245.   #     height : window height
  246.   #--------------------------------------------------------------------------
  247.   def initialize(x, y, width, height)
  248.     super(x, y, width, height)
  249.     @column_max = 1
  250.     self.index = 0
  251.     refresh
  252.   end
  253.   #--------------------------------------------------------------------------
  254.   # * Get Item
  255.   #--------------------------------------------------------------------------
  256.   def item
  257.     return @data[self.index]
  258.   end
  259.   #--------------------------------------------------------------------------
  260.   # * Whether or not to include in item list
  261.   #     item : item
  262.   #--------------------------------------------------------------------------
  263.   def include?(item)
  264.     return false if item == nil
  265.     return false if !$game_switches[item["switch"]]
  266.     return true
  267.   end
  268.   #--------------------------------------------------------------------------
  269.   # * Whether or not to display in enabled state
  270.   #     item : item
  271.   #--------------------------------------------------------------------------
  272.   def enable?(item)
  273.     return true
  274.   end
  275.   #--------------------------------------------------------------------------
  276.   # * Refresh
  277.   #--------------------------------------------------------------------------
  278.   def refresh
  279.     @data = []
  280.     (0..LiTTleDRAgo::MISSION.size).each {|i|
  281.       next unless include?(LiTTleDRAgo::MISSION[i])
  282.       @data.push(LiTTleDRAgo::MISSION[i])
  283.     }
  284.     @data.push(nil) if include?(nil)
  285.     @item_max = @data.size
  286.     create_contents
  287.     for i in 0...@item_max
  288.       draw_item(i)
  289.     end
  290.   end
  291.   #--------------------------------------------------------------------------
  292.   # * Draw Item
  293.   #     index : item number
  294.   #--------------------------------------------------------------------------
  295.   def draw_item(index)
  296.     rect = item_rect(index)
  297.     self.contents.clear_rect(rect)
  298.     item = @data[index]
  299.     if item != nil
  300.       enabled = enable?(item)
  301.       rect.width -= 4
  302.       draw_icon(item["icon"], rect.x, rect.y, enabled)
  303.       self.contents.draw_text(rect.x+24, rect.y, rect.width, WLH, item["judul"])
  304.     end
  305.   end
  306.   #--------------------------------------------------------------------------
  307.   # * Update Help Text
  308.   #--------------------------------------------------------------------------
  309.   def update_help
  310.     @help_window.set_text(LiTTleDRAgo::MISSION_VOCAB)
  311.   end
  312. end
  313.  
  314. #==============================================================================
  315. # ** Window_Status
  316. #------------------------------------------------------------------------------
  317. #  This window displays full status specs on the status screen.
  318. #==============================================================================
  319.  
  320. class Window_MissionStatus < Window_Base
  321.   #--------------------------------------------------------------------------
  322.   # * Object Initialization
  323.   #     actor : actor
  324.   #--------------------------------------------------------------------------
  325.   def initialize(x, y, width, height)
  326.     super(x, y, width, height)
  327.     refresh
  328.   end
  329.   #--------------------------------------------------------------------------
  330.   # * Refresh
  331.   #--------------------------------------------------------------------------
  332.   def refresh(s=nil)
  333.     self.contents.clear
  334.     return if s.nil?
  335.     text = [s["deskripsi"],$game_self_switches[["MissionAccept",s["judul"]]],[]]
  336.    
  337.     self.contents.draw_text(0, 4+24*0, 284, WLH, text[0][0])
  338.     self.contents.draw_text(0, 4+24*1, 284, WLH, text[0][1])
  339.     self.contents.draw_text(0, 4+24*2, 284, WLH, text[0][2])
  340.     self.contents.draw_text(0, 4+24*3, 284, WLH, text[0][3])
  341.     self.contents.draw_text(0, 4+24*4, 284, WLH, text[0][4])
  342.     self.contents.draw_text(0, 4+24*5, 284, WLH, text[0][5])
  343.    
  344.     if $game_variables[s["variable"][0]] >= s["variable"][1]
  345.       text[2] = LiTTleDRAgo::TEXT_VOCAB[2]
  346.     elsif $game_variables[s["variable"][0]] <= (s["variable"][1]*-1)
  347.       text[2] = LiTTleDRAgo::TEXT_VOCAB[3]
  348.     else
  349.       text[2] = text[1] ? LiTTleDRAgo::TEXT_VOCAB[1] : LiTTleDRAgo::TEXT_VOCAB[0]
  350.     end
  351.     self.contents.draw_text(0, 300, 310, WLH, text[2],2)
  352.    
  353.   end
  354. end
  355.  
  356.  
  357. #==============================================================================
  358. # ** Scene_Item
  359. #------------------------------------------------------------------------------
  360. #  This class performs the item screen processing.
  361. #==============================================================================
  362.  
  363. class Scene_Mission < Scene_Base
  364.   #--------------------------------------------------------------------------
  365.   # * Start processing
  366.   #--------------------------------------------------------------------------
  367.   def start
  368.     super
  369.     create_menu_background
  370.     @viewport = Viewport.new(0, 0, 544, 416)
  371.     @help_window = Window_Help.new
  372.     @help_window.viewport = @viewport
  373.     @item_window = Window_Mission.new(0, 56, 544-360, 360)
  374.     @item_window.viewport = @viewport
  375.     @item_window.help_window = @help_window
  376.     @item_window.active = false
  377.     @target_window = Window_MissionStatus.new(544-360, 56, 360, 360)
  378.     hide_target_window
  379.   end
  380.   #--------------------------------------------------------------------------
  381.   # * Termination Processing
  382.   #--------------------------------------------------------------------------
  383.   def terminate
  384.     super
  385.     dispose_menu_background
  386.     @viewport.dispose
  387.     @help_window.dispose
  388.     @item_window.dispose
  389.     @target_window.dispose
  390.   end
  391.   #--------------------------------------------------------------------------
  392.   # * Return to Original Screen
  393.   #--------------------------------------------------------------------------
  394.   def return_scene
  395.     $scene = Scene_Menu.new(0)
  396.   end
  397.   #--------------------------------------------------------------------------
  398.   # * Update Frame
  399.   #--------------------------------------------------------------------------
  400.   def update
  401.     super
  402.     update_menu_background
  403.     @help_window.update
  404.     [@item_window,@target_window].each {|w| w.update}
  405.     if @item_window.active
  406.       update_item_selection
  407.     elsif @target_window.active
  408.       update_target_selection
  409.     end
  410.   end
  411.   #--------------------------------------------------------------------------
  412.   # * Update Item Selection
  413.   #--------------------------------------------------------------------------
  414.   def update_item_selection
  415.     if Input.trigger?(Input::B)
  416.       Sound.play_cancel
  417.       return_scene
  418.     elsif Input.trigger?(Input::C)
  419.       @item = @item_window.item
  420.       if @item != nil && $game_switches[@item["switch"]]
  421.         Sound.play_decision
  422.         determine_item
  423.       else
  424.         Sound.play_buzzer
  425.       end
  426.     end
  427.   end
  428.   #--------------------------------------------------------------------------
  429.   # * Confirm Item
  430.   #--------------------------------------------------------------------------
  431.   def determine_item
  432.     show_target_window(@item_window.index % 2 == 0)
  433.   end
  434.   #--------------------------------------------------------------------------
  435.   # * Update Target Selection
  436.   #--------------------------------------------------------------------------
  437.   def update_target_selection
  438.     if Input.trigger?(Input::B)
  439.       Sound.play_cancel
  440.       @item_window.refresh    
  441.       hide_target_window
  442.     elsif Input.trigger?(Input::C)
  443.      
  444.       if @item == nil
  445.         Sound.play_buzzer
  446.       elsif $game_variables[@item["variable"][0]] >= @item["variable"][1]
  447.         if !$game_self_switches[["MissionReward",@item["judul"]]]
  448.           Sound.play_decision
  449.           v = Dialog_YesNo.show(true, LiTTleDRAgo::COMMAND_VOCAB[2])
  450.           if v
  451.             $game_self_switches[["MissionReward",@item["judul"]]] = true
  452.             Sound.play_decision
  453.             @target_window.refresh(@item)
  454.             $game_temp.common_event_id = @item["commonevent"]
  455.             $scene = Scene_Map.new
  456.           else
  457.             Sound.play_buzzer
  458.           end
  459.         else
  460.           Sound.play_buzzer
  461.         end
  462.       elsif $game_variables[@item["variable"][0]] <= (@item["variable"][1]*-1)
  463.         Sound.play_buzzer
  464.       else
  465.         if !$game_self_switches[["MissionAccept",@item["judul"]]]
  466.           Sound.play_decision
  467.           v = Dialog_YesNo.show(true, LiTTleDRAgo::COMMAND_VOCAB[0])
  468.           if v
  469.             $game_self_switches[["MissionAccept",@item["judul"]]] = true
  470.             Sound.play_decision
  471.             @target_window.refresh(@item)
  472.           else
  473.             Sound.play_buzzer
  474.           end
  475.         else
  476.           Sound.play_decision
  477.           v = Dialog_YesNo.show(true, LiTTleDRAgo::COMMAND_VOCAB[1])
  478.           if v
  479.             $game_self_switches[["MissionAccept",@item["judul"]]] = false
  480.             Sound.play_decision
  481.             @target_window.refresh(@item)
  482.           else
  483.             Sound.play_buzzer
  484.           end
  485.         end    
  486.       end
  487.     end
  488.   end
  489.   #--------------------------------------------------------------------------
  490.   # * Confirm Target
  491.   #    If there is no effect (such as using a potion on an incapacitated
  492.   #    character), play a buzzer SE.
  493.   #--------------------------------------------------------------------------
  494.   def determine_target
  495.     used = false
  496.     if @item.for_all?
  497.       for target in $game_party.members
  498.         target.item_effect(target, @item)
  499.         used = true unless target.skipped
  500.       end
  501.     else
  502.       $game_party.last_target_index = @target_window.index
  503.       target = $game_party.members[@target_window.index]
  504.       target.item_effect(target, @item)
  505.       used = true unless target.skipped
  506.     end
  507.     if used
  508.       use_item_nontarget
  509.     else
  510.       Sound.play_buzzer
  511.     end
  512.   end
  513.   #--------------------------------------------------------------------------
  514.   # * Show Target Window
  515.   #     right : Right justification flag (if false, left justification)
  516.   #--------------------------------------------------------------------------
  517.   def show_target_window(right)
  518.     @item_window.active = false
  519.     @target_window.visible = true
  520.     @target_window.active = true
  521.     @target_window.refresh(@item)
  522.   end
  523.   #--------------------------------------------------------------------------
  524.   # * Hide Target Window
  525.   #--------------------------------------------------------------------------
  526.   def hide_target_window
  527.     @item_window.active = true
  528.     @target_window.visible = false
  529.     @target_window.active = false
  530.     @viewport.rect.set(0, 0, 544, 416)
  531.     @viewport.ox = 0
  532.   end
  533. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement