Submit Your Article


 
RPG Maker

Welcome Guest ( Log In | Register )


  Games Resources RPG Maker VX RPG Maker XP Scripts Tutorials Downloads

 
Reply to this topicStart new topic
> Variable-Based Storage System, Item storage which uses variables to retain data.
AlphaWhelp
post Apr 11 2011, 03:58 PM
Post #1


Level 9
Group Icon

Group: Revolutionary
Posts: 147
Type: Developer
RM Skill: Skilled





Version 1.0
Author AlphaWhelp
Release Date 4/11/11


Introduction
This script adds a simplistic yet effective item storage/banking scene to your game

Features
The main feature in this script that sets it apart from other item storage scripts is that it uses variables to keep track of which items are stored. Why use a cumbersome system of variables to record this? Well, it gives you, the developer, extremely easy access to the party's stored items at any time, without needing any scripting knowledge whatsoever, simply by checking variables, and the entire storage system can be managed entirely with events without you ever having to write a single line of scripting beyond the one line needed to call the storage scene. You can easily add or subtract items from storage, or you can total some or all of the player's storage inventory entirely with events, though a little scripting knowledge makes larger operations easy.

Also, no offense to other scripters out there, but every other storage script I found on the internet crashed immediately, this script on the other hand is pretty darn stable.

Script




CODE
module AW

# The following 3 constants determine what variable the items, weapons, and
# armor start recording quantities. Change if you feel comfortable doing so
# just make sure to avoid overlapping variables.
ITEMBEGINNING = 1001
WEAPONBEGINNING = 2001
ARMORBEGINNING = 3001

# The following 3 constants determine how many variables to reserve for items,
# weapons, and armor. if you have items located outside a beginning and
# beginning + limit range, they will not be able to be stored.
ITEMLIMIT = 999
WEAPONLIMIT = 999
ARMORLIMIT = 999

# This constant determines the max number of items holdable in storage.
# Make this as high or low as you want within reason. Variables are not
# unlimited, and if you set this to be too large I can guarantee your
# game will crash.
MAXQUANTITY = 999

# Assuming you leave everything above untouched, variables 1001-1999 will
# be used for storing items, variables 2001 - 2999 for weapons, variables
# 3001 - 3999 for armors. Make sure you have 4000 variables available.

end


CODE

# Do not edit

class Window_Storage_Help < Window_Base

def initialize
super(0, 0, 544, WLH + 32)
end

def set_text(text, align = 0)
if text != @text or align != @align
self.contents.clear
self.contents.font.color = normal_color
self.contents.draw_text(4, 0, self.width - 40, WLH, text, align)
@text = text
@align = align
end
end

end


CODE

# Do not edit

class Window_Storage_Hud < Window_Base

def initialize
super(0, WLH + 32, 544, WLH + 32)
set_text("Personal Inventory Storage Inventory")
end

def set_text(text, align = 1)
self.contents.draw_text(4, 0, self.width - 40, WLH, text, align)
end

end


CODE

# Do not edit

class Window_Storage_Command < Window_Selectable

def initialize(width, commands, column_max = 3, row_max = 1, spacing = 32)
super(0, WLH + 32, width, WLH + 32)
@commands = commands
@item_max = commands.size
@column_max = column_max
refresh
self.index = 0
end

def refresh
self.contents.clear
for i in 0...@item_max
draw_item(i)
end
end

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])
end

end


CODE

# Do not edit

class Window_Partys_Inventory < Window_Selectable

def initialize(x = 0, y = 112, width = 272, height = 306)
super(x, y, width, height)
@column_max = 1
self.index = 0
refresh
end

# Obtain information on which type of item we will meddle with

def set(type)
@type = type
end

def item
return @data[self.index]
end

def include?(item)
return false if item == nil
case @type
when 0
return false unless item.is_a?(RPG::Item)
when 1
return false unless item.is_a?(RPG::Weapon)
when 2
return false unless item.is_a?(RPG::Armor)
end
return true
end

def refresh
@data = []
for item in $game_party.items
@data.push(item) if include?(item)
end
@data.push(nil) if include?(nil)
@item_max = @data.size
create_contents
for i in 0...@item_max
draw_item(i)
end
end

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 = enable?(item)
rect.width -= 4
draw_item_name(item, rect.x, rect.y, enabled)
self.contents.draw_text(rect, sprintf(":%2d", number), 2)
end
end

def update_help
@help_window.set_text(item == nil ? "" : item.description)
end

def enable?(item)
case @type
when 0
return ($game_variables[item.id + AW::ITEMBEGINNING - 1] < AW::MAXQUANTITY)
when 1
return ($game_variables[item.id + AW::WEAPONBEGINNING - 1] < AW::MAXQUANTITY)
when 2
return ($game_variables[item.id + AW::ARMORBEGINNING - 1] < AW::MAXQUANTITY)
end
end
end


CODE

# Do not edit, but see notes below

class Window_Storage_Inventory < Window_Selectable

def initialize(x = 272, y = 112, width = 272, height = 306)
super(x, y, width, height)
@column_max = 1
self.index = 0
refresh
end

# Obtain information on which type of item we will meddle with

def set(type)
@type = type
end

def item
return @data[self.index]
end

def include?(item)
return false if item == nil
case @type
when 0
return false unless item.is_a?(RPG::Item)
when 1
return false unless item.is_a?(RPG::Weapon)
when 2
return false unless item.is_a?(RPG::Armor)
end
return true
end

def refresh
@data = []
case @type
when 0
for storageitems in 1...(AW::ITEMLIMIT + 1)
next unless $game_variables[storageitems + AW::ITEMBEGINNING - 1] > 0
@data.push($data_items[storageitems])
end
when 1
for storageitems in 1...(AW::WEAPONLIMIT + 1)
next unless $game_variables[storageitems + AW::WEAPONBEGINNING - 1] > 0
@data.push($data_weapons[storageitems])
end
when 2
for storageitems in 1...(AW::ARMORLIMIT + 1)
next unless $game_variables[storageitems + AW::ARMORBEGINNING - 1] > 0
@data.push($data_armors[storageitems])
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

def draw_item(index)
rect = item_rect(index)
self.contents.clear_rect(rect)
item = @data[index]
if item != nil
case @type
when 0
number = $game_variables[item.id + AW::ITEMBEGINNING - 1]
when 1
number = $game_variables[item.id + AW::WEAPONBEGINNING - 1]
when 2
number = $game_variables[item.id + AW::ARMORBEGINNING - 1]
end
enabled = enable?(item)
rect.width -= 4
draw_item_name(item, rect.x, rect.y, enabled)
self.contents.draw_text(rect, sprintf(":%2d", number), 2)
end
end

def update_help
@help_window.set_text(item == nil ? "" : item.description)
end

# If using a script which changes the default item limit away from 99,
# edit this 99 below to the new item limit.

def enable?(item)
return ($game_party.item_number(item) < 99)
end
end


CODE

# Do not edit

class Window_Storage_Number < Window_Base

def initialize(x = 0, y = WLH + 32)
super(x, y, 544, WLH + 32)
@item = nil
@max = 1
@price = 0
@number = 1
end

def set(item, max)
@item = item
@max = max
@number = 1
refresh
end

def number
return @number
end

def refresh
y = 0
self.contents.clear
draw_item_name(@item, 0, y)
self.contents.font.color = normal_color
self.contents.draw_text(212, y, 20, WLH, "×")
self.contents.draw_text(248, y, 20, WLH, @number, 2)
self.cursor_rect.set(244, y, 28, WLH)
end

def update
super
if self.active
last_number = @number
if Input.repeat?(Input::RIGHT) and @number < @max
@number += 1
end
if Input.repeat?(Input::LEFT) and @number > 1
@number -= 1
end
if Input.repeat?(Input::UP) and @number < @max
@number = [@number + 10, @max].min
end
if Input.repeat?(Input::DOWN) and @number > 1
@number = [@number - 10, 1].max
end
if @number != last_number
Sound.play_cursor
refresh
end
end
end
end


CODE

# Do not edit, but see notes below

class Scene_Storage < Scene_Base

def start
super
create_menu_background
@help_window = Window_Storage_Help.new
@hud_window = Window_Storage_Hud.new
@hud_window.visible = false
@main_item_window = Window_Partys_Inventory.new
@main_item_window.active = false
@main_item_window.visible = false
@main_item_window.help_window = @help_window
@item_storage_window = Window_Storage_Inventory.new
@item_storage_window.active = false
@item_storage_window.visible = false
@item_storage_window.help_window = @help_window
@number_window = Window_Storage_Number.new
@number_window.active = false
@number_window.visible = false
@commandindex = 0
@sitems = "Items"
@sweapons = "Weapons"
@sarmors = "Armors"
@command_window = Window_Storage_Command.new(544, [@sitems, @sweapons, @sarmors])
@dummy1 = Window_Base.new(0, 112, 272, 306)
@dummy2 = Window_Base.new(272, 112, 272, 306)
@dummy1.visible = true
@dummy2.visible = true
@command_window.visible = true
@command_window.active = true

