[XP] Blizz-ABS weapon equip HUD for Z-HUD

Started by RPGManiac3030, March 24, 2011, 10:51:11 pm

Previous topic - Next topic

RPGManiac3030

March 24, 2011, 10:51:11 pm Last Edit: January 21, 2012, 11:31:09 pm by RPGManiac3030
Blizz ABS Weapon Equip HUD for Z-HUD
Authors: RPGManiac3030
Version: 1.6
Type: Blizz-ABS Plugin/ Z-HUD addon
Key Term: Blizz-ABS Plugin



Introduction

(My first script post)
This addon/edit basically adds an equipped weapon HUD to the Z-HUD.
I've now edited the script so the weapon, skill, AND item hotkeys all appear on the screen (if you're not using direct hotkeys, of course)
I've also added a background picture to the weapon HUD. You can enable/disable this feature and change the picture in the config area of the script.
Features


  • Adds the player's/party leader's equipped weapon to the screen




Screenshots

Spoiler: ShowHide





Demo

N/A


Script

Spoiler: ShowHide

#+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
# Weapon Equip HUD for Z-HUD
# By RPGManiac3030
# Version 1.6
# www.chaos-project.com
#+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
# Version History:
#   v.1.0
#    -Original Release
#   v.1.1
#    -Removed direct hotkey code
#   v.1.2
#    -Added compatibility for no weapon equipped
#   v.1.3
#    -Added weapon background that displays when no weapon is equipped
#   v.1.4
#    -Added option to change order of the icons via config.
#   v.1.5
#    -Removed edits in v.1.4, and added a background to the weapon icon if desired
#   v.1.5.5
#    -Added option to change location of hotkeys/weapon HUD.
#   v.1.6
#    -Background images for weapon graphic can now be larger than 24x24.
#+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
# Features:
#   -Adds the player's equipped weapon to the HUD.
#   -Displays a graphic for when no weapon is equipped.
#+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
# Instructions:
# -Instructions for editing the config are located in that section.
# -Place this script right under Z-HUD and above main.
# -Place all graphics in your game's pictures folder.
#+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
# Improvements/ Things to change for next version:
# -Spread out icons to it doesn't look cluttered.
# -Improve efficiency of the code.
# -Return layout options?
#+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
if !$BlizzABS || BlizzABS::VERSION < 2.7
  raise 'Error: Weapon Equip Hud needs Blizz-ABS of version 2.7 or higher.'
end

#BEGIN CONFIGURATION
#==============================================================================
# module BlizzCFG
#==============================================================================
module BlizzCFG
 
  #Set to false to show a picture behind the equipped weapon, and true for none
  DISABLE_WEAPON_BACK = false
 
 
  Z_WEAPON_BACK = ''              #image to be displayed behind the weapon
 
 
  WEAPON_EMPTY = 'Weapon'        #image file for when no weapon is equipped
 
  HUD_X = 632                  #Horizontal location of HUD.
                               #This is where the right side of the hud will be!
                               #Take into effect the width of your 3 pictures
                               #in order to set this properly.
                               #The formula is: HUD's left side = HUD_X - width of 3 graphics
                               
  HUD_Y = 4                   #Vertical location of HUD.
 
#END CONFIGURATION
end
#==============================================================================
# DO NOT EDIT ANYTHING BELOW UNLESS YOU KNOW WHAT YOU'RE DOING!!!
#==============================================================================


#==============================================================================
# Hud
#------------------------------------------------------------------------------
#  This class was modified to support SR display and modify the number of
#  skills left to use.
#==============================================================================
class Hud
  #----------------------------------------------------------------------------
  # update
  #  Checks if HUD needs refreshing.
  #----------------------------------------------------------------------------
  def update
    # if actor doesn't exist
    if actor == nil
      # unless already drawn empty HUD
      unless @empty_hud_drawn
        # draw HUD template
        draw_basic
        # draw empty HP, SP and EXP bars
        draw_empty
        # empty HUD was drawn
        @empty_hud_drawn = true
      end
    else
      # if HUD needs refresh
      if $game_temp.hud_refresh
        # draw all data about actor
        draw_name
        draw_level
        draw_hp
        draw_sp
        draw_equip
        draw_hitem
        draw_litem
        unless BlizzABS::Config::DIRECT_HOTKEYS
          draw_hskill
          draw_lskill
        end
        # remove flag
        $game_temp.hud_refresh = nil
      else
        # draw data that needs to ve updated
        test_name
        test_level
        test_hp
        test_sp
        test_equip
        test_hitem
        test_litem
        unless BlizzABS::Config::DIRECT_HOTKEYS
          test_hskill
          test_lskill
        end
      end
      # empty HUD wasn't drawn
      @empty_hud_drawn = false
    end
  end
  #-------------------------------------------------------------------
  # draw_equip
  #  Draws the equipped weapon on the screen.
  #----------------------------------------------------------------------------
  def draw_equip
      b0 = RPG::Cache.picture(BlizzCFG::Z_WEAPON_BACK)
    if BlizzCFG::DISABLE_WEAPON_BACK == true
      @hotkey_sprite.bitmap.fill_rect(0, 0, 24, 24, Color.new(0, 0, 0, 0))
    else
      @hotkey_sprite.bitmap.fill_rect(0, 0, b0.width, b0.height, Color.new(0, 0, 0, 0))
      @hotkey_sprite.bitmap.blt(0, 0, b0, Rect.new(0, 0, b0.width, b0.height))
    end
    wpn = $data_weapons[$game_party.actors[0].weapon_id]
    if wpn != nil
      b1 = RPG::Cache.icon(wpn.icon_name)
      x, y = (b0.width - 24) / 2, (b0.height - 24) / 2
      @hotkey_sprite.bitmap.blt(x, y, b1, Rect.new(0, 0, 24, 24))
    else
       b1 = RPG::Cache.picture(BlizzCFG::WEAPON_EMPTY)
      x, y = (b0.width - 24) / 2, (b0.height - 24) / 2
      @hotkey_sprite.bitmap.blt(x, y, b1, Rect.new(0, 0, 24, 24))
    end
  end
  #----------------------------------------------------------------------------
  # draw_hskill
  #  Draws the skill hotkey on the screen.
  #---------------------------------------------------------------------------- 
  def draw_hskill
      @skill = actor.skill
      b1 = RPG::Cache.picture(BlizzCFG::Z_WEAPON_BACK)
      b2 = RPG::Cache.picture(BlizzCFG::Z_SKILL_BACK)
      x = b1.width + 4
      @hotkey_sprite.bitmap.fill_rect(x, 0, b2.width, b2.height, Color.new(0, 0, 0, 0))
      @hotkey_sprite.bitmap.blt(x, 0, b2, Rect.new(0, 0, b2.width, b2.height))
      if @skill != 0
        bitmap = RPG::Cache.icon($data_skills[@skill].icon_name)
        x, y = b1.width + 4 + (b2.width - 24) / 2, (b2.height - 24) / 2
        @hotkey_sprite.bitmap.blt(x, y, bitmap, Rect.new(0, 0, 24, 24))
      end
    draw_lskill
  end
  #----------------------------------------------------------------------------
  # draw_lskill
  # Draws the number of skills left to use.
  #----------------------------------------------------------------------------
  def draw_lskill
     b1 = RPG::Cache.picture(BlizzCFG::Z_WEAPON_BACK)
      x = b1.width + 4
      @hotkey_sprite.bitmap.fill_rect(x, @left_y, @left_x, 16, Color.new(0, 0, 0, 0))
      @skills_left = get_skills_left
      if @skill != nil && @skill > 0
        if @skills_left >= 0
          if @skills_left == 0
            @hotkey_sprite.bitmap.font.color = Color.new(255, 0, 0)
          elsif @skills_left <= 5
            @hotkey_sprite.bitmap.font.color = Color.new(255, 255, 0)
          else
            @hotkey_sprite.bitmap.font.color = normal_color
          end
          @hotkey_sprite.bitmap.font.size -= 2
          @hotkey_sprite.bitmap.draw_text_full(x, @left_y - 4, @left_x, 20, @skills_left.to_s, 1)
          @hotkey_sprite.bitmap.font.size += 2
        elsif @skills_left == -1
          @hotkey_sprite.bitmap.font.color = Color.new(0, 255, 0)
          @hotkey_sprite.bitmap.font.size += 4
          @hotkey_sprite.bitmap.draw_text_full(x, @left_y - 4, @left_x, 20, '∞', 1)
          @hotkey_sprite.bitmap.font.size -= 4
        end
      end
    end
 
  #----------------------------------------------------------------------------
  # draw_hitem
  # Draws the item hotkey on the screen.
  #----------------------------------------------------------------------------
  def draw_hitem
    @item = actor.item
    b1 = RPG::Cache.picture(BlizzCFG::Z_WEAPON_BACK)
    b2 = RPG::Cache.picture(BlizzCFG::Z_SKILL_BACK)
    b3 = RPG::Cache.picture(BlizzCFG::Z_ITEM_BACK)
    x = b1.width + b2.width + 4
    @hotkey_sprite.bitmap.fill_rect(x, 0, b3.width, b3.height, Color.new(0, 0, 0, 0))
    @hotkey_sprite.bitmap.blt(x, 0, b3, Rect.new(0, 0, b3.width, b3.height))
    if @item != 0
      bitmap = RPG::Cache.icon($data_items[@item].icon_name)
      x, y = b1.width + b2.width + 4 + (b3.width - 24) / 2, (b3.height - 24) / 2
      @hotkey_sprite.bitmap.blt(x, y, bitmap, Rect.new(0, 0, 24, 24))
    end
    draw_litem
  end
 
  #----------------------------------------------------------------------------
  # draw_litem
  # Draws the number of items left to use.
  #----------------------------------------------------------------------------
  def draw_litem
    @items_left = $game_party.item_number(@item)
    b1 = RPG::Cache.picture(BlizzCFG::Z_WEAPON_BACK)
    b2 = RPG::Cache.picture(BlizzCFG::Z_SKILL_BACK)
    x = b1.width + b2.width + 4
    @hotkey_sprite.bitmap.fill_rect(x, @left_y, @left_x, 16, Color.new(0, 0, 0, 0))
    if @item != nil && @item > 0
      if $data_items[@item] != nil && !$data_items[@item].consumable
        @hotkey_sprite.bitmap.font.color = Color.new(0, 255, 0)
        @hotkey_sprite.bitmap.font.size += 4
        @hotkey_sprite.bitmap.draw_text_full(x, @left_y - 4, @left_x, 20, '∞', 1)
        @hotkey_sprite.bitmap.font.size -= 4
      else
        if @items_left == 0
          @hotkey_sprite.bitmap.font.color = Color.new(255, 0, 0)
        elsif @items_left <= 10
          @hotkey_sprite.bitmap.font.color = Color.new(255, 255, 0)
        else
          @hotkey_sprite.bitmap.font.color = normal_color
        end
        @hotkey_sprite.bitmap.font.size -= 2
        @hotkey_sprite.bitmap.draw_text_full(x, @left_y - 4, @left_x, 20, @items_left.to_s, 1)
        @hotkey_sprite.bitmap.font.size += 2
      end
    end
  end
 
  #----------------------------------------------------------------------------
  # test_equip
  #  Tests and draws the equipment.
  #----------------------------------------------------------------------------
  def test_equip
    # tests if the weapon was changed
    draw_equip if actor.weapon_id != nil
  end
 
  #----------------------------------------------------------------------------
  # init_hotkey_sprite(viewport)
  # Sets up the area where the hotkey icons and equipped weapon will be drawn.
  #----------------------------------------------------------------------------
  def init_hotkey_sprite(viewport)
    b1 = RPG::Cache.picture(BlizzCFG::Z_WEAPON_BACK)
    b2 = RPG::Cache.picture(BlizzCFG::Z_ITEM_BACK)
    b3 = RPG::Cache.picture(BlizzCFG::Z_SKILL_BACK)
    width = b1.width + b2.width + b3.width
    @hotkey_sprite = Sprite.new(viewport)
    @hotkey_sprite.x = BlizzCFG::HUD_X - width
    @hotkey_sprite.y = BlizzCFG::HUD_Y
    @hotkey_sprite.bitmap = Bitmap.new(width + 4, b1.height + 24)
    @hotkey_sprite.bitmap.font.name = 'Times New Roman'
    @hotkey_sprite.bitmap.font.size = 16
    @hotkey_sprite.bitmap.font.bold = true
  end
end
$BlizzABS = BlizzABS::Processor.new




Instructions

Put the script below Blizz-ABS and BELOW the Z-HUD. Set DISABLE_WEAPON_BACK to false to allow a picture to be displayed behind the weapon graphic (set what picture will display in the script!), or set to true to disable this picture. You also need to create an "empty weapon" file, which should be the same dimensions as the item and skill back pictures. Name it Weapon and place it in the pictures folder, or name it anything you want and edit the appropriate place in the script. It would be a fist or anything you want that will show when the player is unarmed. You can either make your own, or use this one. I got this graphic from http://www.pixeljoint.com/files/icons/full/34x34icons.png Place all graphics in your game's pictures folder!

Spoiler: ShowHide



Compatibility

  • Requires Blizz ABS and Z-HUD to work.

  • Any other script that modifies the Z-HUD may not be compatible.

  • Works with the Quick weapon switch addon by Blizzard perfectly.


Credits and Thanks


  • Blizzard

  • Winkio

  • ForeverZer0 (For help with fixing the no weapon problem)





Author's notes
I kind of just did this version and didn't test it yet...if anyone has a problem, please let me know!


Official Gio website:
gioadventures.freehostingcloud.com (under construction)

AliveDrive

Do not listen to spammer,

I like your script quite a bit! ^.^
Quote from: Blizzard on September 09, 2011, 02:26:33 am
The permanent solution for your problem would be to stop hanging out with stupid people.

