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.

[Resolved]Changing battle damage font

Status
Not open for further replies.
Hey, can someone tell me which default script I need to edit to change the font used for the battle damage amounts? Help would be appreciated please!
 
The damage method is in the RPG::Sprite hidden class, but the help file has it.
Here you have the damage method:
Code:
module RPG
  class Sprite < ::Sprite
    def damage(value, critical)
      dispose_damage
      if value.is_a?(Numeric)
        damage_string = value.abs.to_s
      else
        damage_string = value.to_s
      end
      bitmap = Bitmap.new(160, 48)
      bitmap.font.name = "Arial Black" # Change the font here
      bitmap.font.size = 32
      bitmap.font.color.set(0, 0, 0)
      bitmap.draw_text(-1, 12-1, 160, 36, damage_string, 1)
      bitmap.draw_text(+1, 12-1, 160, 36, damage_string, 1)
      bitmap.draw_text(-1, 12+1, 160, 36, damage_string, 1)
      bitmap.draw_text(+1, 12+1, 160, 36, damage_string, 1)
      if value.is_a?(Numeric) and value < 0
        bitmap.font.color.set(176, 255, 144)
      else
        bitmap.font.color.set(255, 255, 255)
      end
      bitmap.draw_text(0, 12, 160, 36, damage_string, 1)
      if critical
        bitmap.font.size = 20
        bitmap.font.color.set(0, 0, 0)
        bitmap.draw_text(-1, -1, 160, 20, "CRITICAL", 1)
        bitmap.draw_text(+1, -1, 160, 20, "CRITICAL", 1)
        bitmap.draw_text(-1, +1, 160, 20, "CRITICAL", 1)
        bitmap.draw_text(+1, +1, 160, 20, "CRITICAL", 1)
        bitmap.font.color.set(255, 255, 255)
        bitmap.draw_text(0, 0, 160, 20, "CRITICAL", 1)
      end
      @_damage_sprite = ::Sprite.new(self.viewport)
      @_damage_sprite.bitmap = bitmap
      @_damage_sprite.ox = 80
      @_damage_sprite.oy = 20
      @_damage_sprite.x = self.x
      @_damage_sprite.y = self.y - self.oy / 2
      @_damage_sprite.z = 3000
      @_damage_duration = 40
    end
end
 
Code:
module RPG
  class Sprite < ::Sprite
    @@font = Font.new("Arial Black", 16)
    @@font.bold = true

    def self.font
      @@font
    end

    def self.font=(value)
      @@font = value
    end

    def damage(value, critical)
      dispose_damage
      if value.is_a?(Numeric)
        damage_string = value.abs.to_s
      else
        damage_string = value.to_s
      end
      bitmap = Bitmap.new(160, 48)
      bitmap.font = @@font.clone
      bitmap.font.color.set(0, 0, 0)
      bitmap.draw_text(-1, 12-1, 160, 36, damage_string, 1)
      bitmap.draw_text(+1, 12-1, 160, 36, damage_string, 1)
      bitmap.draw_text(-1, 12+1, 160, 36, damage_string, 1)
      bitmap.draw_text(+1, 12+1, 160, 36, damage_string, 1)
      if value.is_a?(Numeric) and value < 0
        bitmap.font.color.set(176, 255, 144)
      else
        bitmap.font.color.set(255, 255, 255)
      end
      bitmap.draw_text(0, 12, 160, 36, damage_string, 1)
      if critical
        bitmap.font.size = 20
        bitmap.font.color.set(0, 0, 0)
        bitmap.draw_text(-1, -1, 160, 20, "CRITICAL", 1)
        bitmap.draw_text(+1, -1, 160, 20, "CRITICAL", 1)
        bitmap.draw_text(-1, +1, 160, 20, "CRITICAL", 1)
        bitmap.draw_text(+1, +1, 160, 20, "CRITICAL", 1)
        bitmap.font.color.set(255, 255, 255)
        bitmap.draw_text(0, 0, 160, 20, "CRITICAL", 1)
      end
      @_damage_sprite = ::Sprite.new(self.viewport)
      @_damage_sprite.bitmap = bitmap
      @_damage_sprite.ox = 80
      @_damage_sprite.oy = 20
      @_damage_sprite.x = self.x
      @_damage_sprite.y = self.y - self.oy / 2
      @_damage_sprite.z = 3000
      @_damage_duration = 40
    end
  end
end

So, you should use...
Code:
RPG::Sprite.font = Font.new("Tahoma", 32")
... To define a new font. This is valid for ALL instances of RPG::Sprite (every object).
 
Well, I posted it all the way at the top, but nothing changed. I also put it above all my custom scripts, nothing. Is there a certain place it needs to be other then all the way at the top?
 
What are you saying? ^^
It works for all battles, and you have to change it only once. Substitute the font name in the script by the font name you want. By making that all damages will have that font. NOW, you can change them in mid-game too ,at any moment, by using the syntax:
Code:
RPG::Sprite.font = Font.new("font_name", font_size)
 
It still hasn't changed the font. It's the top most script, I put the font name in it, nothing. I tried using the small bit of code in a Script command, but it still doesn't work
 
Well it works perfectly for me. The only disadvantage is that bigger texts and font sizes can´t be shown properly. I even created a new skil to call a common event with that small piece of code inside a script call, and it changed the damage font INSIDE the battle. Check there if you haven´t done anything wrong or if you have any other script that rewrites the RPG::Sprite method (like Selwyn´s Damage script or any CBS script).
 
I don´t have this script (xD sorry i don´t have time to check it now). Please check to see if there´s ANY rewrite of the method damage in the RPG::Sprite class. If so, move my script to any place below those "rewrite" scripts. (Hope you understood...)

Or, post the script here for me to take a quick look... Maybe it´ll be necessary to change a few lines of code.
 
Alright, it works now, but there's a problem that I can live with, but it would be nice if it were fixed. When I attack the enemy, the damage shows up in the font I want, but then the damage amount won't leave. Like, if I hit the enemy for 344 damage, it'll show it, but the amount will stay there and won't leave until the battle ends. Is there anyway to fix this?
 
Status
Not open for further replies.

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