Better Inventory / HUD / Keyboard Shortcuts

Near's Inventory/HUD/Shortcut Script Version 1.0
By: Near

Introduction

This script (or script compilation) creates a small HUD on
the map/menu, an inventory grid, and allows the player to set
shortcuts for certain scenes. This script is simply plug 'n' play.

Features

  • Nice little HUD
  • Sweet Grid Inventory
  • Keyboard Shortcuts

Screenshots

Image
Image
Image
Image

Demo

http://www.mediafire.com/?sharekey=7e28669a9545db99d2db6fb9a8902bda


Instructions

This script is just plug 'n' play basically.
To open the Shortcuts menu press Ctrl + Q or W

FAQ

No questions yet.

Compatibility

Will not work with any CMSes(that I know of) and will not work
with Large Party scripts.

Author's Notes

Just ignore the RPG::Item script. I am working on item weights for the inventory system.

Terms and Conditions

Credit is necessary, and don't claim as your own.
Some suggestions from Seph

1) I don't suggest adding \w[n] to the description for weight. For one, you are having to call the set_weight method, which ends up just adding a bunch of new lines of code to go through.

Why not try this:
  1. class RPG::Item
  2.   # weapon_id => weight
  3.   Weight = {}
  4.   # default weight
  5.   Weight.default = 1
  6.   def weight
  7.      return Weight[@id]
  8.   end
  9. end
Expand to see the code.


Cuts your 93 lines down pretty quickly. Not as simple as adding the \w in the item description, but a little more efficient.

------------------------------------------------------

2) This code:
  1.       draw_actor_graphic(@actor1, 64, y1)
  2.      draw_actor_graphic(@actor2, 164, y1)
  3.      draw_actor_graphic(@actor3, 264, y1)
  4.      draw_actor_graphic(@actor4, 364, y1)
  5.      draw_actor_name(@actor1, 32, y2)
  6.      draw_actor_name(@actor2, 140, y2)
  7.      draw_actor_name(@actor3, 240, y2)
  8.      draw_actor_name(@actor4, 340, y2)
  9.      self.contents.draw_text(420, 23, 64, 32, $data_system.words.gold)
  10.      self.contents.draw_text(440, 46, 144, 32, $game_party.gold.to_s)
  11.   end
  12.   def reset_actors
  13.      @actor1 = $game_party.actors[0]
  14.      @actor2 = $game_party.actors[1]
  15.      @actor3 = $game_party.actors[2]
  16.      @actor4 = $game_party.actors[3]
  17.  
Expand to see the code.


What happens if there is only 1, 2 or 3 actors in the party?

I also suggest a loop function. Could cut down on some lines:
  1. class Window_Hud < Window_Base
  2.   def initialize
  3.      super 0, 320, 640, 160
  4.      self.contents = Bitmap.new(width - 32, height - 32)
  5.      self.z = 1
  6.      self.opacity = 160
  7.      self.back_opacity = 120
  8.      refresh
  9.   end
  10.   def refresh
  11.      self.contents.clear
  12.      @actors = $game_party.actors
  13.      y1, y2 = 64, 75
  14.      for i in [email hidden]
  15.         draw_actor_name(@actors[i], 32 + i * 100, y2)
  16.         draw_actor_graphic(@actors[i], 64 + i * 100, y1)
  17.      end
  18.      self.contents.draw_text(420, 23, 64, 32, $data_system.words.gold)
  19.      self.contents.draw_text(440, 46, 144, 32, $game_party.gold.to_s)
  20.   end
  21. end
Expand to see the code.


------------------------------------------------------

3) This block right here:
  1.          case @cwin.index
  2.         when 0
  3.            $shortcuts[@key] = Scene_Item.new
  4.         when 1
  5.            $shortcuts[@key] = Scene_Status.new
  6.         when 2
  7.            $shortcuts[@key] = Scene_Equip.new
  8.         when 3
  9.            $shortcuts[@key] = Scene_Skill.new
  10.         when 4
  11.            $shortcuts[@key] = Scene_Save.new
  12.         end
Expand to see the code.


You are essentially making new objects and saving them to the $shortcuts variable. I suggest instead setting class name (remove the .new) Then down on your $scene = $shortcuts[0] line, change those to $scene = $shortcuts[0].new. Create the new object then.

I would also suggest adding this little method in Window_Command
  1. class Window_Command
  2.   def command(index = self.index)
  3.      return @commands[index]
  4.   end
  5. end
Expand to see the code.


The reason for this is because I have found it better practice to not base command windows based off indexes, but the command itself. This way, you can add other commands without having to change all the index values in your case. So you would have

case @cwin.command

