Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # =============================================================================
- # TheoAllen - Select Item Scene
- # Version : 1.0
- # Contact : www.rpgmakerid.com (or) http://theolized.blogspot.com
- # (This script documentation is written in informal indonesian language)
- # =============================================================================
- ($imported ||= {})[:Theo_SelectItem] = true
- # =============================================================================
- # CHANGE LOGS:
- # -----------------------------------------------------------------------------
- # 2013.05.25 - Finished script
- # 2013.05.24 - Started script
- # =============================================================================
- =begin
- Perkenalan :
- Script ini sama seperti halnya show choice. Hanya saja yang dipilih disini
- adalah item.
- Cara penggunaan :
- Pasang di bawah material namun diatas main.
- =============================================================================
- * Script call :
- ----------------------------------------------------------------------------
- MENENTUKAN KONDISI :
- Tulis script call kek gini
- - @item = [1,2,3,4,5] << id dari item
- - @value = [2,5,2,4,3] << jumlah item
- Itu artinya:
- - item dengan id 1 syaratnya berjumlah 2
- - item dengan id 2 syaratnya berjumlah 5
- - item dengan id 3 syaratnya berjumlah 2
- - item dengan id 4 syaratnya berjumlah 4
- - item dengan id 5 syaratnya berjumlah 3
- ----------------------------------------------------------------------------
- PANGGIL SCENE SELECT ITEM :
- - select_item << udah tulis gini ajah :v
- ----------------------------------------------------------------------------
- PANGGIL KONDISI :
- Dalam conditional branch, page 4, pilih yg script. Lalu tulis kek gini
- (pilih aja salah satu)
- - item?(item_id, value, operand_type)
- - item?(item_id, value)
- - item?(item_id)
- - item?
- Pilihan pertama :
- Kamu nentuin kondisinya sendiri dari script call conditional branch. item_id
- adalah id dari item. Value adalah jumlah yg jadi patokannya. operand_type
- adalah tipe pembandingnya. List pembandingnya kek gini.
- - 0 >> Sama dengan
- - 1 >> Lebih besar
- - 2 >> Lebih kecil
- - 3 >> Lebih besar sama dengan
- - 4 >> Lebih kecil sama dengan
- - 5 >> Tidak sama dengan
- Semisal kamu nulisnya @> Script : item?(1,3,3)
- Maka, jika item yang kamu pilih adalah id 1 dengan jumlah lebih dari atau
- sama dengan 3, maka conditional branchnya bener
- Pilihan kedua :
- Kamu cuman nentuin kondisinya item_id ama valuenya doank. operand_type yang
- dipake secara default adalah nomor 3
- Pilihan ketiga :
- Kamu cuman nentuin kondisi item_idnya doank. Value secara default nilainya 1
- Pilihan keempat :
- Kamu ga nentuin kondisi pas manggil ini. Kondisinya otomatis sama kek yg
- diatas. Pake @item ama @value. Cuman jika u pengen operand_typenya laen
- (bukan 3), maka yg harus u tulis kek gini.
- @> Script : item?(@item,@value,1)
- ----------------------------------------------------------------------------
- Contoh penggunaan dalam event kek gini
- ----------------------------------------------------------------------------
- @> Script :@item = [1,2,3,4,5]
- : :@value = [2,5,2,4,3]
- @> Script :select_item
- @> Conditional Branch: Script :item?
- @> # Jika iya eventnya disini
- : else
- @> # Jika ngga eventnya disini
- : Branch end
- @>
- ----------------------------------------------------------------------------
- Terms of use :
- Credit gw, TheoAllen. Kalo semisal u bisa ngedit2 script gw trus jadi lebih
- keren, terserah. Ane bebasin. Asal ngga ngeklaim aja. Dan btw, kalo dipake
- untuk komersial, bagi ane keuntungannya juga. Ama gratisan gamenya juga
- =end
- # =============================================================================
- # Konfigurasi :
- # =============================================================================
- module THEO
- module SELECT
- # =======================================================================
- SELECT_VOCAB = "Select Item"
- # -----------------------------------------------------------------------
- # Kata-kata untuk footer
- # =======================================================================
- # =======================================================================
- LOSE_ITEM = false
- # -----------------------------------------------------------------------
- # Semisal u set true, maka pas u milih barang, barang u otomatis ilang.
- # Semisal u set false, u bisa manual ngilangin barang dari inventory pake
- # script call kek gini.
- #
- # @> Script : lose_item
- # =======================================================================
- # =======================================================================
- SHOW_AMOUNT = true
- AMOUNT_VOCAB = "Amount :"
- AMOUNT_WIDTH = 200
- # -----------------------------------------------------------------------
- # Jika show amount u tulis true, maka akan keluar window amount untuk
- # nentuin berapa banyak item yg u select/pilih. Jika false, otomatis
- # jumlah item yg u pilih nilainya 1
- #
- # Amount vocab : kata2 di window amount
- # Amount width : lebar windownya (default: 200)
- # =======================================================================
- end
- end
- # =============================================================================
- # Akhir dari konfigurasi
- # =============================================================================
- class Game_Interpreter
- alias pre_select_item_init initialize
- def initialize(depth = 0)
- pre_select_item_init(depth)
- init_selected_item
- end
- def init_selected_item
- @item = [0]
- @value = [1]
- end
- def item?(item_ids = @item,value = @value,operand_type = 3)
- item_ids = [item_ids] unless item_ids.is_a?(Array)
- value = [value] unless value.is_a?(Array)
- hash = {}
- item_ids.each_with_index do |id, index|
- hash[id] = value[index].nil? ? 1 : value[index]
- end
- obj_id = $game_temp.selected_item.object.id rescue obj_id = 0
- return hash.any? do |k,v|
- k == obj_id && compare(v,operand_type)
- end
- end
- def compare(v,type)
- amount = $game_temp.item_amount
- case type
- when 0 # sama dengan jumlah
- return amount == v
- when 1 # lebih besar dari jumlah
- return amount > v
- when 2 # lebih kecil dari jumlah
- return amount < v
- when 3 # lebih besar sama dengan jumlah
- return amount >= v
- when 4 # lebih kecil sama dengan jumlah
- return amount <= v
- when 5 # tidak sama dengan jumlah
- return amount != v
- end
- end
- def select_item
- new_command = RPG::EventCommand.new(230,@indent,[1])
- @list.insert(@index+1,new_command)
- SceneManager.call(Scene_SelectItem)
- end
- def lose_item
- return unless $game_temp.selected_item.object
- item = $game_temp.selected_item.object
- amount = $game_temp.item_amount
- $game_party.lose_item(item,amount)
- end
- def gain_item
- return unless $game_temp.selected_item.object
- item = $game_temp.selected_item.object
- amount = $game_temp.item_amount
- $game_party.gain_item(item,amount)
- end
- end
- class Game_Temp
- attr_accessor :item_amount
- attr_reader :selected_item
- alias selected_item_init initialize
- def initialize
- selected_item_init
- @selected_item = Game_BaseItem.new
- @item_amount = 0
- end
- def clear_selected_item
- @selected_item.object = nil
- @item_amount = 0
- end
- end
- class Scene_SelectItem < Scene_MenuBase
- include THEO::SELECT
- def start
- super
- create_help_window
- create_footer_window
- create_window_itemlist
- create_amount_window
- end
- def create_footer_window
- @footer = Window_SelectFooter.new
- @footer.viewport = @viewport
- end
- def create_window_itemlist
- x = 0
- y = @help_window.height
- w = Graphics.width
- h = Graphics.height - y - @footer.height
- @item_window = Window_SelectItem.new(x,y,w,h)
- @item_window.viewport = @viewport
- @item_window.help_window = @help_window
- @item_window.set_handler(:ok, method(:select_item))
- @item_window.set_handler(:cancel, method(:return_scene))
- @item_window.category = :item
- @item_window.activate
- @item_window.select(0)
- end
- def create_amount_window
- @amount_window = Window_SelectAmount.new
- @amount_window.viewport = @viewport
- @amount_window.item_window = @item_window
- end
- def select_item
- if SHOW_AMOUNT
- show_amount
- return
- end
- on_amount_confirm
- end
- def show_amount
- @amount_window.open
- end
- def update
- super
- if @amount_window.open?
- hide_amount if Input.trigger?(:B)
- on_amount_confirm if Input.trigger?(:C)
- end
- end
- def hide_amount
- Sound.play_cancel
- @amount_window.close
- @item_window.activate
- end
- def on_amount_confirm
- Sound.play_ok
- process_save_item
- process_lose_item if LOSE_ITEM
- return_scene
- end
- def process_save_item
- $game_temp.selected_item.object = @item_window.item
- $game_temp.item_amount = @amount_window.amount
- end
- def process_lose_item
- $game_party.lose_item(@item_window.item,@amount_window.amount)
- end
- end
- class Window_SelectFooter < Window_Base
- def initialize
- w = Graphics.width
- h = fitting_height(1)
- x = 0
- y = Graphics.height - h
- super(x,y,w,h)
- refresh
- end
- def refresh
- contents.clear
- draw_text(0,0,contents.width,line_height,THEO::SELECT::SELECT_VOCAB,1)
- end
- end
- class Window_SelectItem < Window_ItemList
- def enable?(item)
- return true
- end
- def item_number(item = @data[index])
- $game_party.item_number(item)
- end
- end
- class Window_SelectAmount < Window_Base
- attr_writer :item_window
- attr_reader :amount
- include THEO::SELECT
- def initialize
- super(0,0,window_width,window_height)
- self.openness = 0
- reset_amount
- update_position
- refresh
- end
- def reset_amount
- @amount = 1
- end
- def open
- super
- reset_amount
- end
- def update_position
- self.x = (Graphics.width / 2) - (self.width / 2)
- self.y = (Graphics.height / 2) - (self.height / 2)
- end
- def refresh
- contents.clear
- draw_text(0,0,contents.width,24,AMOUNT_VOCAB)
- draw_text(0,0,contents.width,24,@amount,2)
- end
- def window_width
- return AMOUNT_WIDTH
- end
- def window_height
- return 24+24
- end
- def update
- super
- if open?
- increment if Input.repeat?(:RIGHT)
- decrement if Input.repeat?(:LEFT)
- ten_increment if Input.repeat?(:UP)
- ten_decrement if Input.repeat?(:DOWN)
- end
- end
- def increment
- change_amount(1)
- end
- def decrement
- change_amount(-1)
- end
- def ten_increment
- change_amount(10)
- end
- def ten_decrement
- change_amount(-10)
- end
- def change_amount(modifier)
- @amount = [[@amount+modifier,1].max,max_amount].min
- refresh
- end
- def show
- super
- reset_amount
- end
- def max_amount
- @item_window.item_number rescue 0
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment