Main Menu
  • Welcome to The RPG Maker Resource Kit.

Limited Inventory edit help

Started by SowS, February 18, 2010, 07:43:13 AM

0 Members and 1 Guest are viewing this topic.

SowS

I'm trying to edit modern algebra's Limited Inventory system but i have problems right now that i can't figure out...

1. how can i make the indexes of the items interchangeable(is it the right word? ;D) instead of having a pop-up window for selecting Use/Discard?

example:
x u x x o
o is the selected item
u is the desired index
when o is selected, a new cursor is shown to select u.
after u is selected:
x o x x u

2. how can i increase the vertical spaces between the item rects?

The script is very complicated for me... right now... so any help will be appreciated.  :lol:

Grafikal


Nhoj_yeR


modern algebra

#3
I think he was just a little confused at your post. I'm a little confused as to what you want as well. Is it that you want the player to be able to switch the positions of items, so:

Potion
High Potion
Sword
Shield

could become something like:

Potion
Shield
Sword
High Potion

I haven't looked at the script for a long time, but I think to do so I think I or another scripter would need to add in a way to track positions. I think the way I made it adds new items based on item order. So Items 0-999, then Weapons 0-999, then Armors 0-999. I'm not sure if that's true though as I haven't looked at it for a long time. But I think there would need to be some alterations to the way items are added. So, if you want that functionality, the first thing you will need to do is change the way items are added and removed from the inventory. After that, you would probably want to make a new invisible window over top with the same to show the next cursor and base it off that. I do a similar thing in the Integrated Reserve Party if you want to see an example of switching order with two cursors.


Increasing the vertical space is a little easier, but you might run into other problems based on how I calculated what sprites should be drawn when... Again, I don't remember this script very well, so I can't remember if the way I did that would cause problems in this regard. The simple answer, however, is to find the item_rect method of the Window_Item class in my script. You should see this:


#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 # * Item Rect
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 def item_rect (index)
   wlh = @wlh == nil ? WLH : @wlh
   rect = Rect.new(0, 0, 0, 0)
   rect.width = (contents.width + @spacing) / @column_max - @spacing
   rect.height = wlh
   rect.x = index % @column_max * (rect.width + @spacing)
   rect.y = (index / @column_max * wlh)
   return rect
 end


Alter the last line where rect.y is set to change the y position of the slots. So, a line like this:


   rect.y = (index / @column_max * (wlh + 4))


would increase the vertical spacing by 4 pixels. Change the 4 to however many you want.


And don't feel bad about it being complicated :P I barely knew what I was doing when I wrote this script - it's not well written I don't think.

Grafikal

Quote from: Nhoj_yeR on February 18, 2010, 01:01:25 PM
what's with that post?!   ???

this

Quote from: Modern Algebra on February 18, 2010, 03:50:02 PM
I think he was just a little confused at your post.



But now that MA wrote something, I think I know what you mean.

Nhoj_yeR

#5
sorry for the double account but i think i made a mistake while changing my email address so the i can't see the validation email(i even typed the same in the email confirmation box :-\)... just delete/ban/whatever the previous account.. i'll stick with this...

now, on the topic:
for the vertical spaces... i didn't thought of increasing wlh... i just did:
rect.y = (index / @column_max * wlh) + 32
so the starting point for all the item rects is the only thing changed...

for item switching positions:
i'll try what you said... thanks!



Nhoj_yeR

#6
ok, I'm done with the vertical spacing problem. Now, i'm doing the item-switching problem but i can't reproduce the code i did yesterday whatever i do. :-\

i'm doing the invisible window first since it's easier. my problem there is that the invisible window doesn't check when player press C or B. i think the problem is in the update method of Scene_Item.

here's the window code:
[spoiler]#==============================================================================
# ** Window Blank Inventory Cursor
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  This window draws a cursor over a selected actor.
#==============================================================================

class Window_BlankInvCursor < Window_Item
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 # * Object Initialization
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 def initialize(x = 50, y = 50, width = 300, height = 300)
   super(x, y, width, height)
   self.visible = false
   self.active = false
   self.index = -1
   self.opacity = 0
 end
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 # * Refresh
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 def refresh
   @spacing = 32
   @column_max = 4
   @item_max = 12
 end
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 # * Item Rect
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 def item_rect (index)
   wlh = @wlh == nil ? WLH : @wlh
   rect = Rect.new(0, 0, 0, 0)
   rect.width = 32 #(contents.width + @spacing) / @column_max - @spacing
   rect.height = 32
   rect.x = (index % @column_max * (rect.width + @spacing + 24)) + 32
   rect.y = (index / @column_max * (wlh + 58)) + 32
   return rect
 end
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 # * Set Index
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 def set_index (index)
   self.index = index
 end
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 # * Get Index
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 def get_index
   return self.index
 end
end
[/spoiler]

and Scene_Item:
[spoiler]class Scene_Item
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 # * Start processing
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 def start
   super
   create_menu_background
   @activated_frame = true
   @viewport = Viewport.new(0, 0, Graphics.width, Graphics.height)
   @help_window = Window_Help.new(0, 361)
   @help_window.width = Graphics.width
   @help_window.viewport = @viewport
   wlh = Window_Base::WLH
   @item_window = Window_Item.new(((544 - 394) / 2), 20, 394, 296)
   @item_window.help_window = @help_window
   @item_window.active = true
   @item_window.viewport = @viewport
   @active_window = @item_window
   @cursor_window = Window_BlankInvCursor.new(((544 - 394) / 2), 20, 394, 296)
   @cursor_window.viewport = @viewport
   @target_window = Window_MenuStatus.new(0, 0)
   @target_window.x = Graphics.width - @target_window.width
   @target_window.height = Graphics.height
   @target_window.z = 150
   hide_target_window
   # Create Loot Window
   wdth = Graphics.width / 2
   hght = Graphics.height - 64 - 2*wlh
   @loot_window = Window_Item.new (wdth, 64 + (2*wlh), wdth, hght)
   @loot_window.index = -1
   @loot_window.viewport = @viewport
   # Create Loot Label Window
   @lootlabel_window = Window_Base.new (wdth, 32 + wlh, wdth, 32 + wlh)
   @lootlabel_window.visible = false
   @lootlabel_window.contents.font.color = @lootlabel_window.system_color
   @lootlabel_window.contents.draw_text (0, 0, 240, wlh, Vocab::MA_LOOT_LABEL, 1)
   @lootlabel_window.viewport = @viewport
   @loot_window.active = false
   # If no loot, hide the window
   if $game_temp.slots_to_discard.slots.empty?
     @loot_window.visible = false
     @loot_window.refresh ($game_temp.slots_to_discard, 1)
     @overloaded_initially = false
   else
     show_loot
     @overloaded_initially = true
   end
   @last_index = $game_party.last_item_id
 end
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 # * Return Scene
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 alias malg_grfk_inventoy_lmt_rtrnscn_1h45 return_scene
 def return_scene
   # If Still items left in Loot
   if RPG::MA_WARN_WINDOW && !$game_temp.slots_to_discard.slots.empty?
     # Give warning
     @warning_window = Window_Warning.new
     return
   end
   if @overloaded_initially
     $scene = Scene_Map.new
   else
     # Run Original Method
     malg_grfk_inventoy_lmt_rtrnscn_1h45
   end
 end
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 # * Show Target Window
 #     right : Right justification flag (if false, left justification)
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 def show_target_window(right)
   right = @loot_window.visible ? @active_window == @item_window : right
   @item_window.active = false
   width_remain = Graphics.width - @target_window.width
   @target_window.x = right ? width_remain : 0
   @target_window.visible = true
   @target_window.active = true
   if right
     @viewport.rect.set(0, 0, width_remain, @target_window.height)
     @viewport.ox = 0
   else
     @viewport.rect.set(@target_window.width, 0, width_remain, @target_window.height)
     @viewport.ox = @target_window.width
   end
 end
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 # * Hide Target Window
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 def hide_target_window
   @item_window.active = true
   @target_window.visible = false
   @target_window.active = false
   @viewport.rect.set(0, 0, Graphics.width, Graphics.height)
   @viewport.ox = 0
 end
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 # * Termination processing
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 alias mdlg_graf009_invlimit_trmnte_itemscene_5bd3 terminate
 def terminate (*args)
   # Run Original Method
   mdlg_graf009_invlimit_trmnte_itemscene_5bd3 (*args)
   # Dispose of new windows
   @loot_window.dispose
   @lootlabel_window.dispose
   @cursor_window.dispose
 end
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 # * Update Frame
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 alias malg_gfl009_limitedinventory_upt_2h45 update
 def update
   malg_gfl009_limitedinventory_upt_2h45
   @loot_window.update
   if @activated_frame
     @activated_frame = false
     return
   end
   case @active_window
   when @item_window
     update_item_selection
   when @cursor_window
     @cursor_window.update
