Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #===============================================================================
- # * [ACE] Simple 1-Point Based HP HUD
- #===============================================================================
- # * Made by: Sixth (www.rpgmakervxace.net, www.forums.rpgmakerweb.com)
- # * Version: 1.0
- # * Updated: 06/06/2016
- # * Requires: ---------
- #-------------------------------------------------------------------------------
- # * < Change Log >
- #-------------------------------------------------------------------------------
- # * Version 1.0 (06/06/2016)
- # - Initial release.
- #-------------------------------------------------------------------------------
- # * < Description >
- #-------------------------------------------------------------------------------
- # * This script will make a HP HUD on the map which will, obviously, display
- # the party leader's HP.
- # * This script is made for games which use 1-point based HP.
- # What this means? Well, 1 point of HP is one picture displayed on the HUD.
- # Imagine if you got 500 HP, that would be 500 HP image, so yeah...
- # Only use this if your actors got way less HP in your game!
- # * Horizontal, vertical, and custom placement for your HP images!
- # * Flash effect on the affected HP images for gaining or losing HP (optional)!
- # * Show/hide the HUD with a switch!
- #-------------------------------------------------------------------------------
- # * < Installation >
- #-------------------------------------------------------------------------------
- # * Place this script between Materials and Main!
- #-------------------------------------------------------------------------------
- # * < Compatibility Info >
- #-------------------------------------------------------------------------------
- # * No known incompatibilities.
- #-------------------------------------------------------------------------------
- # * < Known Issues >
- #-------------------------------------------------------------------------------
- # * No known issues.
- #-------------------------------------------------------------------------------
- # * < Terms of Use >
- #-------------------------------------------------------------------------------
- # * Free to use for whatever purposes you want.
- # * Credit me (Sixth) in your game, pretty please! :P
- # * Posting modified versions of this script is allowed as long as you notice me
- # about it with a link to it!
- #===============================================================================
- $imported = {} if $imported.nil?
- $imported["Sixth1PHPHUD"] = true
- #===============================================================================
- # Settings:
- #===============================================================================
- module HPHUD
- #-----------------------------------------------------------------------------
- # HUD Settings:
- #-----------------------------------------------------------------------------
- # This is the setting area. Who would have guessed, right? :P
- #
- # I won't explain the obvious settings, those will only get a one-liner
- # layour explanation besides them.
- #
- # The not-so-obvious settings:
- #
- # - :spacing => value,
- # Actually, this is quite obvious, but just to be sure...
- # This only works if you set the :type setting to :horz or :vert!
- # Will NOT work if the :type is set to :spec!
- #
- # - :type => :horz/:vert/:spec,
- # This decides the layout of the HP images.
- # :horz = Horizontally lined up images.
- # :vert = Vertically lined up images.
- # :spec = Specific position settings for each HP image.
- # Uses the extra :spec setting to get the position of the images!
- # So, the :spec setting will let you place the HP images wherever you want,
- # not following any pre-made layout.
- #
- # - :spec => { * specific position settings here *},
- # And this is where the :spec type HUD gets the position for your HP images
- # on the HUD. Each position setting here corresponds to 1 HP.
- # You must make at least the same amount of position settings here than the
- # maximum amount of HP your actors can get!
- # The layout is simple:
- # index => [x,y],
- # The index must start from 0 and increments by 1 for each HP shown on the
- # HUD!
- #
- # - :flash => { * flash settings here *},
- # These are the flash effect settings.
- # When the player gains or lose HP, the affected HP images on the HUD can be
- # set to flash for a brief (or long? o.o) time.
- # The :gain setting is the flash effect for gained HP points, while the :lose
- # setting is for the lost HP points.
- # The :color setting is the color of the flash effect, uses RGBA codes!
- # The :dur setting is the duration of the flash effect in frames.
- # The duration setting for the :gain effect will directly set the flash effect
- # to that duration.
- # The duration setting for the :lose effect, however, will be divided by 3,
- # and the result will decide the actual duration of the effect. This is
- # because simply letting the fade effect to finish and make the HP images
- # disappear after that looked weird, so I decided to gradually fade out the
- # images, and they should disappear when the flash effect reaches it's highest
- # color (so, during the peak of the flash effect).
- # You can also disable the flash effects for both types (:gain/:lose) or for
- # only one type. To disable the effect for only one type, comment out the
- # line where the setting for it is. To disable all flash effects, either
- # comment out both lines for both types, or comment out this whole setting.
- #-----------------------------------------------------------------------------
- HUD = {
- :toggle => 10, # Switch ID. This switch can be used to toggle the HUD.
- :img => "hp_icon", # Image file name. Must be in "Graphics/Pictures/"!
- :pos => [20,10], # HUD position.
- :spacing => 2, # Spacing between each HP images.
- :z => 200, # The Z level of the HP images.
- :type => :horz, # Type of the HP image placement.
- :flash => { # Flash settings.
- :gain => {:color => Color.new(100,250,100,255), :dur => 30},
- :lose => {:color => Color.new(250,250,100,255), :dur => 40},
- },
- :spec => { # Specific HP image position settings. Used with the :spec type!
- 0 => [20,10],
- 1 => [43,14],
- 2 => [66,10],
- 3 => [89,14],
- 4 => [112,10],
- 5 => [135,14],
- 6 => [158,10],
- 7 => [181,14],
- 8 => [204,10],
- 9 => [227,14],
- 10 => [250,10],
- 11 => [273,10],
- 12 => [296,10],
- # <-- Add more position setting here if needed!
- },
- }
- end
- #===============================================================================
- # End of settings! O.o
- #===============================================================================
- class HP_HUD
- attr_accessor :visible
- def initialize(data,id=0)
- @data = data
- @id = id
- @actor = $game_party.members[id]
- @old_hp = @actor.hp
- @visible = $game_switches[HPHUD::HUD[:toggle]]
- init_hp_imgs
- end
- def init_hp_imgs
- @imgs = {}; @disp = {}
- @actor.hp.times do |i|
- init_img(i,false)
- end
- end
- def init_img(i,flash=true)
- @imgs[i] = Sprite.new
- @imgs[i].visible = @visible
- @imgs[i].bitmap = Cache.picture(@data[:img]).clone
- @imgs[i].z = @data[:z]
- case @data[:type]
- when :horz
- @imgs[i].x = @data[:pos][0] + i * (@imgs[i].bitmap.width + @data[:spacing])
- @imgs[i].y = @data[:pos][1]
- when :vert
- @imgs[i].x = @data[:pos][0]
- @imgs[i].y = @data[:pos][1] + i * (@imgs[i].bitmap.height + @data[:spacing])
- when :spec
- @imgs[i].x = @data[:pos][0] + @data[:spec][i][0]
- @imgs[i].y = @data[:pos][1] + @data[:spec][i][1]
- end
- if flash && @data[:flash] && @data[:flash][:gain]
- @imgs[i].flash(*@data[:flash][:gain].values)
- end
- end
- def toggle(state)
- @imgs.each_value {|sp| sp.visible = state }
- @visible = state
- end
- def update
- @imgs.each_value {|sp| sp.update }
- if @old_hp < @actor.hp
- change = @actor.hp - @old_hp
- change.times do |i|
- init_img(@imgs.size)
- end
- @old_hp = @actor.hp
- end
- if @old_hp > @actor.hp
- change = @old_hp - @actor.hp
- change.times do |i|
- if @data[:flash] && @data[:flash][:lose]
- @imgs[@imgs.size-1-i].flash(*@data[:flash][:lose].values)
- @disp[@imgs.size-1-i] = @data[:flash][:lose][:dur]/3
- else
- dispose_img(@imgs.size-1)
- end
- end
- @old_hp = @actor.hp
- end
- @disp.each do |key,val|
- if @disp[key] > 0
- @disp[key] -= 1
- if @disp[key] <= 0
- @imgs[key].opacity = 0
- else
- @imgs[key].opacity = 255 - 255/@disp[key]
- end
- else
- dispose_img(key)
- @disp.delete(key)
- end
- end
- end
- def dispose_img(i)
- return if @imgs[i].nil? || @imgs[i].disposed?
- @imgs[i].bitmap.dispose
- @imgs[i].dispose
- @imgs.delete(i)
- end
- def dispose
- @imgs.each_value {|sp| sp.bitmap.dispose; sp.dispose}
- end
- end
- class Spriteset_Map
- alias add_hp_hud7735 initialize
- def initialize
- add_hp_hud7735
- init_hp_hud
- end
- def init_hp_hud
- @hp_hud = HP_HUD.new(HPHUD::HUD) if $game_party.members.size > 0
- end
- alias update_hp_hud6625 update
- def update
- update_hp_hud6625
- if @hp_hud
- if @hp_hud.visible != $game_switches[HPHUD::HUD[:toggle]]
- @hp_hud.toggle($game_switches[HPHUD::HUD[:toggle]])
- end
- @hp_hud.update
- end
- end
- alias disp_hp_hud8826 dispose
- def dispose
- @hp_hud.dispose if @hp_hud
- disp_hp_hud8826
- end
- end
- #==============================================================================
- # !!END OF SCRIPT - OHH, NOES!!
- #==============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement