Hi all, i've been trying to get this script to work for a while but i'm really having trouble with it.
I used SephirothSpawn's 'Storage box' script as referance to make this one. Bear in mind, I don't understand every single thing i've written in here, I only get all the basic things. Most of the things I haven't understood are the movement of the windows and such; and other things but I don't know how to explain them.
The problem:
When the scene is called, the windows appear (As they should) and it all works fine. Until I actually try and deposit an item; it just cancels the scene. There's no error message or anything, because it doesn't call one. It just stops the scene.
So far, I only know about that error because I haven't actually been able to deposit anything in order to withdraw it.
I'm thinking my problem is that when the 'Deposit' and 'Deposit everything' command is called, it just does nothing (Thus ending the scene). But I can't even remember where I put it in the script (Last time I looked at it was a month ago). As I said, withdraw commands have't been tested yet because I haven't been able to deposit.
Sephiroth would probably be best to answer this, considering I used his script as referance and to some extent, guidance in making mine.
Note:
~This is just for items. Not weapons/armour/gold.
~I am a noob scripter, this is my first script that doesn't consist of just windows or menus.
Thanks to anybody who can fix/help me with it :$
I used SephirothSpawn's 'Storage box' script as referance to make this one. Bear in mind, I don't understand every single thing i've written in here, I only get all the basic things. Most of the things I haven't understood are the movement of the windows and such; and other things but I don't know how to explain them.
The problem:
When the scene is called, the windows appear (As they should) and it all works fine. Until I actually try and deposit an item; it just cancels the scene. There's no error message or anything, because it doesn't call one. It just stops the scene.
So far, I only know about that error because I haven't actually been able to deposit anything in order to withdraw it.
I'm thinking my problem is that when the 'Deposit' and 'Deposit everything' command is called, it just does nothing (Thus ending the scene). But I can't even remember where I put it in the script (Last time I looked at it was a month ago). As I said, withdraw commands have't been tested yet because I haven't been able to deposit.
Sephiroth would probably be best to answer this, considering I used his script as referance and to some extent, guidance in making mine.
Code:
#================================
# chest - By HamsterMan (Skyline)
# Last updated - 1/08/06
#================================
class Game_Chest
attr_reader :id
attr_reader :name
attr_reader :deposited_items
attr_reader :main_commands
attr_reader :deposit_commands
attr_reader :withdraw_commands
def initialize(id, name = "Chest #{id}", items = {},
main_commands = ['Deposit', 'Withdraw', 'Cancel'],
deposit_commands = ['One', 'Everything'].collect! {|x| "Deposit #{x}"} << 'Return',
withdraw_commands = ['One', 'Everything'].collect! {|x| "Withdraw #{x}"} << 'Return')
@id, @name = id, name
@deposited_items = items
@main_commands = main_commands
@deposit_commands = deposit_commands
@withdraw_commands = withdraw_commands
end
#--------------------------------
def total_items
n = 0
@deposited_items.values.each {|x| n += x}
return n
end
#--------------------------------
def item_number
return @deposited_items.has_key? (item_id) ?
@deposited_items[item_id] : 0
end
#--------------------------------
def deposit_item(item_id, number)
unless @deposited_items.has_key?(item_id)
@deposited_items[item_id] = 0
end
@deposited_items[item_id] += number
$game_party.lose_item(item_id, number)
end
#--------------------------------
def deposit_all_items
$game_party.items.each do |item_id, number|
deposit_item(item_id, number)
end
end
#--------------------------------
def withdraw_item(item_id, number)
@deposited_items[item_id] -= number
$game_party.gain_item(item_id, number)
end
#--------------------------------
def withdraw_all_items
@deposited_items.each do |item_id, number|
self.withdraw_item(item_id, number)
end
end
#--------------------------------
def make_item_list
list = []
for i in 1...$data_item.size
if self.item_number(i) > 0
list << i
end
end
return list << 'Back'
end
end
#================================
# Start editing here!
# Guide to make your own boxes:
# ~Comma after Game_Chest.new(1)
# ~Make new 'chest' using:
# ~Game_Chest.new(ID)
# ~Call the box number using:
# ~$scene = Scene_Chest.new(ID)
#--------------------------------
module Chest
Chest = [nil, Game_Chest.new(1)]
end
#================================
class Game_Party
attr_reader :items
end
#================================
class Scene_Title
alias hamsterman_skyline_chest_cng command_new_game
def command_new_game
hamsterman_skyline_chest_cng
$game_chest = Chest::Chest.dup
end
end
#================================
class Scene_Save
alias hamsterman_skyline_chest_wd write_save_data
def write_data(file)
hamsterman_skyline_chest_wd(file)
Marshal.dump($game_chest, file)
end
end
#================================
class Scene_Load
alias hamsterman_skyline_chest_rd read_save_data
def load_data(file)
hamsterman_skyline_chest_rd(file)
$game_chest = Marshal.load(file)
end
end
#================================
class Window_Chest < Window_Base
def initialize(box_id)
super(640, 272, 224, 192)
self.contents = Bitmap.new(width - 32, height - 32)
self.opacity = 160
@box = $game_chest[box_id]
refresh
end
def refresh
self.contents.clear
self.contents.font.color = system_color
self.contents.draw_text(4, 64, 192, 32, 'Deposited items:')
self.contents.font.color = normal_color
self.contents.draw_text(-4, 64, 192, 32, @box.total_items.to_s, 2)
end
end
#================================
class Window_ChestItems < Window_Selectable
def initialize(box_id)
super(- 320, 96, 320, 160)
self.active = false
self.opacity = 160
@box = $game_chest[box_id]
end
def item
return @data[self.index]
end
def item_name
if @data[self.index] == 'Return'
return @data[self.index]
else
return 'Withdraw ' + @data[self.index].name
end
end
def refresh(type = @type)
@type = type
if self.contents != nil
self.contents.dispose
self.contents = nil
end
@data = []
if type == 0 || type == 1
for i in 1...$data_items.size
if @box.item_number(i) > 0
@data << $data_items[i]
end
end
end
@data << 'Return'
@item_max = @data.size
self.index = 0
self.height = 32 + @item_max * 32
if @item_max > 0
self.contents = Bitmap.new(288, @item_max * 32)
for i in 0...@item_max
draw_item(i)
end
end
end
def draw_item(index)
item, y = @data[index], 32 * index
if item == 'Return'
self.contents.draw_text(0, y, contents.width, 32, item, 1)
return
end
case item
when RPG::Item
number = @box.item_number(item.id)
end
bitmap = RPG::Cache.icon(item.icon_name)
self.contents.blt(4, y + 4, bitmap, Rect.new(0, 0, 24, 24))
self.contents.draw_text(32, y, contents.width - 32, 32, item.name)
self.contents.draw_text(contents.width - 32, y, 16, 32, ':')
self.contents.draw_text(-4, y, contents.width, 32, number.to_s, 2)
end
end
#===============================
class Window_PartyItems < Window_Selectable
def initialize
super(- 320, 96, 320, 160)
self.active = false
self.opacity = 160
end
def item
return @data[self.index]
end
def item_name
if @data[self.index] == 'Return'
return @data[self.index]
else
return 'Deposit ' + @data[self.index].name
end
end
#-----------------------------
def refresh(type = @type)
@type = type
if self.contents != nil
self.contents.dispose
self.contents = nil
end
@data = []
if type == 0 || type == 1
for i in 1...$data_items.size
if $game_party.item_number(i) > 0
@data << $data_items[i]
end
end
end
@data << 'Return'
@item_max = @data.size
self.index = 0
self.height = 32 + @item_max * 32
if @item_max > 0
self.contents = Bitmap.new(288, @item_max * 32)
for i in 0...@item_max
draw_item(i)
end
end
end
#-----------------------------
def draw_item(index)
item, y = @data[index], 32 * index
if item == 'Return'
self.contents.draw_text(0, y, contents.width, 32, item, 1)
return
end
case item
when RPG::Item
number = $game_party.item_number(item.id)
end
bitmap = RPG::Cache.icon(item.icon_name)
self.contents.blt(4, y + 4, bitmap, Rect.new(0, 0, 24, 24))
self.contents.draw_text(32, y, contents.width - 32, 32, item.name)
self.contents.draw_text(contents.width - 32, y, 16, 32, ':')
self.contents.draw_text(-4, y, contents.width, 32, number.to_s, 2)
end
end
#==============================
class Scene_Chest
def initialize(box_id = 1)
@chest = $game_chest[box_id]
end
def main
@spriteset = Spriteset_Map.new
@help_window = Window_Help.new
@help_window.width = 604
@help_window.contents = Bitmap.new(572, 32)
@help_window.x = 16
@help_window.y = - 64
@help_window.opacity = 160
@main_commands = Window_Command.new(224, @chest.main_commands)
@main_commands.x = - 224
@main_commands.y = 96
@main_commands.opacity = 160
@deposit_command = Window_Command.new(224, @chest.deposit_commands)
@deposit_command.x = - 224
@deposit_command.y = 96
@deposit_command.opacity = 160
@deposit_command.active = false
@withdraw_command = Window_Command.new(224, @chest.withdraw_commands)
@withdraw_command.x = - 224
@withdraw_command.y = 96
@withdraw_command.opacity = 160
@withdraw_command.active = false
@chest_data = Window_Chest.new(@chest.id)
@chest_items = Window_ChestItems.new(@chest.id)
@party_items = Window_PartyItems.new
@party_items.x = - 244
@party_items.y = 96
@party_items.opacity = 160
@party_items.active = false
update_help_text
@scene_objects = [@spriteset, @help_window, @main_commands,
@deposit_command, @withdraw_command, @chest_data,
@chest_items, @party_items]
Graphics.transition
while $scene == self
Graphics.update
Input.update
@scene_objects.each {|x| x.update}
if Input.press?(Input::UP) || Input.press?(Input::DOWN)
update_help_text
end
update
end
Graphics.freeze
@scene_objects.each {|x| x.dispose}
end
#--------------------------------
def update
if @main_commands.active
update_main_commands
return
elsif @deposit_command.active
update_deposit_command
return
elsif @withdraw_command.active
update_withdraw_command
return
elsif @chest_items.active
update_withdraw
return
elsif @party_items.active
update_deposit
return
end
update_scene_exit
end
#-----------------------------
def update_main_commands
@help_window.y += 12 if @help_window.y < 16
@main_commands.x += 30 if @main_commands.x < 16
@deposit_command.x -= 30 if @deposit_command.x > - 224
@withdraw_command.x -= 30 if @withdraw_command.x > - 224
@chest_data.x -= 30 if @chest_data.x > 400
@chest_items.x -= 42 if @chest_items.x > - 320
@party_items.x -= 42 if @party_items.x > - 320
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
@main_commands.active = false
return
end
if Input.trigger?(Input::C)
$game_system.se_play($data_system.decision_se)
@main_commands.active = false
check_main_commands
return
end
end
#----------------------------
def update_deposit_command
@help_window.y += 12 if @help_window.y < 16
@main_commands.x -= 30 if @main_commands.x > - 224
@deposit_command.x += 30 if @deposit_command.x < 16
@withdraw_command.x -= 30 if @withdraw_command.x > - 224
@chest_data.x -= 30 if @chest_data.x > 400
@chest_items.x -= 42 if @chest_items.x > - 320
@party_items.x -= 42 if @party_items.x > - 320
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
@deposit_command.active = false
@main_commands.active = true
return
end
if Input.trigger?(Input::C)
$game_system.se_play($data_system.decision_se)
@deposit_command.active = false
check_deposit_command
return
end
end
#----------------------------
def update_withdraw_command
@help_window.y += 12 if @help_window.y < 16
@main_commands.x -= 30 if @main_commands.x > - 224
@deposit_command.x -= 30 if @deposit_command.x > - 224
@withdraw_command.x += 30 if @withdraw_command.x < 16
@chest_data.x -= 30 if @chest_data.x > 400
@chest_items.x -= 42 if @chest_items.x > - 320
@party_items.x -= 42 if @party_items.x > - 320
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
@withdraw_command.active = false
@main_commands.active = true
return
end
if Input.trigger?(Input::C)
$game_system.se_play($data_system.decision_se)
@withdraw_command.active = false
check_withdraw_command
return
end
end
#-----------------------------
def update_deposit
@help_window.y += 12 if @help_window.y < 16
@main_commands.x -= 30 if @main_commands.x > - 224
@deposit_command.x -= 30 if @deposit_command.x > - 224
@withdraw_command.x -= 30 if @withdraw_command.x > - 224
@chest_data.x -= 30 if @chest_data.x > 400
@chest_items.x -= 42 if @chest_items.x > - 320
@party_items.x += 42 if @party_items.x < 16
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
@party_items.active = false
@deposit_command.active = true
return
end
if Input.trigger?(Input::C)
$game_system.se_play($data_system.decision_se)
item = @party_items.item
if item == 'Return'
@party_items.active = false
@deposit_command.active = true
return
end
case item
when RPG::Item
@chest.deposit_item(item.id, 1)
end
@party_items.refresh
@chest_data.refresh
end
end
#---------------------------
def update_withdraw
@help_window.y += 12 if @help_window.y < 16
@main_commands.x -= 30 if @main_commands.x > - 224
@deposit_command.x -= 30 if @deposit_command.x > - 224
@withdraw_command.x -= 30 if @withdraw_command.x > - 224
@chest_data.x -= 30 if @chest_data.x > 400
@chest_items.x += 42 if @chest_items.x < 16
@party_items.x -= 42 if @party_items.x > - 320
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
@chest_items.active = false
@withdraw_command.active = true
return
end
if Input.trigger?(Input::C)
$game_system.se_play($data_system.decision_se)
item = @chest_items.item
if item == 'Return'
@chest_items.active = false
@withdraw_command.active = true
return
end
case item
when RPG::Item
@chest.withdraw_item(item.id, 1)
end
@chest_items.refresh
@chest_data.refresh
end
end
#---------------------------
def update_scene_exit
@help_window.y -= 12 if @help_window.y > - 64
@main_commands.x -= 30 if @main_commands.x > - 224
@deposit_command.x -= 30 if @deposit_command.x > - 224
@withdraw_command.x -= 30 if @withdraw_command.x > - 224
@chest_data.x += 30 if @chest_data.x < 640
@chest_items.x -= 42 if @chest_items.x > - 320
@party_items.x -= 42 if @party_items.x > - 320
if @help_window.y == - 64 && @main_commands.x == - 224
$scene = Scene_Map.new
end
end
#---------------------------
def update_help_text
text = 'Select To '
if @main_commands.active
text += @chest.main_commands[@main_commands.index]
elsif @deposit_command.active
text += @chest.deposit_commands[@deposit_command.index]
elsif @withdraw_command.active
text += @chest.withdraw_commands[@withdraw_command.index]
elsif @party_items.active
text += "#{@party_items.item_name}"
elsif @chest_items.active
text += "#{@chest_items.item_name}"
end
@help_window.set_text(text, 1)
end
#-----------------------------
def check_main_commands
case @chest.main_commands[@main_commands.index]
when 'Deposit'
@deposit_command.active = true
when 'Withdraw'
@withdraw_command.active = true
when 'Cancel'
return
end
update_help_text
end
#-----------------------------
def check_deposit_command
case @chest.deposit_commands[@deposit_command.index]
when 'Deposit Items'
@party_items.refresh(1)
@party_items.active = true
when 'Deposit All Items'
@chest.deposit_all_items
when 'Deposit Everything'
@chest.deposit_everything
when 'Return'
end
if @deposit_command.index > 3
@chest_data.refresh
@main_commands.active = true
end
update_help_text
end
#-----------------------------
def check_withdraw_command
case @chest.withdraw_commands[@withdraw_command.index]
when 'Withdraw Items'
@chest_items.refresh(1)
@chest_items.active = true
when 'Withdraw All Items'
@chest.withdraw_all_items
when 'Withdraw Everything'
@chest.withdraw_everthing
when 'Return'
end
if @withdraw_command.index > 3
@chest_data.refresh
@main_commands.active = true
end
update_help_text
end
end
Note:
~This is just for items. Not weapons/armour/gold.
~I am a noob scripter, this is my first script that doesn't consist of just windows or menus.
Thanks to anybody who can fix/help me with it :$