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.

Script that prevents weapon from being remove?

Anyone has a script that prevents an actor's weapon from being remove and leaving them unarmed? I mean can I possibly remove the empty slot at the weapon choice window? The one I mean is this:

http://i163.photobucket.com/albums/t295 ... wpnrem.png[/IMG]

If can't, is there a way to make unarmed attack goes animated?
OR set the empty slot with a default equipment "Unarmed"?

Please help 8-)
 

khmp

Sponsor

Aliased two methods in two separate classes hope that doesn't interfere with anything you have but it will display Unarmed if no weapon is equipped.

Code:
# The string that will be drawn when no weapon is equipped.
NO_WEAPON_STRING = 'Unarmed'

class Window_EquipRight
  alias_method :window_equipright_refresh, :refresh
  def refresh
    # Execute normal behavior.
    window_equipright_refresh
    # if the weapon was nil draw NO_WEAPON_STRING in its place.
    if @data[0] == nil
      draw_item_name(NO_WEAPON_STRING, 92, 32 * 0)
    end
  end
end

class Window_Base
  alias_method :window_base_draw_item_name, :draw_item_name
  def draw_item_name(item, x, y)
    if item == nil
      return
    end
    # See if we wanted unarmed to be drawn
    if item == NO_WEAPON_STRING
      self.contents.font.color = normal_color
      self.contents.draw_text(x + 28, y, 212, 32, NO_WEAPON_STRING)
      return
    end
    # Continue on with normal behavior. 
    # Yes it will execute 'if item == nil' again. Sorry.
    window_base_draw_item_name(item, x, y)
  end
end

Good luck Kinnison! :thumb:
 

khmp

Sponsor

Yes but doesn't that also prevent the item from being replaced and not just removed. However I am looking through the code for preventing the weapon slot from being emptied and not just writing Unarmed in place of the weapon not existing.

And this one is an override so I apologize:

Code:
class Scene_Equip
  # Override update_item. Need to intercept actor.equip call.
  def update_item
    # If B button was pressed
    if Input.trigger?(Input::B)
      # Play cancel SE
      $game_system.se_play($data_system.cancel_se)
      # Activate right window
      @right_window.active = true
      @item_window.active = false
      @item_window.index = -1
      return
    end
    # If C button was pressed
    if Input.trigger?(Input::C)
      # Play equip SE
      item = @item_window.item
      # If item is nil don't want to work with it.
      return if item == nil
      $game_system.se_play($data_system.equip_se)
      # Change equipment
      @actor.equip(@right_window.index, item.id)
      # Activate right window
      @right_window.active = true
      @item_window.active = false
      @item_window.index = -1
      # Remake right window and item window contents
      @right_window.refresh
      @item_window.refresh
      return
    end
  end
end

This doesn't get rid of that pesky empty space but all equipment can only be replaced never removed. This just makes a check to see if an item exists at the index where the user pressed the C button.
 
Alright cool! Thanks for the script. This will do anyway, I just found out that armors couldn't be removed as well but don't worry about that the rest I can figure out on my own 8-).
 

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