Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

This problem is already solved.

Hi. I have a bit challenging request, but I hope you take it as a challenge and try to help!

I'm using RPG Maker XP.

I want to make an inventory in which it is only possible to have 1 item. That item's icon would be displayed during the playable parts of the game in a window in the upper right corner or the lower right corner. Can you script something like that? I'd do it myself but I really don't know how to script and it doesn't seem THAT hard to me, I think you could just limit the maximum amount of items to 1, make a new window that shows up in game in the position I said and have the icon of the item show up there. It would be also nice if I could use bigger icons for that effect... And if I could activate the window's visiblity whenever I wanted... Anyway, I really hope you take this harder request. It will be worth it, I think my game is at least very different from every RPG Maker game I've ever seen, and it's also very fast to create, which means I'd have a demo very soon, possibly in two weeks.

Thank you and I'm looking forward to replies. If anyone is interested in making the script but needs more details you can PM me and I'll say all I can. If there is already a script that allows me to do what I want to do, even though it seems unlikely to me, you could tell me where to find it too.

Regards
 
1. Try this:
Code:
class Window_Base
  alias fontpatch_setcontents contents=
  
  def contents=(bitmap)
    fontpatch_setcontents(bitmap)
    if $scene.is_a?(Scene_Menu)
      bitmap.font.name = "Monotype Corsiva"
    elsif $scene.is_a?(Scene_Title)
      bitmap.font.name = "Courier New"
    end
  end
end
 
Code:
class Window_Base
  alias fontpatch_setcontents contents=
  
  def contents=(bitmap)
    fontpatch_setcontents(bitmap)
    if $scene.is_a?(Scene_Menu)
      bitmap.font.name = "Monotype Corsiva"
      bitmap.font.color = Color.new(128, 255, 128)
    elsif $scene.is_a?(Scene_Title)
      bitmap.font.name = "Courier New"
      bitmap.font.color = Color.new(255, 128, 128)
    end
  end
end
 
Oh my God, not only did it not work but it destroyed my project. It's not working now! I tried the script above Main, then when I play tested it said "Failed to create process". Then I deleted the script and the error keeps on showing up when I play test! Please someone help.
 
How can it not work? It's the correct code so you must have done something wrong, and the "Failed to create process" error can't have anything to do with it, you must have done something else to screw it up.

Try to create a new project and then move the "Data" folder to it (move "Graphics" and "Audio" too if you have anything there)  :thumb:
 
Damn, this makes me want to write a special module for individual Window/Scene visual settings (for font 'n stuff).

Yeah, there actually was problems with the method provided, I went ahead and re-wrote it for you and tested it with the "Anime Ace" and "Georgia" fonts to make sure it was working. Here, go ahead and paste this somewhere above main/below Scene_Debug/SDK if using the SDK.

If you don't have one of these fonts installed, it won't show up, so the command window on Scene_Title might be blank, go ahead and change the "Anime Ace" to whatever is on your machine, that should fix that too.

Code:
class Window_Base < Window
  alias_method :fontset_winbase_update_later, :update
  def update
    if self.contents.is_a?(Bitmap) && @font_set.nil?
      if $scene.is_a?(Scene_Menu)
        self.contents.font.name = "Georgia"
        self.contents.font.color = Color.new(128, 255, 128)
      elsif $scene.is_a?(Scene_Title)
        self.contents.font.name = "Anime Ace"
        self.contents.font.color = Color.new(255, 128, 128)
      end
      if self.respond_to?(:refresh)
        refresh
      end
      @font_set = true
    end
    fontset_winbase_update_later
  end
end
 
Ok I suggest anyone tries this script because it always makes a project stop working, I tried it in various new projects, and when you test it says "Failed to create process", and the error stays forever even if you delete the script you just pasted. Everything becomes alright if I create a new project and put there the Data, Graphics and Audio folders, like suggested to me (thanks a lot!), but this script still doesn't work. Note that I0m using RPG Maker XP. Any suggestions?

I'll make it easier. I found a script that works, just need to change Main to this:

#==============================================================================
# ** Main
#------------------------------------------------------------------------------
#  After defining each class, actual processing begins here.
#==============================================================================

begin
  $fontface = "Cooper Black"
  $fontsize = 18
  # Prepare for transition
  Graphics.freeze
  Font.default_name = "Cooper Black"
  # Make scene object (title screen)
  $scene = Scene_Title.new
  # Call main method as long as $scene is effective
  while $scene != nil
    $scene.main
  end
  # Fade out
  Graphics.transition(20)
rescue Errno::ENOENT
  # Supplement Errno::ENOENT exception
  # If unable to open file, display message and end
  filename = $!.message.sub("No such file or directory - ", "")
  print("Unable to find file #{filename}.")
end

What do I add and where to change the font color (also, isn't the color supposed to have 4 values instead of 3, as in the script given to me here?)
 
stillzero":1zjwpgnb said:
(also, isn't the color supposed to have 4 values instead of 3, as in the script given to me here?)
Not exactly true. It's 3 or 4 arguments. The fourth argument is alpha (opacity) which is optional. Without putting it there, it's automatically set to 255. So in general, Color.new(255, 255, 255, 255) is the same as Color.new(255, 255, 255). Both return 100% opaque white.

Now, if you want to change the default color (will not change all scripts due to contents colors changing), you can use:
Code:
Font.default_color = Color.new(red, green, blue)
Obviously change the red, green, blue part into integers from 0 to 255. If you press Ctrl-Shift-F inside your script editor and search for 'self.contents.font.color =', you will find all locations where the font color changes regardless of the default color. If your color problem occurs in any of these spots, this is going to have to change. Note that such color changes are used in almost every Bitmap-based script in the default system, so it's going to have a lot to change.

Alternatively, you can go into Window_Base and change the color functions in there into specific colors of your choice. These are such as:
Code:
def normal_color
  return Color.new(255,255,255)
end

def disabled_color
  return Color.new(255, 255, 255, 160)
end
And a bunch of those. You can change these to fix every single script to your new values. Make sure all that is changed is required.

For the message system, change colors based on the 'def text_color()' method.

Hope this helps on the color front.
 
Ok, first problem is solved, thank you all (even the guy who created the Project Destroyer script, lol). Now I just need the second problem solved...(if anyone could delete all the posts since the first one in this thread I would appreciate it, as the first problem is solved).
 
That shouldn't be too hard. It would require a bit of modifications, however, but it shouldn't be hard. Try using this code I just cooked up:
Code:
class Game_Party
  def items_size
    return @items.size
  end
end

class Interpreter
  alias_method(:sarkilas_command_126, :command_126)
  
  def command_126
    if $game_party.items_size >= 1
      return
    end
    sarkilas_command_126
  end
end

class HUD < Window_Base
  def initialize
    super(0,0,640,64)
    self.contents = Bitmap.new(width - 32, height - 32)
    refresh
    self.visible = true
    self.opacity = 0
    self.z = 9999
  end
  
  def refresh
    self.contents.clear
    unless $game_party.items_size == 0
      for item in $data_items
        if item.is_a?(RPG::Item)
          if $game_party.item_number(item.id) > 0 and $data_items[item.id] != @f_item
            @f_item = $data_items[item.id]
            break
          end
        end
      end
      if @f_item.nil? or !@f_item.is_a?(RPG::Item)
        return
      end
      bitmap = RPG::Cache.icon(@f_item.icon_name)
      self.contents.blt(0,0,bitmap,Rect.new(0,0,24,24),255)
      self.contents.draw_text(28,4,640,32,@f_item.name)
    end
  end
end

class Scene_Map
  alias_method(:sarkilas_map_main, :main)
  alias_method(:sarkilas_map_update, :update)
  
  def main
    @hud = HUD.new
    sarkilas_map_main
    @hud.dispose
  end

  def update
    @hud.refresh
    sarkilas_map_update
  end
end

Hope that does the trick.
 
Wow man that's so cool thank you so much!

But there are still some things that don't work very well about it, could you help me? I know maybe I'm being a little annoying but you only have to help me if you want to.

I managed to modify your script a little so it became this way:

class Game_Party
  def items_size
    return @items.size
  end
end

class Interpreter
  alias_method:)sarkilas_command_126, :command_126)
 
  def command_126
    if $game_party.items_size >= 1
      return
    end
    sarkilas_command_126
  end
end

class HUD < Window_Base
  def initialize
    super(565,405,55,55)
    self.contents = Bitmap.new(width - 32, height - 32)
    refresh
    self.visible = true
    self.opacity = 200
    self.z = 9999
  end
 
  def refresh
    self.contents.clear
    unless $game_party.items_size == 0
      for item in $data_items
        if item.is_a?(RPG::Item)
          if $game_party.item_number(item.id) > 0 and $data_items[item.id] != @f_item
            @f_item = $data_items[item.id]
            break
          end
        end
      end
      if @f_item.nil? or !@f_item.is_a?(RPG::Item)
        return
      end
      bitmap = RPG::Cache.icon(@f_item.icon_name)
      self.contents.blt(0,0,bitmap,Rect.new(0,0,24,24),255)
      self.contents.draw_text(28,4,640,32,@f_item.name)
    end
  end
end

class Scene_Map
  alias_method:)sarkilas_map_main, :main)
  alias_method:)sarkilas_map_update, :update)
 
  def main
    @hud = HUD.new
    sarkilas_map_main
    @hud.dispose
  end

  def update
    @hud.refresh
    sarkilas_map_update
  end
end

Now it would be nice if I could have the word Item show up above the small window. I don't need the item's name.

Here are the other things that don't work very well: I want it to be possible to always have one and only one item which is currently in your possession, and that item would be replaceable by other items you gained through the game (for example, you had a ball, and you "talked" to a cube, the ball would leave the inventory and the cube would come in. The same would happen if you used the item, it would go away ( this part works, but I think I can't have the item again in the inventory after I use it...). I hope you understand my idea and are willing to help.

Oh and one more thing (I know maybe I'm asking too mcuh but I HAVE to get this right!), this one shouldn't be any hard anyway, can you make the window's visibility be controlled by a switch?
 
You can do the item swap by removing this snippet of the code presented:

Code:
class Interpreter
  alias_method(:sarkilas_command_126, :command_126)
  
  def command_126
    if $game_party.items_size >= 1
      return
    end
    sarkilas_command_126
  end
end
That will allow you to still add and remove items, but only the first item will be displayed. So unless you remove all items and give a new one the old one will remain in the window.
 
Cool, the replaceable thing is working fine! If you could do the other things it would be perfect (and you would of course have all the due credit...)!

All that's left is:
- window visibility controlled by switch (there could be a place where you had to put for example "0004" to choose the switch in control)
- word "Item" above the window

To see the window i changed opacity to 200 and set the coordinates to 565, 405, 55, 55.

What is the script event command that allows me to remove ALL the items in the inventory at the same time?
There should be one, right?
 
stillzero":2x2y4abo said:
What is the script event command that allows me to remove ALL the items in the inventory at the same time?
There should be one, right?
There is none. But by adding this snippet somewhere, you can remove all items by calling a script inside events (event command page 3, bottom-right) and insert the code: $game_party.clear_items

Code:
class Game_Party
  def clear_items
    @items.clear if @items.is_a?(Array)
  end
end
 
Ok it looks like Sarkilas won't do it. I'd like to know if there's anyone willing to add the following features to this script then (it shouldn't be too hard):

class Game_Party
  def items_size
    return @items.size
  end
end

class HUD < Window_Base
  def initialize
    super(565,405,55,55)
    self.contents = Bitmap.new(width - 32, height - 32)
    refresh
    self.visible = true
    self.opacity = 200
    self.z = 9999
  end
 
  def refresh
    self.contents.clear
    unless $game_party.items_size == 0
      for item in $data_items
        if item.is_a?(RPG::Item)
          if $game_party.item_number(item.id) > 0 and $data_items[item.id] != @f_item
            @f_item = $data_items[item.id]
            break
          end
        end
      end
      if @f_item.nil? or !@f_item.is_a?(RPG::Item)
        return
      end
      bitmap = RPG::Cache.icon(@f_item.icon_name)
      self.contents.blt(0,0,bitmap,Rect.new(0,0,24,24),255)
      self.contents.draw_text(28,4,640,32,@f_item.name)
    end
  end
end

class Scene_Map
  alias_method:)sarkilas_map_main, :main)
  alias_method:)sarkilas_map_update, :update)
 
  def main
    @hud = HUD.new
    sarkilas_map_main
    @hud.dispose
  end

  def update
    @hud.refresh
    sarkilas_map_update
  end
end

The features are:
- making it possible to control the window's (test the script and you'll see it) visibility (visible/invisble) by a switch
- making the expression "Item" show up above the window, either inside a small window or just the word by itself, do as you wish as long as it works( the words visibilty would also be controlled by the switch)

Both of them look quite basic to me from a non-scripter point of view, so I'll be looking forward to the help of the self-proclaimed "masters of scripting". Of course you'll be credited, if that motivates you...
 
This was done by adding three more lines to the script, so I did this while I had some spare time. Here goes:
Code:
class Game_Party
  def items_size
    return @items.size
  end
end

class HUD < Window_Base
  ENABLE_HUD_SWITCH = 1 # HUD switch ID
  def initialize
    super(565,405,55,55)
    self.contents = Bitmap.new(width - 32, height - 32)
    refresh
    self.visible = true
    self.opacity = 200
    self.z = 9999
  end
 
  def refresh
    self.contents.clear
    self.contents.draw_text(0,0,640,32,"Item")
    unless $game_party.items_size == 0
      for item in $data_items
        if item.is_a?(RPG::Item)
          if $game_party.item_number(item.id) > 0 and $data_items[item.id] != @f_item
            @f_item = $data_items[item.id]
            break
          end
        end
      end
      if @f_item.nil? or !@f_item.is_a?(RPG::Item)
        return
      end
      bitmap = RPG::Cache.icon(@f_item.icon_name)
      self.contents.blt(8,32,bitmap,Rect.new(0,0,24,24),255)
      self.contents.draw_text(28,4,640,32,@f_item.name)
    end
    self.visible = $game_switches[ENABLE_HUD_SWITCH]
  end
end

class Scene_Map
  alias_method(:sarkilas_map_main, :main)
  alias_method(:sarkilas_map_update, :update)
 
  def main
    @hud = HUD.new
    sarkilas_map_main
    @hud.dispose
  end

  def update
    @hud.refresh
    sarkilas_map_update
  end
end
Hope it works. Change the value of the ENABLE_HUD_SWITCH to whatever ID you want.
 
The switch worked perfectly. The Item thing sucked. But guess what, I did some modifications here and there, tried until I got it right and it's finally working! So this thread is officially over! Thanks for all the help, Sarkilas, you will be credited.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top