Blizzard

Quote from: RPGManiac3030 on March 24, 2011, 10:51:11 pm
Key Term: Blizz-ABS Plugin Z-HUD


That key term doesn't exist. Please make sure you are using only key terms that exist.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

RPGManiac3030

Quote from: Blizzard on March 25, 2011, 02:33:05 am
Quote from: RPGManiac3030 on March 24, 2011, 10:51:11 pm
Key Term: Blizz-ABS Plugin Z-HUD


That key term doesn't exist. Please make sure you are using only key terms that exist.


Sorry about that, Blizz!


Official Gio website:
gioadventures.freehostingcloud.com (under construction)

Blizzard

Thank you. Now your topic can be moved into the database and will appear in the database index.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

RPGManiac3030

I looked through again...and I realized that an error will appear if you try to use an item. I originally edited the different parts of Blizz-ABS directly which made it work. I then put my edits into a separate script and posted it here to make it convenient for others.


You need to find this part in PART 2 of the Blizz-ABS:
Spoiler: ShowHide
    #--------------------------------------------------------------------------
   # check_item_condition?
   #  Checks whether a item should be executed or not.
   #--------------------------------------------------------------------------
   def check_item_condition?
     # disallow usage if item button disabled
     return false if !$game_system.item_button
     # disallow usage
     item_condition = false
     # if using direct hotkeys
     if BlizzABS::Config::DIRECT_HOTKEYS
       # check direct hotkeys
       item_condition = self.item_hotkeys?
     # if item button pressed
     elsif Input.trigger?(Input::Item)
       # allow usage
       item_condition = true
     end
     # return result
     return item_condition
   end



and replace it with the code found in my script:
Spoiler: ShowHide
    #--------------------------------------------------------------------------
   # check_item_condition?
   #  Checks whether a item should be executed or not.
   #--------------------------------------------------------------------------
   def check_item_condition?
     # disallow usage if item button disabled
     return false if !$game_system.item_button
     # disallow usage
     item_condition = false
     # if using direct hotkeys
     if BlizzABS::Config::DIRECT_HOTKEYS
       if Input.trigger?(Input::Item)
         # allow usage
         item_condition = true
       end
     end
     # return result
     return item_condition
   end


After this, you need to remove this part from my script:
Spoiler: ShowHide
module BlizzABS
 #============================================================================
 # BlizzABS::Controls
 #----------------------------------------------------------------------------
 #  This class handles player input for battle on the map.  Some input is
 #  processed instantly, while some is converted into commands to be given to
 #  the player character.
 #============================================================================
 
 class Controls
   #--------------------------------------------------------------------------
   # check_item_condition?
   #  Checks whether a item should be executed or not.
   #--------------------------------------------------------------------------
   def check_item_condition?
     # disallow usage if item button disabled
     return false if !$game_system.item_button
     # disallow usage
     item_condition = false
     # if using direct hotkeys
     if BlizzABS::Config::DIRECT_HOTKEYS
       if Input.trigger?(Input::Item)
         # allow usage
         item_condition = true
       end
     end
     # return result
     return item_condition
   end
 end
end


I'll edit the script and add another spoiler for the code. I'm new to scripting, so I'm not completely sure how to get all of this to work how I originally had it in the script.


Official Gio website:
gioadventures.freehostingcloud.com (under construction)

Blizzard

Actually you don't have to do that. You can simply add that part in your script and if it is put below Blizz-ABS and Z-HUD (which it should since it's a plugin for both), it will simply override the original code.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

RPGManiac3030

March 26, 2011, 09:32:01 pm #7 Last Edit: March 26, 2011, 09:42:58 pm by RPGManiac3030
Doing that still gets the same error. I don't remember seeing this before taking my edits and putting it into this script. I'm trying to look into this.



Official Gio website:
gioadventures.freehostingcloud.com (under construction)

Blizzard

Change in the error giving line item_number to $game_party.item_number.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

RPGManiac3030

April 10, 2011, 01:33:57 pm #9 Last Edit: April 10, 2011, 01:56:24 pm by RPGManiac3030
Version 1.1 is now out

Improvments/Changes:

-All 3 icons will appear in the hud (weapon, skill, and item)
-My edits to the direct hotkeys have been REMOVED for the purposes of posting this script


For the next version:
-I need to learn how to make the script shorter...


Official Gio website:
gioadventures.freehostingcloud.com (under construction)

Boba Fett Link

This post will self-destruct in 30 seconds.

Boba Fett Link

So what do I need to name the Equip hotkey background?
This post will self-destruct in 30 seconds.

Kagutsuchi

I just want to point out that the game crashed when I unequipped my weapon

Great work btw, I would have to do this myself for TES, and go through the painfull process of learning ruby and finding out what I need to do with blizz abs, but now I dont have to =D Thanks!

ForeverZer0

The "draw_equip" method has no way to compensate for no weapon equipped.

This should fix it (untested):
  def draw_equip
    wpn = $data_weapons[$game_party.actors[0].weapon_id]
    @hotkey_sprite.bitmap.fill_rect(0, 0, 24, 24, Color.new(0, 0, 0, 0))
    @hotkey_sprite.bitmap.font.color = normal_color
    @hotkey_sprite.bitmap.font.size = 14
    if wpn != nil
      icon = RPG::Cache.icon(wpn.name)
      x, y = (icon.width - 24) / 2, (icon.height - 24) / 2
      @hotkey_sprite.bitmap.blt(x, y, icon, Rect.new(0, 0, 24, 24))
    end
  end
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

RPGManiac3030

May 05, 2011, 12:54:05 am #14 Last Edit: May 05, 2011, 01:13:54 am by RPGManiac3030
Sorry, guys, I've been on vacation for the past month...

I never noticed that problem before, but I'll post up an updated version soon!

Quote from: Boba Fett Link on April 16, 2011, 07:09:01 am
So what do I need to name the Equip hotkey background?


The background is simply the icon of the weapon you have equipped. To be safe, I would name the icon graphic the same as the weapon name in the database.

EDIT:

Version 1.2 is now out!

New features:
-The no weapon problem has now been fixed.
-You need to specify a graphic for the "Weapon Back", similar to the skill and item backs. Simply make an image the same size as the other backs, save it in your pictures folder as "Weapon", and you're done! It should be preferably empty since it won't show up on screen anyway. I had to do this so that the bitmap can always draw itself without relying on the player's equipped weapon since he/she may not always have one.


Official Gio website:
gioadventures.freehostingcloud.com (under construction)

ForeverZer0

Just use
RPG::Cache.icon(weapon.icon_name)


As long as you have it set right in the editor, it will get the right graphic.

I also just noticed that I made the error in my above post by using "wpn.name".
It should be "wpn.icon_name"

Oops.  :P
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

RPGManiac3030

Maybe, but I tried using the code and I still got an error since I had previously set it so that the weapon icon graphic is being used to set the position of the next hotkey graphic. If you have no weapon equipped, there wouldn't be a graphic to use...


Official Gio website:
gioadventures.freehostingcloud.com (under construction)

ForeverZer0

Quote from: ForeverZer0 on April 17, 2011, 02:50:43 pm
The "draw_equip" method has no way to compensate for no weapon equipped.

This should fix it (untested):
  def draw_equip
   wpn = $data_weapons[$game_party.actors[0].weapon_id]
   @hotkey_sprite.bitmap.fill_rect(0, 0, 24, 24, Color.new(0, 0, 0, 0))
   @hotkey_sprite.bitmap.font.color = normal_color
   @hotkey_sprite.bitmap.font.size = 14
   if wpn != nil
     icon = RPG::Cache.icon(wpn.icon_name)
     x, y = (icon.width - 24) / 2, (icon.height - 24) / 2
     @hotkey_sprite.bitmap.blt(x, y, icon, Rect.new(0, 0, 24, 24))
   end
 end



Hence I posted this.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

RPGManiac3030

May 05, 2011, 01:22:41 am #18 Last Edit: May 05, 2011, 01:26:24 am by RPGManiac3030
Yeah, I took that and placed it right into my code, and I still got errors.

EDIT: I'll leave it the way it is for now, since it works, but if I can get the code to work without needing that graphic, I'll post it as another update.


Official Gio website:
gioadventures.freehostingcloud.com (under construction)

ForeverZer0

What errors?
I can say with pretty much 100% certainty that the error is not in that method.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.