end

def terminate
super
dispose_menu_background
@help_window.dispose
@hud_window.dispose
@main_item_window.dispose
@item_storage_window.dispose
@number_window.dispose
@command_window.dispose
@dummy1.dispose
@dummy2.dispose
end

def update
super
update_menu_background
@help_window.update
@main_item_window.update
@item_storage_window.update
@command_window.update
@number_window.update
if @command_window.active
update_command_selection
elsif @main_item_window.active
update_main_item_selection
elsif @item_storage_window.active
update_item_store_selection
elsif @number_window.active
update_number_input
end
end

def update_command_selection
if Input.trigger?(Input::cool.gif
Sound.play_cancel
$scene = Scene_Map.new
end
if Input.trigger?(Input::C)
Sound.play_decision
@indextype = @command_window.index
@command_window.active = false
@command_window.visible = false
@hud_window.visible = true
@main_item_window.set(@indextype)
@main_item_window.visible = true
@main_item_window.active = true
@main_item_window.refresh
@item_storage_window.set(@indextype)
@item_storage_window.visible = true
@item_storage_window.refresh
@dummy1.visible = false
@dummy2.visible = false
@commandindex = 0
end
end

def update_main_item_selection
if Input.trigger?(Input::cool.gif
Sound.play_cancel
@dummy1.visible = true
@dummy2.visible = true
@hud_window.visible = false
@main_item_window.visible = false
@main_item_window.active = false
@item_storage_window.visible = false
@command_window.visible = true
@command_window.active = true
end
if Input.trigger?(Input::RIGHT)
Sound.play_cursor
@main_item_window.active = false
@item_storage_window.active = true
@commandindex = 1
end
if Input.trigger?(Input::C)
@item = @main_item_window.item
number = $game_party.item_number(@item)
case @indextype
when 0
beginning = AW::ITEMBEGINNING
when 1
beginning = AW::WEAPONBEGINNING
when 2
beginning = AW::ARMORBEGINNING
end
if @item == nil or $game_variables[@item.id + beginning - 1] == AW::MAXQUANTITY
Sound.play_buzzer
else
Sound.play_decision
max = [AW::MAXQUANTITY - $game_variables[@item.id + beginning - 1], $game_party.item_number(@item)].min
@main_item_window.active = false
@number_window.set(@item, max)
@number_window.active = true
@number_window.visible = true
@hud_window.visible = false
end
end

end

def update_item_store_selection
if Input.trigger?(Input::cool.gif
Sound.play_cancel
@dummy1.visible = true
@dummy2.visible = true
@hud_window.visible = false
@main_item_window.visible = false
@item_storage_window.active = false
@item_storage_window.visible = false
@command_window.visible = true
@command_window.active = true
end
if Input.trigger?(Input::LEFT)
Sound.play_cursor
@item_storage_window.active = false
@main_item_window.active = true
@commandindex = 0
end
if Input.trigger?(Input::C)
case @indextype
when 0
beginning = AW::ITEMBEGINNING
when 1
beginning = AW::WEAPONBEGINNING
when 2
beginning = AW::ARMORBEGINNING
end
@item = @item_storage_window.item
number = $game_variables[@item.id + beginning - 1]

# If using a script which changes the default item limit away from 99,
# edit this 99 below to the new item limit.

if @item == nil or $game_party.item_number(@item) == 99
Sound.play_buzzer
else
Sound.play_decision

# If using a script which changes the default item limit away from 99,
# edit this 99 below to the new item limit.

max = [number, 99 - $game_party.item_number(@item)].min
@item_storage_window.active = false
@number_window.set(@item, max)
@number_window.active = true
@number_window.visible = true
@hud_window.visible = false
end
end
end

def update_number_input
if Input.trigger?(Input::cool.gif
cancel_number_input
elsif Input.trigger?(Input::C)
decide_number_input
end
end

def cancel_number_input
Sound.play_cancel
@number_window.active = false
@number_window.visible = false
@hud_window.visible = true
case @commandindex
when 0 # Store
@main_item_window.active = true
when 1 # Take
@item_storage_window.active = true
end
end

def decide_number_input
Sound.play_shop
@number_window.active = false
@number_window.visible = false
@hud_window.visible = true
case @indextype
when 0
beginning = AW::ITEMBEGINNING
when 1
beginning = AW::WEAPONBEGINNING
when 2
beginning = AW::ARMORBEGINNING
end
case @commandindex
when 0 # Store
$game_party.lose_item(@item, @number_window.number)
$game_variables[@item.id + beginning - 1] += @number_window.number
@main_item_window.active = true
when 1 # Take
$game_party.gain_item(@item, @number_window.number)
$game_variables[@item.id + beginning - 1] -= @number_window.number
@item_storage_window.active = true
end
@main_item_window.refresh
@item_storage_window.refresh
end
end


Customization
All customization options are located within module AW.

Compatibility
You will have issues with scripts which change the default limit per item your party is allowed to carry away from 99. If you're using a different item limit, whether it is lower or higher, you must examine Window_Storage_Inventory and Scene_Storage and change 99 values to the new item limit.


Screenshot


Uploaded with ImageShack.us

DEMO
http://www.mediafire.com/?i7otfbtgioysg5f

Installation
plug-n-play, I highly recommend copying the scripts out of the demo instead of from this message board. paste under Materials but before Main. You must have enough variables for the script to use or else it won't work.


FAQ
This script is provided as is... no further changes will be made to the script by me unless it's a bugfix to the function intended by the original script. If you are a scripter, however, feel free to change it on your own all you want, but don't ask me for help if you break it.


Terms and Conditions
Credit me if you use this script, it may just be a spaghetti code mess of default scripts, but it took real effort. Commercial projects don't need special approval from me.


Credits
Just AlphaWhelp.

This post has been edited by AlphaWhelp: Apr 12 2011, 05:48 AM


__________________________
My scripts...

Haste/Slow States for Tankentai SBS with ATB: http://www.rpgrevolution.com/forums/index....showtopic=18304 (scroll to the middle of the first post and find it under Add-ons)

Old Fashioned Game Overs http://www.rpgrevolution.com/forums/index....ic=29201&hl

Comic Book Cut Scenes http://www.rpgrevolution.com/forums/index....showtopic=30920

Force Preemptive or Surprise Battles: http://www.rpgrevolution.com/forums/index....showtopic=31668

[Show/Hide] Script Snippets written by me:
Fade Victory ME after battle end (fully compatible)
CODE
class Scene_Battle < Scene_Base
alias kill_victory_me battle_end
def battle_end(result)
RPG::ME.fade(500)
kill_victory_me(result)
RPG::ME.stop
end
end

Simple footsteps sound: Note Knock is a pretty terrible footstep sound, you should download your own.
CODE
class Game_Party < Game_Unit
alias footsteps_on_player_walk on_player_walk
def on_player_walk
footsteps_on_player_walk
RPG::SE.new("Knock", 1, 150).play
end
end

More to come as I think of them.
Go to the top of the page
 
+Quote Post
   
Kread-EX
post Apr 12 2011, 02:50 AM
Post #2


(=___=)/
Group Icon

Group: +Gold Member
Posts: 4,136
Type: Scripter
RM Skill: Undisclosed




Approved because it follows the requirements but...

Seriously? 4000 variables? This is madness, one single hash (or three if you really want to separate items from weapons and armors) would be enough for this and the access wouldn't be so hard. Even if the developper only uses 25 items, 30 weapons and 20 armors, that still makes 75 variables to be reserved.

One variable per item is definitely bad design... unless you are completely eventing the system, without any script.


__________________________
FRACTURE - a SMT inspired game (demo) made by Rhyme, Karsuman and me. Weep and ragequit.

My blog.

Click here for my e-peen


Go to the top of the page
 
+Quote Post
   
AlphaWhelp
post Apr 12 2011, 05:52 AM
Post #3


Level 9
Group Icon

Group: Revolutionary
Posts: 147
Type: Developer
RM Skill: Skilled




QUOTE (Kread-EX @ Apr 12 2011, 06:50 AM) *
Approved because it follows the requirements but...

Seriously? 4000 variables? This is madness, one single hash (or three if you really want to separate items from weapons and armors) would be enough for this and the access wouldn't be so hard. Even if the developper only uses 25 items, 30 weapons and 20 armors, that still makes 75 variables to be reserved.

One variable per item is definitely bad design... unless you are completely eventing the system, without any script.

My answer to this is it depends on your limits. If you set the item limits to about 30 each, then all you need would be 90 variables, not 4000. 4000 is just what you need assuming you leave everything to defaults. the design is intended to work out of the box in any game, even ones that use all 999 slots for all three types of items, even though that's ludicrous. the design isn't bad, you just need to understand how the script works a little more.


__________________________
My scripts...

Haste/Slow States for Tankentai SBS with ATB: http://www.rpgrevolution.com/forums/index....showtopic=18304 (scroll to the middle of the first post and find it under Add-ons)

Old Fashioned Game Overs http://www.rpgrevolution.com/forums/index....ic=29201&hl

Comic Book Cut Scenes http://www.rpgrevolution.com/forums/index....showtopic=30920

Force Preemptive or Surprise Battles: http://www.rpgrevolution.com/forums/index....showtopic=31668

[Show/Hide] Script Snippets written by me:
Fade Victory ME after battle end (fully compatible)
CODE
class Scene_Battle < Scene_Base
alias kill_victory_me battle_end
def battle_end(result)
RPG::ME.fade(500)
kill_victory_me(result)
RPG::ME.stop
end
end

Simple footsteps sound: Note Knock is a pretty terrible footstep sound, you should download your own.
CODE
class Game_Party < Game_Unit
alias footsteps_on_player_walk on_player_walk
def on_player_walk
footsteps_on_player_walk
RPG::SE.new("Knock", 1, 150).play
end
end

More to come as I think of them.
Go to the top of the page
 
+Quote Post
   
Kread-EX
post Apr 12 2011, 07:57 AM
Post #4


(=___=)/
Group Icon

Group: +Gold Member
Posts: 4,136
Type: Scripter
RM Skill: Undisclosed




I completely understand how the script works. Did you even read my post entirely? Sure, nobody will use the upper limit, but, especially if you want your script to "work out of the box in any game", using 1 variable per item will force the developper to reserve a crapload of variables which could be invisible into a script.
It doesn't change anything in terms of efficiency (unless the developper keeps a very large array of unused variables) but it certainly makes things confusing when working with variables.

Also, note that I am by no mean bashing you or your work, just sharing my thoughts.


__________________________
FRACTURE - a SMT inspired game (demo) made by Rhyme, Karsuman and me. Weep and ragequit.

My blog.

Click here for my e-peen


Go to the top of the page
 
+Quote Post
   
AlphaWhelp
post Apr 12 2011, 02:28 PM
Post #5


Level 9
Group Icon

Group: Revolutionary
Posts: 147
Type: Developer
RM Skill: Skilled




QUOTE (Kread-EX @ Apr 12 2011, 11:57 AM) *
I completely understand how the script works. Did you even read my post entirely? Sure, nobody will use the upper limit, but, especially if you want your script to "work out of the box in any game", using 1 variable per item will force the developper to reserve a crapload of variables which could be invisible into a script.
It doesn't change anything in terms of efficiency (unless the developper keeps a very large array of unused variables) but it certainly makes things confusing when working with variables.

Also, note that I am by no mean bashing you or your work, just sharing my thoughts.

I still think you are somehow missing the point of the script. I acknowledge the system of 1 variable per item was cumbersome in my original post, however, the point of the script wasn't to make a tidy and compressed script, it was supposed to be exactly what it is, simple, stable, and easily interfaced with events. It also takes no effort whatsoever to create 4000 variables. you just click on new max and type "4000" and boom its done. It's not like you even have to name the variables... variables without names work just as well as variables with names, and the script never gets mixed up over which variable to use... the developer simply has to add the item id - 1 to the beginning constant to find out what variable controls that item. You might not see what the value of having a script done this way is, but it is exactly what I needed for my game.

actually my game uses a modified item-only version of this script, this public version is generic, but still, this script has its uses, even if it isn't the most advanced script floating around. sometimes less is more.


__________________________
My scripts...

Haste/Slow States for Tankentai SBS with ATB: http://www.rpgrevolution.com/forums/index....showtopic=18304 (scroll to the middle of the first post and find it under Add-ons)

Old Fashioned Game Overs http://www.rpgrevolution.com/forums/index....ic=29201&hl

Comic Book Cut Scenes http://www.rpgrevolution.com/forums/index....showtopic=30920

Force Preemptive or Surprise Battles: http://www.rpgrevolution.com/forums/index....showtopic=31668

[Show/Hide] Script Snippets written by me:
Fade Victory ME after battle end (fully compatible)
CODE
class Scene_Battle < Scene_Base
alias kill_victory_me battle_end
def battle_end(result)
RPG::ME.fade(500)
kill_victory_me(result)
RPG::ME.stop
end
end

Simple footsteps sound: Note Knock is a pretty terrible footstep sound, you should download your own.
CODE
class Game_Party < Game_Unit
alias footsteps_on_player_walk on_player_walk
def on_player_walk
footsteps_on_player_walk
RPG::SE.new("Knock", 1, 150).play
end
end

More to come as I think of them.
Go to the top of the page
 
+Quote Post
   

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 25th May 2013 - 04:00 PM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker