Chaos Project

RPG Maker => RPG Maker Scripts => Script Troubleshooting => Topic started by: Cal RPG MGS on April 07, 2011, 09:26:12 am

Title: Change the EXP to Current weapon (Blizz Abs) Script help
Post by: Cal RPG MGS on April 07, 2011, 09:26:12 am
Game:RPG XP
Blizz ABS: 2.8

I post a topic on RRR on how to change the EXP Meter on the HUD To the current Weapon and it Works but there are to problems.
The person who help me said there may be error but he was un sure of what they would be.

The first One is; when you use the quick weapon change, the name of the weapons over lap each other and do not replace.

the only work around i have to this is to keep going on to the menu to make it refresh

The Second one is if you do not have a weapon equip it causes the game to crash with the error message;
Line 49: NoMethodError occurred
undefined method 'name' for nil:NilClass

This is the edited script

#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=

if !$BlizzABS || BlizzABS::VERSION < 2.7
  raise 'ERROR: The "EXP in HUD" requires Blizz-ABS 2.7 or higher.'
end

#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# START Configuration
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

# word displayed for EXP
EXP_WORD = 'WPN'

#==============================================================================
# Hud
#==============================================================================

class Hud
 
  alias create_positions_expinhud_later create_positions
  def create_positions
    create_positions_expinhud_later
    @exp_x, @exp_y = 4, 49# + @hud_height - @original_height
    @hud_height += 16
    @hot_y += 16
    @left_y += 16
  end
 
  alias draw_basic_expinhud_later draw_basic
  def draw_basic
    draw_basic_expinhud_later
    color = case BlizzABS::Config::HUD_TYPE
    when 0 then Color.new(255, 255, 255, 192)
    when 1 then Color.new(0, 0, 0, 0)
    end
    self.bitmap.fill_rect(@exp_x+32, @exp_y+3, 116, 14, color) if color.is_a?(Color)
    self.bitmap.fill_rect(@exp_x, @exp_y, 32, 20, Color.new(0, 0, 0, 128))
    self.bitmap.font.color = system_color
    self.bitmap.draw_text_full(@exp_x, @exp_y, 80, 20, EXP_WORD)
    self.bitmap.font.color = normal_color
  end
 
  def draw_empty
    return
  end
 
  def draw_exp
    self.bitmap.font.color = normal_color
    self.bitmap.draw_text_full(@exp_x + 54, @exp_y, 84, 20, $data_weapons[$game_party.actors[0].weapon_id].name, 2)
  end
 
  alias upd_expinhud_later update
  def update
    redraw_weapon = ($game_temp.hud_refresh |= test_refresh)
    upd_expinhud_later
    draw_exp if redraw_weapon
  end
 
  def test_refresh
    @lastWeaponID = -1 if @lastWeaponID.nil?
    needs_refresh = @lastWeaponID != $game_party.actors[0].weapon_id
    @lastWeaponID = $game_party.actors[0].weapon_id
    return needs_refresh
  end

end
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=


Title: Re: Change the EXP to Current weapon (Blizz Abs) Script help
Post by: nathmatt on April 07, 2011, 12:30:13 pm
def draw_exp
    self.bitmap.font.color = normal_color
    self.bitmap.fill_rect(@exp_x + 54, @exp_y, 84, 20, Color.new(255, 255, 255, 192))
    self.bitmap.draw_text_full(@exp_x + 54, @exp_y, 84, 20, $data_weapons[$game_party.actors[0].weapon_id].name, 2)
  end
Title: :D
Post by: Cal RPG MGS on April 07, 2011, 10:29:53 pm
Thanks nathmatt  :D

Thats Solves the first problem, just the No weapon crash problem now :D
Title: Re: Change the EXP to Current weapon (Blizz Abs) Script help
Post by: Spaceman McConaughey on April 07, 2011, 10:45:01 pm
You don't seem to have a steady flow of Uranium going to your Flux Capacitor. Fix that, and you should be good. ;)
Title: Re: Change the EXP to Current weapon (Blizz Abs) Script help
Post by: ForeverZer0 on April 07, 2011, 10:56:22 pm
For the second problem, replace the "draw_exp" method with this::


  def draw_exp
    self.bitmap.font.color = normal_color
    wpn = $data_weapons[$game_party.actors[0].weapon_id]
    self.bitmap.draw_text_full(@exp_x + 54, @exp_y, 84, 20, wpn == nil ? 'None' : wpn.name, 2)
  end


The problem is, having no weapon equipped is the 0 index of $data_weapons, which is nil. NilClass doesn't have a "name" paramter to call. Using this little edit will show the word "None" when this occurs.
Title: Re: Change the EXP to Current weapon (Blizz Abs) Script help
Post by: Cal RPG MGS on April 08, 2011, 07:17:30 am
And now i will also thank ForeverZer0, that has saved a massive event based work around  :D

not sure how Tuggernuts post helps but i made me lol.

thanks for the help people.

---EDIT---

if i credit Nathmatt and ForeverZer0 would i be able to post this in the script database, i will say it was originaly created by Blizzard.

it just seems like a very used script(well for me it is and i have seen other requests) and i don't want it to die in time