Krishna Siva 1 Posted October 18, 2014 (edited) KrishGM Simple HUD System Introduction What does this thing do? it shows you a transparent - backed HUD that shows your HP, MP, XP, Gold and Equipped weapon with an icon! The credit goes to me and Cidomar, for his HUD generator. This thing is toottaly editable! except the XP text. The Code So let's come to the code. =begin ---------- KrishGM's SimpleHUD System ---------- ---------- Credits ---------- Do credit me for making the HUD, and credit Cidomar for making the HUD Generator. ---------- Information ---------------------------------------------------------------------------------- This script shows a transparent HUD that shows your HP, MP, XP in the lower section of the screen and Gold. The are all easily editable by changing the options below except the XP text. Hope you like it =end #------------------------------------------------------------------------------- # # HUD Editable Section # #------------------------------------------------------------------------------- HUD = true # Change into false to turn off HUD. W_Icon = 148 #The Weapon Icon. G_Icon = 361 #The Gold Icon H_Text = 'HP:' #The HP text. Change to whatever you want. M_Text = 'MP:' #The MP text. Change to whatever you want. HP_X = 37 # Change for changing the horizontal or X position of the HP bar. MP_X = 37 # Change for changing the horizontal or X position of the MP bar. # Editable Area End ------------------------------------------------------------ #Please do not edit unless you know what these mean. module HUDWidgets #---------- class WidgetBase < Sprite def initialize(name, x, y, z) super() @name = name self.x, self.y, self.z = x, y, z end def z=(v) super(v + 60) end def z return super() - 60 end end #---------- class RectWidget < WidgetBase def initialize(name, x, y, z, w, h, color) super(name, x, y, z) @color = color bmp = Bitmap.new(w, h) bmp.fill_rect(bmp.rect, color) self.bitmap = bmp end end #---------- class ImageWidget < WidgetBase attr_accessor :zoom_x, :zoom_y def initialize(name, x, y, z, w, h, a, param, text, idx) super(name, x, y, z) @iw, @ih = w, h self.opacity = a @param, @text, @idx = param, text, idx case @param when 3 .. 16 self.bitmap = Cache.system('Iconset') self.src_rect = Rect.new(0, 0, 24, 24) update_icon end #----- @zoom_x_base = @iw.to_f / self.width @zoom_y_base = @ih.to_f / self.height self.zoom_x = 1.0 self.zoom_y = 1.0 end def zoom_x=(v) @zoom_x = v.to_f super(@zoom_x_base * @zoom_x) end def zoom_y=(v) @zoom_y = v.to_f super(@zoom_y_base * @zoom_y) end def update_icon return unless @param >= 3 actor = $game_party.leader i_idx = 0 case @param when 3 i_idx = @idx else i_idx = 0 end self.src_rect = Rect.new(i_idx % 16 * 24, i_idx / 16 * 24, 24, 24) end end #---------- class TextWidget < WidgetBase def initialize(name, x, y, z, param, text, id, fname, fsize, fbold, fitalic, fshadow, fcolor, foutline, foutline_color, tw, th, fix_from) super(name, x, y, z) #----- @fsize = fsize @fix_from = fix_from @initial_width = nil #----- @font = Font.new(fname, fsize) @font.bold = fbold @font.italic = fitalic @font.shadow = fshadow @font.outline = foutline @font.out_color = foutline_color @fbmp = Bitmap.new(1, 1) @fbmp.font = @font #----- @param, @text, @id = param, text, id @tw, @th = tw, th #----- r = @fbmp.text_size('Text') @font.size *= (@tw.to_f / r.width) #----- @fbmp.font = @font #----- self.oy = (((r.height * (@tw.to_f / r.width)) * (1.0 - (r.width / @tw.to_f))) * 0.5).ceil #----- update end def update actor = $game_party.leader case @param when 0 # Text str = @text when 3 # HP/Max HP str = (@text % [actor.hp, actor.mhp]) rescue (actor.hp + '/' + actor.mhp) when 6 # MP/Max MP str = (@text % [actor.mp, actor.mmp]) rescue (actor.mp + '/' + actor.mmp) when 9 # EXP/Next Level EXP str = (@text % [actor.exp, actor.next_level_exp]) rescue (actor.exp + '/' + actor.next_level_exp) when 14 # Gold Amount str = (@text % $game_party.gold) rescue '0' when 15 # Actor's Weapon str = (@text % actor.weapons.first.name) rescue '' else return end #----- self.bitmap.dispose if self.bitmap and not self.bitmap.disposed? return if str.empty? #----- r = @fbmp.text_size(str) bmp = self.bitmap = Bitmap.new(r.width + 32, r.height) bmp.font = @font bmp.draw_text(bmp.rect, str, 0) #----- @initial_width ||= self.width #----- case @fix_from when 0 self.ox = 0 when 1 self.ox = (self.width - @initial_width) / 2 when 2 self.ox = self.width - @initial_width end end end end class Scene_Map < Scene_Base #---------- alias :hud_alias_start :start alias :hud_alias_update :update alias :hud_alias_p_term :terminate #---------- def start hud_alias_start start_hud end #----- def start_hud @actor_info_cache, @var_info_cache, @hud_widgets = {}, {}, {} @hud_widgets[1] = HUDWidgets::TextWidget.new('HP text', 8, 7, 0, 0, H_Text, 0, 'Georgia', 12, false, false, false, Color.new(255, 255, 255, 255), false, Color.new(0, 0, 0, 255), 31, 12,0) @hud_widgets[2] = HUDWidgets::RectWidget.new('HP Bar', HP_X, 5, 1, 150, 20, Color.new(228, 39, 39, 255)) @hud_widgets[3] = HUDWidgets::TextWidget.new('MP text', 7, 33, 2, 0, M_Text, 0, 'Georgia', 12, false, false, false, Color.new(255, 255, 255, 255), false, Color.new(0, 0, 0, 255), 31, 12,0) @hud_widgets[4] = HUDWidgets::RectWidget.new('MP Bar', MP_X, 29, 3, 150, 20, Color.new(96, 171, 244, 255)) @hud_widgets[5] = HUDWidgets::TextWidget.new('Gold', 491, 6, 4, 14, '%d', 0, 'Georgia', 12, false, false, false, Color.new(255, 255, 255, 255), true, Color.new(255, 215, 0, 255), 31, 12,0) @hud_widgets[6] = HUDWidgets::ImageWidget.new('GoldIcon', 460, 2, 5, 24, 24, 255, 3, '', G_Icon) @hud_widgets[7] = HUDWidgets::ImageWidget.new('WeaponIcon', 8, 62, 6, 24, 24, 255, 3, '', W_Icon) @hud_widgets[8] = HUDWidgets::TextWidget.new('WeaponText', 40, 69, 7, 15, '%s', 0, 'Georgia', 12, false, false, false, Color.new(255, 255, 255, 255), false, Color.new(0, 0, 0, 255), 31, 12,0) @hud_widgets[9] = HUDWidgets::TextWidget.new('Exp Text', 7, 393, 8, 0, 'Xp:', 0, 'Georgia', 12, false, false, false, Color.new(255, 255, 255, 255), false, Color.new(0, 0, 0, 255), 31, 12,0) @hud_widgets[10] = HUDWidgets::RectWidget.new('Exp Bar', 39, 393, 9, 495, 15, Color.new(137, 237, 37, 255)) @hud_widgets[13] = HUDWidgets::TextWidget.new('HP lvl', 39, 8, 10, 3, '%d/%d', 0, 'Arial', 12, false, false, false, Color.new(211, 211, 211, 255), false, Color.new(0, 0, 0, 255), 31, 12,0) @hud_widgets[14] = HUDWidgets::TextWidget.new('MP lvl', 39, 32, 11, 6, '%d/%d', 0, 'Arial', 12, false, false, false, Color.new(211, 211, 211, 255), false, Color.new(0, 0, 0, 255), 31, 12,0) @hud_widgets[15] = HUDWidgets::TextWidget.new('XP lvl', 44, 395, 12, 9, '%d/%d', 0, 'Arial', 12, false, false, false, Color.new(255, 255, 255, 255), false, Color.new(0, 0, 0, 255), 31, 12,0) update_hud end #---------- def update hud_alias_update update_hud end #----- def update_hud actor = $game_party.leader if @actor_info_cache[:char_hp] != actor.hp or @actor_info_cache[:char_mhp] != actor.mhp @hud_widgets[2].zoom_y = (actor.hp.to_f / actor.mhp) @hud_widgets[13].update @actor_info_cache[:char_hp], @actor_info_cache[:char_mhp] = actor.hp, actor.mhp end if @actor_info_cache[:char_mp] != actor.mp or @actor_info_cache[:char_mmp] != actor.mmp @hud_widgets[4].zoom_y = (actor.mp.to_f / actor.mmp) @hud_widgets[14].update @actor_info_cache[:char_mp], @actor_info_cache[:char_mmp] = actor.mp, actor.mmp end if @actor_info_cache[:party_gold] != $game_party.gold @hud_widgets[5].update @actor_info_cache[:party_gold] = $game_party.gold end if @actor_info_cache[:char_equips] != actor.equips @hud_widgets[8].update @actor_info_cache[:char_equips] = actor.equips end if @actor_info_cache[:char_exp] != actor.exp or @actor_info_cache[:char_nl_exp] != actor.next_level_exp @hud_widgets[10].zoom_x = (actor.exp.to_f / actor.next_level_exp) @hud_widgets[15].update @actor_info_cache[:char_exp], @actor_info_cache[:char_nl_exp] = actor.exp, actor.next_level_exp end end #---------- def terminate hud_alias_p_term hud_dispose end #----- def hud_dispose @hud_widgets.each_value {|hw| hw.dispose } end #---------- end HUDWidgets unless HUD == false Screenies Our Site and Demo The master demo link: https://drive.google.com/file/d/0ByYnu01dAcF-aWZ5WVBkSUdBVlk/view?usp=sharing RGB Gamers Club Site: http://rgbgameworks.wordpress.com Thanks for seeing! Edited October 19, 2014 by KrishGM Share this post Link to post Share on other sites
crystalknight 28 Posted October 18, 2014 I have yet to try this one, and I can't really use it in the game I'm creating, BUT: I think this looks fantastic! I've also read that you are only 13years old, but you already got so much more scripting knowledge than me . Keep up the good work, one day you'll be an Amazing scripter! One remark though: I think you should let people know if they should credit you/pay you for your script . Share this post Link to post Share on other sites
Krishna Siva 1 Posted October 19, 2014 thanks crystalknight. and yeah, They should credit me and cidomar. after all the hud was created using his HUD Generator but I made some edits to the code! Share this post Link to post Share on other sites
Arufonsu 0 Posted December 15, 2014 undefined method on line 142 for "hp" Share this post Link to post Share on other sites