#~       update_item_selection
   end
 end
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 # * Update Item Selection
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 alias moal_rfkl9_invntr_limit_upditmselect_1hr4 update_item_selection
 def update_item_selection
   # IF ESC pressed
   if Input.trigger?(Input::B)
     Sound.play_cancel
     return_scene
   elsif Input.trigger?(Input::C)
     if @item_window.active == true
       item = @item_window.item
       if item != nil
         Sound.play_decision
         @item_window.active = false
         @cursor_window.active = true
         @cursor_window.visible = true
         @cursor_window.set_index(@item_window.get_index)
         @active_window = @cursor_window
       else
         Sound.play_buzzer
       end
     elsif @cursor_window.active == true
       Sound.play_decision
       @item_window.active = true
       @cursor_window.active = false
       @cursor_window.visible= false
       @item_window.set_index(@cursor_window.get_index)
       @active_window = @item_window
     end
   end
 end
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 # * Use Item (apply effects to non-ally targets)
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 alias modalg_grkl_liminv_ustmnntrgt_2hb4 use_item_nontarget
 def use_item_nontarget
   # Get last instance of this item in the inventory.
   id = @item_window.index
   while id == @item_window.index
     @item_window.index += 1
     id += 1 if @item == @item_window.item
   end
   @item_window.index -= 1
   modalg_grkl_liminv_ustmnntrgt_2hb4
   $game_party.last_item_id = @item_window.index
   # Refresh Item Window if that slot is now empty
   if @item_window.item == nil
     @item_window.refresh
#~       @emptycount_window.refresh ($game_party.limit_inventory)
     hide_target_window
   end
 end
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 # * Show Loot
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 def show_loot
   @loot_window.refresh ($game_temp.slots_to_discard, 1)
   @loot_window.update
   @loot_window.visible = true
   @lootlabel_window.visible = true
   @item_window.width = Graphics.width / 2
   @item_window.refresh ($game_party.limit_inventory, 1)
 end
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 # * Check to Hide Loot
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 def check_to_hide_loot
   @loot_window.refresh ($game_temp.slots_to_discard, 1)
#~     @emptycount_window.refresh ($game_party.limit_inventory)
   # If there are no more items in loot
   if $game_temp.slots_to_discard.slots.size == 0
     # Hide Loot Window
     @loot_window.visible = false
     @loot_window.active = false
     @loot_window.index = -1
     @lootlabel_window.visible = false
     @item_window.width = Graphics.width
     @item_window.index = 0
     @item_window.refresh ($game_party.limit_inventory, 2)
     @item_window.active = true
     @active_window = @item_window
   else
     @item_window.refresh ($game_party.limit_inventory, 1)
     @loot_window.active = true
   end
 end
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 # * Clear Loot Slots
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 def clear_loot_slots
   # Destroy all items in Loot
   unless $game_temp.slots_to_discard.slots.empty?
     # Update Party Hash and remove items
     $game_temp.slots_to_discard.slots.each { |slot|
       $game_party.drnlgbr_grafikal_limited_inventory_gn_itm_94n6 (slot.item, -1*slot.amount)
     }
     RPG::SE.new (Sound::MA_DESTROY_SE).play
     $game_temp.slots_to_discard.clear
   end
 end
end
[/spoiler]

please help...

EDIT: I solved it. I just need to trace what I edited.  ;D Now, off to the actual switching part. :D

EDIT2: i can't figure out how to switch the items. maybe because i haven't worked with items before. can you help me with its algorithm?

Nhoj_yeR

ok... i still haven't figured it out. i don't know which to edit, the add_item method or the gain_item method? i think lose_item and remove_item methods don't need to be edited.

Nhoj_yeR

BUMP (just to tell that i still haven't figured it out.. )