In the end, this makes things easier in the future.

------------------------------------------------------

The only other thing would be to modify Window_Item to not spread the icons by 28, but by the default of 32. This is more a general practice. You could then remove those methods below update_help, that modify the cursor height to 28.

------------------------------------------------------

Finally, I suggest adding a specialized update method in Window_HUD. The purpose of this is to check if the actors change. Just create some some flag variables that hold @character_name, @character_hue and @name of your actors in the refresh method. Then in the update method, compare party size and those instances.

  1. def refresh
  2.   @actors = $game_party.actors
  3.   @size = @actors.size
  4.   @character_names = @actors.collect {|n| n.character_name}
  5.   @character_hues = @actors.collect {|n| n.character_hue}
  6.   @names = @actors.collect {|n| n.name}
  7.   # ...
  8.  
  9.   def update
  10.      super
  11.      character_names = $game_party.actors.collect {|n| n.character_name}
  12.      character_hues = $game_party.actors.collect {|n| n.character_hue}
  13.      names = $game_party.actors.collect {|n| n.name}
  14.      if @size != @actors.size || character_names != @character_names ||
  15.           character_hues != @character_hues || names != @names
  16.         refresh
  17.      end
Expand to see the code.


Something like that. The same thing is done in Sprite_Character/Sprite_Battler in the update methods if you would like to see another example of this.

------------------------------------------------------

Pretty good script. I like the idea for the shortcuts and the Window_Item modification looks much better than the default one. I don't mean to pick apart your script, just offer guidance, as I see potential in you. :thumb:
Thanks, I knew that it wasn't the cleanest code when I posted it, but I wanted to make a public release before I modified it anymore (helps in case I screw my file up, I have a demo download).

Also, I did the \w[n] thing for sheer simplicity, because I always hate having to look through every weapon id in my database and try to remember 4 or 5 at a time. And I am not using that script yet anyway. I wanted to make sure it worked, and I was think maybe I should make the Inventory more like 'Golden Sun', where each party member has his/her own inventory and party members can trade and give items to each other.

And thanks for the info on the HUD, I had no idea the '.collect' method even existed. (And I have read the help file. Many times) And you're right, the HUD probably would have crashed if you had less people in your party.

And one more thing, the Keyboard Shortcuts were my favorite to do, because it made the system so much easier to access. But I did not
know wether or not I could use classes without calling their 'new' method.
like: $dummy = Scene_Item ; I always thought you had to initialize the
object before you could save it into a variable.

And one more thing (for real this time) I really appreciate your help man, I
am still working on the coding side of RMXP, and I have been struggling
with some things. Like for instance, the Platformer Game... I did it perfectly
with events and one new script method, and I tried it fully scripted, and
my guy jumped through the roof and never came back down. Also, I did a
perfect ABS with events, and I've always wanted to code one, but never knew where to start. So really, thanks for the help with not only this script, but also my Mouse Module, and all my random scripting questions.
.collect actually isn't even included in most Array documentation (why .collect! is and not .collect is beyond me). But you can see documentation on .collect in the Enumerable module.

Well Scene_Item can be assigned, as it is actually a constant. Ruby is just cool that way. lol

And no problem. I'd be happy to help you with anything you need. :thumb:
Thanks, and also, I haven't gotten a chance yet to see what happens when you have less than 4 actors in your party, I'm at school. Wouldn't it raise a NoMethodError ? undefined method 'character_name' for nil:NilClass or something of the like?

And a bit of random off topic-ness: Didn't you create a script at one point, that made scripted event creation easier? I might be able to use that.
Exactly right. :)

Yeah that old event spawner (3 hours of coding, 10+ hours of commenting lol): http://www.owainc.net/scripts/macl_modu ... pawner.txt

Semi complicated to use, but a lot easier than actually coding out the events.
Shweet. I was gonna do something like that at one point... and then I gave up because I kept getting an Uninitialized Constant Error.

But one question that I have been wondering about. Can have an instance variable in a module that is a class?

Like:
module Near
  @class = NearClass.new
end

I tried that with a module I was making to go with another script,
but I got several errors.
As long as the class is defined before it is initialized, it should be fine.
  1. class NearClass
  2. end
  3.  
  4. module Near
  5.   @class = NearClass.new
  6. end
Expand to see the code.
Again, Shweet. I'll get working on the new version ASAP.
i cant download it......
Wow, the download doesn't work... so you necropost instead of PMing me? :haha:

Honestly, this garbage isn't worth downloading, it's unstable and I'm not developing it any further. So, if you still want it that bad, PM me and I'll send it, but it's your job to figure out how to get it working 😀

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=62268