Код:
#==========================================================================
# Скрипт СУНДУК Автор: Sirius (Светлый) aka Naruto (GDSA~ПВЫФ)
# Версия: 1.0
# Скрипт добавляет в игру хранилища предметов:
# сундуки, ящики, шкафы, NPC и т.д.
#--------------------------------------------------------------------------
# Другими словами, взаимодействие с сундуками происходит в двустороннем
# режиме. Как в BaldursGate, Neverwinter, Morrowind и т.п.
# Из сундука можно как брать предметы, так и класть в него.
# Добавленна возможность класть в сундук большие суммы золота.
# При выборе предмета вы перемещаете ОДИН предмет. А вот золото
# перемещается все сразу.
#--------------------------------------------------------------------------
# Для открытия сундука вставьте код ==> $scene=Scene_Chest.new(X,Y)
# Где X ID карты а У ID эвента Пример: $scene=Scene_Chest.new(10,36)
# где 10 ID карты а 36 ID эвента
#--------------------------------------------------------------------------
# Для добавления предметов в сундук используйте следующий код для каждого
# предмета : $chest[[X,Y,Z]]=[A,B,C] Где X ID карты, Y ID эвента, а Z
# номер этого предмета в сундуке. Далее, А это тип предмета 0 - Item,
# 1 - Weapon, 2 - Armor, B это ID предмета, и, наконец, С это количество
# этого предмета.
# Например, давайте создадим сундук с двумя предметами:
# $chest[[1,4,1]]=[0,1,10]
# $chest[[1,4,2]]=[1,8,1]
# $scene=Scene_Chest.new(1,4)
# Как вы уже догадались, мы создали сундук на карте с ID 1 и в Эвенте с ID 4
# первый предмет простой, с ID 1 в количестве 10 штук, второй это оружие
# с ID 8 в количестве одной штуки.
#--------------------------------------------------------------------------
# Теперь я расскажу про то, как создать золото:
# 1. Что делать необязательно:
# Создайте обычный предмет (Область действия: нет Доступность: никогда)
# Назовите его "Золото" и вставьте описание для золота.
# 2. Что делать обязательно:
# Внесите ID этого предмета в переменную $chest_gold Например:
# $chest_gold = [22,23]
# И количество монет укажите в заметках (Note)
# Данные=>База данных=>Вещи=>Заметки
#===========================================================================
$chest = {} #Это глобальная переменная Сундука
$ch_key = [ ] #массив для проверки на наличие ключевых предметов в сундуках.
$chest_gold = [ ] # Здесь указывайте ID предметов, являющихся золотом
class Scene_Chest < Scene_Base
#--------------------------------------------------------------------------
# * Object Initialization
# event :ID Эвента
# map_id:ID карты
#--------------------------------------------------------------------------
def initialize( map_id, event_id)
@event_id = event_id
@map_id = map_id
@k = 0
@n = 0
@temp = 0
@item = 0
@array = []
@val = nil
end
def start
super
create_menu_background
@help_window = Window_Help.new
@Window_Chest = Window_Chest.new(@event_id)
@Window_Actor = Window_Actor.new
@Window_Chest_cont = Window_Chest_cont.new(@map_id, @event_id)
@Window_Chest_cont.help_window = @help_window
@Window_Actors_cont = Window_Actors_cont.new
@Window_Chest_cont.active = true
@Window_Actors_cont.active = false
create_choise_window
hide_choise_window
end
#--------------------------------------------------------------------------
# * Return to Original Screen
#--------------------------------------------------------------------------
def return_scene
$scene = Scene_Map.new
end
#--------------------------------------------------------------------------
# * Termination Processing
#--------------------------------------------------------------------------
def terminate
super
dispose_menu_background
@help_window.dispose
@Window_Chest.dispose
@Window_Actor.dispose
@Window_Chest_cont.dispose
@Window_Actors_cont.dispose
@Window_choise.dispose
end
#--------------------------------------------------------------------------
# * Update Frame
#--------------------------------------------------------------------------
def update
super
update_menu_background
@help_window.update
@Window_Chest_cont.update
@Window_Actors_cont.update
@Window_choise.update
if @Window_Chest_cont.active
@Window_Chest_cont.help_window = @help_window
update_chest_item_selection
elsif @Window_Actors_cont.active
@Window_Actors_cont.help_window = @help_window
update_party_item_selection
elsif @Window_choise.active
update_choise_selection
end
end
#--------------------------------------------------------------------------
# * Update Chest Item Selection
#--------------------------------------------------------------------------
def update_chest_item_selection
if Input.trigger?(Input::B)
Sound.play_cancel
@Window_choise.visible = true
@Window_choise.active = true
@Window_Chest_cont.active = false
elsif Input.trigger?(Input::C)
@item = @Window_Chest_cont.item
chest_lose_item
end
end
#--------------------------------------------------------------------------
# * Update Party Item Selection
#--------------------------------------------------------------------------
def update_party_item_selection
if Input.trigger?(Input::B)
Sound.play_cancel
@Window_choise.visible = true
@Window_choise.active = true
@Window_Actors_cont.active = false
elsif Input.trigger?(Input::C)
@item = @Window_Actors_cont.item
chest_gain_item
end
end
#--------------------------------------------------------------------------
# * Создание окна выбора
#--------------------------------------------------------------------------
def create_choise_window
c1 = "Забрать"
c2 = "Положить"
@Window_choise = Window_choise.new([c1, c2])
@Window_choise.index = 0
end
#--------------------------------------------------------------------------
# * Update Choise Selection
#--------------------------------------------------------------------------
def update_choise_selection
if Input.trigger?(Input::B)
Sound.play_cancel
$scene = Scene_Map.new
elsif Input.trigger?(Input::C)
Sound.play_decision
case @Window_choise.index
when 0 # @Window_Chest_cont.active = true
@Window_Chest_cont.active = true
hide_choise_window
when 1 # @Window_Actors_cont.active = true
@Window_Actors_cont.active = true
hide_choise_window
end
end
end
#--------------------------------------------------------------------------
# * Hide Choise Window
#--------------------------------------------------------------------------
def hide_choise_window
@Window_choise.active = false
@Window_choise.visible = false
end
#--------------------------------------------------------------------------
# * Взятие предмета из сундука
#--------------------------------------------------------------------------
def chest_lose_item
# p $chest.values
# p $chest.keys
if @item != nil
$game_party.last_item_id = @item.id
$game_party.gain_item(@item, 1)
Sound.play_equip
for i in 0..$chest_items.size-1
if $chest_items[i] == @item
@n = i + 1
end
end
@k = [@map_id, @event_id, @n]
@temp = $chest[@k]
if @temp[2] <= 1
@array = []
$chest.delete(@k)
$chest.each_key{|key| if key[0]==@map_id and key[1]==@event_id and key[2] > @n then @array.push(key[2]) end}
for i in @array.sort
@key = [@map_id, @event_id, i]
@new_key = [@map_id, @event_id, i-1]
@value = $chest[@key]
$chest[@new_key] = @value
$chest.delete(@key)
end
else
@temp[2]-=1
$chest[@k] = @temp
end
@Window_Actors_cont.refresh
@Window_Chest_cont.refresh
end
end
#--------------------------------------------------------------------------
# * Перенос предмета в сундук
#--------------------------------------------------------------------------
def chest_gain_item
if @item != nil
$game_party.last_item_id = @item.id
$game_party.lose_item(@item, 1)
Sound.play_equip
@val = nil
for i in 0..$chest_items.size-1
if $chest_items[i] == @item
@temp_kv = [@map_id, @event_id, i+1]
@val = $chest[@temp_kv]
end
end
@array = []
if @val == nil
$chest.each_key{|key| if key[0]==@map_id and key[1]==@event_id then @array.push(key[2]) end}
unless @array.empty?
@temp = [@map_id, @event_id, @array.max+1]
else
@temp = [@map_id, @event_id, 1]
end
if $data_items.include?(@item)
@type = 0
elsif $data_weapons.include?(@item)
@type = 1
elsif $data_armors.include?(@item)
@type = 2
end
$chest[@temp] = [@type, @item.id, 1]
else
@val[2]+=1
$chest[@temp_kv] = @val
end
@Window_Actors_cont.refresh
@Window_Chest_cont.refresh
end
end
end
#----------------------------------------------------------------------
#**ОКНО С ИМЕНЕМ ЭВЕНТА
#----------------------------------------------------------------------
class Window_Chest < Window_Base
#--------------------------------------------------------------------------
# * Object Initialization
# event :ID Эвента
#--------------------------------------------------------------------------
def initialize (event)
@event =$game_map.events[event]
# @cn = @event.character_name
# @ci = @event.character_index
super(0, 56, 544, 56)
refresh
end
def refresh
# self.contents.clear
self.contents.draw_text(0, 0, 500, 24, @event.event_name, 1)
# draw_character(@cn, @ci, 100, 30)
end
end
#--------------------------------------------------------------------------
# * Содержание сундука
#--------------------------------------------------------------------------
class Window_Chest_cont < Window_Selectable
#--------------------------------------------------------------------------
# * Object Initialization
# x : window x-coordinate
# y : window y-coordinate
# width : window width
# height : window height
#--------------------------------------------------------------------------
def initialize( map_id, event_id)
@map_id = map_id # ID Карты
@event_id = event_id # ID Эвента
@chest_last_item_id = 0 # Номер последнего предмета
$chest_items =[]
super(0, 112, 544, 124)
@column_max = 2
self.index = 0
refresh
end
#--------------------------------------------------------------------------
# * Создание массива предметов
#--------------------------------------------------------------------------
def create_chest_item
$chest_items =[] # Массив предметов в сундуке
@numbers_hash ={} # Хэш количества предметов(Ключи сами предметы)
@chest_ietm_number = [] # Массив, последовательности предметов в сундуке
$chest.each_key {|k| if k[0]==@map_id && k[1]==@event_id then @chest_ietm_number.push(k[2]) end}
@m = @chest_ietm_number.max # @m максимальный номер предмета в сундуке (не ID!)
for i in @chest_ietm_number.sort
@t = [@map_id, @event_id, i]
@temp = $chest[@t] # @temp временная переменная
unless @temp == nil
case @temp.at(0)
when 0
$chest_items.push($data_items[@temp[1]])
@numbers_hash [$data_items[@temp[1]]] = @temp[2]
if i == @m
@chest_last_item_id = $data_items[@temp[1]].id
end
when 1
$chest_items.push($data_weapons[@temp[1]])
@numbers_hash [$data_weapons[@temp[1]]] = @temp[2]
if i == @m
@chest_last_item_id = $data_weapons[@temp[1]].id
end
when 2
$chest_items.push($data_armors[@temp[1]])
@numbers_hash [$data_armors[@temp[1]]] = @temp[2]
if i == @m
@chest_last_item_id = $data_armors[@temp[1]].id
end
end
end
end
end
#--------------------------------------------------------------------------
# * Get Item
#--------------------------------------------------------------------------
def item
return @data[self.index]
end
#--------------------------------------------------------------------------
# * Whether or not to include in item list
# item : item
#--------------------------------------------------------------------------
def include?(item)
return false if item == nil
return true
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
create_chest_item
@data = []
for item in $chest_items
next unless include?(item)
@data.push(item)
if item.is_a?(RPG::Item) and item.id == @chest_last_item_id
self.index = @data.size - 1
end
end
@data.push(nil) if include?(nil)
@item_max = @data.size
create_contents
for i in 0...@item_max
draw_item(i)
end
end
#--------------------------------------------------------------------------
# * Draw Item
# index : item number
#--------------------------------------------------------------------------
def draw_item(index)
rect = item_rect(index)
self.contents.clear_rect(rect)
item = @data[index]
if item != nil
number = @numbers_hash[item]
enabled = true
rect.width -= 4
draw_item_name(item, rect.x, rect.y, enabled)
if $chest_gold.include?(item.id)
self.contents.draw_text(rect, sprintf(":%2d", item.note.to_i), 2)
else
self.contents.draw_text(rect, sprintf(":%2d", number), 2)
end
end
end
#--------------------------------------------------------------------------
# * Update Help Text
#--------------------------------------------------------------------------
def update_help
@help_window.set_text(item == nil ? "" : item.description)
end
end
#----------------------------------------------------------------------
#**ОКНО С ИМЕНЕМ ПЕРВОГО ЧЛЕНА ГРУППЫ
#----------------------------------------------------------------------
class Window_Actor < Window_Base
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super(0, 236, 544, 56)
@name= $game_party.members[0].name
# @actor = $game_player.main_actor.name
refresh
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
# self.contents.clear
# draw_actor_name(@actor, 4, 0)
self.contents.draw_text(0, 0, 500, 24, @name, 1)
end
end
#--------------------------------------------------------------------------
# * Содержание инвентаря
#--------------------------------------------------------------------------
class Window_Actors_cont < Window_Selectable
#--------------------------------------------------------------------------
# * Object Initialization
# x : window x-coordinate
# y : window y-coordinate
# width : window width
# height : window height
#--------------------------------------------------------------------------
def initialize
super(0, 292, 544, 124)
@column_max = 2
self.index = 0
refresh
end
#--------------------------------------------------------------------------
# * Get Item
#--------------------------------------------------------------------------
def item
return @data[self.index]
end
#--------------------------------------------------------------------------
# * Whether or not to include in item list
# item : item
#--------------------------------------------------------------------------
def include?(item)
return false if item == nil
if $game_temp.in_battle
return false unless item.is_a?(RPG::Item)
end
return true
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
@data = []
for item in $game_party.items
next unless include?(item)
@data.push(item)
if item.is_a?(RPG::Item) and item.id == $game_party.last_item_id
self.index = @data.size - 1
end
end
@data.push(nil) if include?(nil)
@item_max = @data.size
create_contents
for i in 0...@item_max
draw_item(i)
end
end
#--------------------------------------------------------------------------
# * Draw Item
# index : item number
#--------------------------------------------------------------------------
def draw_item(index)
rect = item_rect(index)
self.contents.clear_rect(rect)
item = @data[index]
if item != nil
number = $game_party.item_number(item)
enabled = true
rect.width -= 4
draw_item_name(item, rect.x, rect.y, enabled)
self.contents.draw_text(rect, sprintf(":%2d", number), 2)
end
end
#--------------------------------------------------------------------------
# * Update Help Text
#--------------------------------------------------------------------------
def update_help
@help_window.set_text(item == nil ? "" : item.description)
end
end
#--------------------------------------------------------------------------
# * Окно выбора
#--------------------------------------------------------------------------
class Window_choise < Window_Selectable
def initialize(commands, column_max = 1, row_max = 0, spacing = 32)
super(178,158, 200, 2 * WLH + 32, spacing)
@commands = commands
@item_max = 2
@column_max = 1
refresh
self.index = 0
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
for i in 0...@item_max
draw_item(i)
end
end
#--------------------------------------------------------------------------
# * Draw Item
# index : item number
# enabled : enabled flag. When false, draw semi-transparently.
#--------------------------------------------------------------------------
def draw_item(index, enabled = true)
rect = item_rect(index)
rect.x += 4
rect.width -= 8
self.contents.clear_rect(rect)
self.contents.font.color = normal_color
self.contents.font.color.alpha = enabled ? 255 : 128
self.contents.draw_text(rect, @commands[index],1)
end
end
#--------------------------------------------------------------------------
# Добавляет Метод Event_name
#--------------------------------------------------------------------------
class Game_Event < Game_Character
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_reader :trigger # trigger
attr_reader :list # list of event commands
attr_reader :starting # starting flag
attr_reader :event_name # Имя эвента
#--------------------------------------------------------------------------
# * Object Initialization
# map_id : map ID
# event : event (RPG::Event)
#--------------------------------------------------------------------------
alias initialize_A initialize
def initialize(map_id, event)
super()
@map_id = map_id
@event = event
@id = @event.id
@erased = false
@starting = false
@through = true
moveto(@event.x, @event.y) # Move to initial position
refresh
@event_name = event.name # Event_name
end
end
#==============================================================================
# ** Game_Party
#------------------------------------------------------------------------------
# This class handles the party. It includes information on amount of gold
# and items. The instance of this class is referenced by $game_party.
#==============================================================================
class Game_Party < Game_Unit
#--------------------------------------------------------------------------
# * Gain Items (or lose)
# item : Item
# n : Number
# include_equip : Include equipped items
#--------------------------------------------------------------------------
alias gain_item_new gain_item
def gain_item(item, n, include_equip = false)
if $chest_gold.include?(item.id) # Если true то предмет является
$game_party.gain_gold(item.note.to_i) # золотом, и перечисляется
else # сразу в золото группы
number = item_number(item)
case item
when RPG::Item
@items[item.id] = [[number + n, 0].max, 99].min
when RPG::Weapon
@weapons[item.id] = [[number + n, 0].max, 99].min
when RPG::Armor
@armors[item.id] = [[number + n, 0].max, 99].min
end
n += number
if include_equip and n < 0
for actor in members
while n < 0 and actor.equips.include?(item)
actor.discard_equip(item)
n += 1
end
end
end
end
end
end
#==============================================================================
# ** Scene_File
#------------------------------------------------------------------------------
# Добавляем переменную $chest в методы сохранения и загрузки
# теперь при перезагрузке сундуки будут "помнить" что в них лежало
#==============================================================================
class Scene_File < Scene_Base
#--------------------------------------------------------------------------
# * Write Save Data
# file : write file object (opened)
#--------------------------------------------------------------------------
alias write_save_data_new write_save_data
def write_save_data(file)
characters = []
for actor in $game_party.members
characters.push([actor.character_name, actor.character_index])
end
$game_system.save_count += 1
$game_system.version_id = $data_system.version_id
@last_bgm = RPG::BGM::last
@last_bgs = RPG::BGS::last
Marshal.dump(characters, file)
Marshal.dump(Graphics.frame_count, file)
Marshal.dump(@last_bgm, file)
Marshal.dump(@last_bgs, file)
Marshal.dump($game_system, file)
Marshal.dump($game_message, file)
Marshal.dump($game_switches, file)
Marshal.dump($game_variables, file)
Marshal.dump($game_self_switches, 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($chest, file)
end
#--------------------------------------------------------------------------
# * Read Save Data
# file : file object for reading (opened)
#--------------------------------------------------------------------------
alias read_save_data_new read_save_data
def read_save_data(file)
characters = Marshal.load(file)
Graphics.frame_count = Marshal.load(file)
@last_bgm = Marshal.load(file)
@last_bgs = Marshal.load(file)
$game_system = Marshal.load(file)
$game_message = Marshal.load(file)
$game_switches = Marshal.load(file)
$game_variables = Marshal.load(file)
$game_self_switches = 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)
$chest = Marshal.load(file)
if $game_system.version_id != $data_system.version_id
$game_map.setup($game_map.map_id)
$game_player.center($game_player.x, $game_player.y)
end
end
end
Социальные закладки