Cozziekuns's Earthbound system Mortal Damage

Hi Forum! I'm working into a project that takes inspiration from Earthbound.
During my test-plays I realized that I couldn't tell when the player would die because there is no Mortal Damage indicator.

In Earthbound, Mortal Damage occurs when a party member takes damage which would reduce their HP to 0. Because of the Rolling HP Meter, the character is not instantly knocked. If the affected character is healed before their HP reaches 0, they will have successfully avoided fainting until taking mortal damage again. It even has a distinctive sound effect when you receive mortal damage

I am looking something similar to this with Cozziekuns's EarthBound style script, hope someone can help me with this and I would really appreciate it!

Spoiler: Script
#==============================================================================
# ** Earthbound-Ish Battle Core
#------------------------------------------------------------------------------
# Version: 1.0
# Author: cozziekuns
# Date: February 17, 2013
#==============================================================================
# Description:
#------------------------------------------------------------------------------
# This script attempts to mimic the battle system of the Earthbound/Mother
# series; most notably Earthbound and Earthbound 2 (Mother 2 and 3).
#==============================================================================
# Instructions:
#------------------------------------------------------------------------------
# Paste this script into its own slot in the Script Editor, above Main but
# below Materials. Edit the modules to your liking.
#==============================================================================

#==============================================================================
# ** Cozziekuns
#==============================================================================

module Cozziekuns

module Earthboundish

ActorIcons ={
# Command Name => IconID
"Attack" => 116,
"PSI" => 8,
"Guard" => 506,
"Items" => 264,
"Run" => 1084,
}

end

end

include Cozziekuns

#==============================================================================
# ** Sprite Battler
#==============================================================================

class Sprite_Battler

alias coz_ebish_spbtlr_update_effect update_effect
def update_effect(*args)
update_select_whiten if @effect_type == :select_white
if @battler.sprite_effect_type == :select_white_to_normal
revert_to_normal
@battler.sprite_effect_type = nil
end
coz_ebish_spbtlr_update_effect(*args)
end

def update_select_whiten
self.color.set(255, 255, 255, 0)
self.color.alpha = 128
end

end

#==============================================================================
# ** Window_ActorCommand
#==============================================================================

class Window_ActorCommand

def visible_line_number
return 1
end

def col_max
return 6
end

def contents_height
item_height
end

def top_col
ox / (item_width + spacing)
end

def top_col=(col)
col = 0 if col < 0
col = col_max - 1 if col > col_max - 1
self.ox = col * (item_width + spacing)
end

def bottom_col
top_col + col_max - 1
end

def bottom_col=(col)
self.top_col = col - (col_max - 1)
end

def ensure_cursor_visible
self.top_col = index if index < top_col
self.bottom_col = index if index > bottom_col
end

def item_rect(index)
rect = super
rect.x = index * (item_width + spacing)
rect.y = 0
rect
end

def window_width
Graphics.width - 224
end

def open
@help_window.open
super
end

def close
@help_window.close
super
end

def update
super
@help_window.update
end

def draw_item(index)
rect = item_rect_for_text(index)
x = rect.x + rect.width / 2 - 12
y = item_rect_for_text(index).y
draw_icon(Earthboundish::ActorIcons[command_name(index)], x, y, command_enabled?(index))
end

alias coz_ebish_waccmd_make_command_list make_command_list
def make_command_list(*args)
coz_ebish_waccmd_make_command_list(*args)
add_escape_command
end

def add_escape_command
add_command(Vocab::escape, :escape, BattleManager.can_escape?)
end

def update_help
@help_window.set_text(command_name(index))
end

end

#==============================================================================
# ** Window_BattleStatus
#==============================================================================

class Window_BattleStatus

[:basic_area_rect, :gauge_area_rect].each { |method|
define_method(method) { |index|
rect = item_rect(index)
rect
}
}

def col_max
$game_party.members.size
end

def window_width
Graphics.width / ( 4 / $game_party.members.size.to_f )
end

def window_height
fitting_height($data_system.opt_display_tp ? 5 : 4)
end

def item_width
(window_width - standard_padding * 2) / $game_party.members.size
end

def item_height
(window_height - standard_padding * 2)
end

def draw_basic_area(rect, actor)
draw_actor_name(actor, rect.x, rect.y, rect.width)
draw_actor_icons(actor, rect.x + 4, rect.y + line_height, rect.width)
end

def draw_gauge_area_with_tp(rect, actor)
draw_gauge_area_without_tp(rect, actor)
draw_actor_tp(actor, rect.x + 4, rect.y + line_height * 4, rect.width - 8)
end

def draw_gauge_area_without_tp(rect, actor)
draw_actor_hp(actor, rect.x + 4, rect.y + line_height * 2, rect.width - 8)
draw_actor_mp(actor, rect.x + 4, rect.y + line_height * 3, rect.width - 8)
end

def draw_actor_name(actor, x, y, width = 112)
change_color(hp_color(actor))
draw_text(x, y, width, line_height, actor.name, 1)
end

alias coz_ebish_wbtlsts_item_rect item_rect
def item_rect(index, *args)
rect = coz_ebish_wbtlsts_item_rect(index, *args)
rect.x = index % col_max * item_width
rect
end

def update
super
update_position
end

def update_position
self.x = (Graphics.width - window_width) / 2 + 128
end

end

#==============================================================================
# ** Window_BattleActor
#==============================================================================

class Window_BattleActor

def update_position
self.x = (Graphics.width - window_width) / 2
end

end

#==============================================================================
# ** Window_BattleEnemy
#==============================================================================

class Window_BattleEnemy

def cursor_left(wrap)
select((index - 1 + item_max) % item_max)
end

def cursor_right(wrap)
select((index + 1) % item_max)
end

def cursor_up(wrap)
cursor_left(true)
end

def cursor_down(wrap)
cursor_right(true)
end

def show
select(0)
self
end

def update_help
@help_window.set_text(enemy.name)
end

end

#==============================================================================
# ** Window_BattleSkill + Window_BattleItem
#==============================================================================

[:Window_BattleSkill, :Window_BattleItem].each { |klass|
Object.const_get(klass).send🙂define_method, :show) {
select_last
super()
}
Object.const_get(klass).send🙂define_method, :hide) { super() }
}

#==============================================================================
# ** Window_ActorHelp
#==============================================================================

class Window_ActorHelp < Window_Help

def initialize
super(1)
self.openness = 0
update_position
end

def update_position
self.x = Graphics.width - 224
self.width = 224
create_contents
end

def refresh
contents.clear
draw_text(4, 0, 224 - standard_padding * 2, line_height, @text, 1)
end

end

#==============================================================================
# ** Scene_Battle
#==============================================================================

class Scene_Battle

def start_party_command_selection
unless scene_changing?
@status_window.open
@status_window.refresh
if BattleManager.input_start
next_command
start_actor_command_selection
else
@party_command_window.deactivate
turn_start
end
end
end

def create_actor_command_window
@actor_command_window = Window_ActorCommand.new
@actor_command_window.set_handler🙂attack, method🙂command_attack))
@actor_command_window.set_handler🙂skill, method🙂command_skill))
@actor_command_window.set_handler🙂guard, method🙂command_guard))
@actor_command_window.set_handler🙂item, method🙂command_item))
@actor_command_window.set_handler🙂escape, method🙂command_escape))
@actor_command_window.set_handler🙂cancel, method🙂prior_command))
@actor_command_window.help_window = Window_ActorHelp.new
end

def create_help_window
@help_window = Window_Help.new(1)
@help_window.visible = false
end

alias coz_ebish_scbtl_create_enemy_window create_enemy_window
def create_enemy_window(*args)
coz_ebish_scbtl_create_enemy_window(*args)
@enemy_window.help_window = @actor_command_window.help_window
end

alias coz_ebish_scbtl_update_basic update_basic
def update_basic(*args)
old_enemy = @enemy_window.active ? @enemy_window.enemy : nil
coz_ebish_scbtl_update_basic(*args)
update_enemy_whiten(old_enemy)
end

def update_enemy_whiten(old_enemy)
if !@enemy_window.active or old_enemy != @enemy_window.enemy
old_enemy.sprite_effect_type = :select_white_to_normal if old_enemy && !old_enemy.dead?
end
@enemy_window.enemy.sprite_effect_type = :select_white if @enemy_window.active
end

def update_info_viewport
move_info_viewport(128)
end

end
You need to place scripts in a code block inside the spoiler block.

The attached script does not do anything for the earthbound health slow countdown.
It's the Odometer script.

Taking from that and removing the graphic, this does what you want with the default status
Spoiler: Modified Odometer
Ruby:
#==============================================================================
# ** Earthbound-Ish Odometer Roll [Graphical Edit]
#------------------------------------------------------------------------------
# Version: 1.0
# Author: cozziekuns
# Thread: rmrk.net/index.php?topic=47693.0
# Date: February 17, 2013
# Edit date: October 24, 2020
#==============================================================================
# Edit:
# Removes the odometer graphics. Just drains HP and MP with default gauges.
# Credit the original author (cozziekuns) and follow their terms of use
#==============================================================================
# Description:
#------------------------------------------------------------------------------
# This script attempts to emulate the battle system of the Earthbound/Mother
# series; most notably Earthbound and Earthbound 2 (Mother 2 and 3). This
# certain addon addresses the infamous HP/MP scrolling system that made battles
# that much more intense.
#==============================================================================
# Instructions:
#------------------------------------------------------------------------------
# Paste this script into its own slot in the Script Editor, above Main but
# below Materials. Edit the modules to your liking.
#==============================================================================
# [Unneeded] Graphics:
#------------------------------------------------------------------------------
# You must have two Odometer pictures in your Graphics/System folder. One of
# them must be named "Odometer_HP", and the other one must be named
# "Odometer_MP". Obviously, they represent the odometer for HP and MP values,
# respectively
#==============================================================================

#==============================================================================
# ** Cozziekuns
#==============================================================================

module Cozziekuns

  module Earthboundish
   
    Odometer_Roll_Speed = 2 # Smaller speeds are faster than larger speeds.
    Mortal_Damage_Msg = "%s took mortal damage and will die"
    Sound = RPG::ME.new("Item", 100, 100)
  end

end

include Cozziekuns

#==============================================================================
# ** Game_Actor
#==============================================================================

class Game_Actor

  attr_accessor :odometer_hp
  attr_accessor :odometer_mp

  alias coz_ebisohd_gmactr_setup setup
  def setup(actor_id, *args)
    coz_ebisohd_gmactr_setup(actor_id, *args)
    @odometer_hp = 0
    @odometer_mp = 0
  end

  alias coz_ebishod_gmactr_execute_damage execute_damage
  def execute_damage(user, *args)
    if $game_party.in_battle
      on_damage(@result.hp_damage) if @result.hp_damage > 0
      @odometer_hp += @result.hp_damage
      @odometer_mp += @result.mp_damage
      user.hp += @result.hp_drain
      user.mp += @result.mp_drain
      if @odometer_hp >= self.hp
        me = Earthboundish::Sound
        me.play
        $game_message.add(sprintf(Earthboundish::Mortal_Damage_Msg, self.name))
      end
    else
      coz_ebishod_gmactr_execute_damage(user, *args)
    end
  end

  [:hp, :mp].each { |stat|
    alias_method("coz_ebishod_gmactr_item_effect_recover_#{stat}".to_sym, "item_effect_recover_#{stat}".to_sym)
    define_method("item_effect_recover_#{stat}".to_sym) { |user, item, effect|
      if $game_party.in_battle
        value = (send("m#{stat}".to_sym) * effect.value1 + effect.value2) * rec
        value *= user.pha if item.is_a?(RPG::Item)
        value = value.to_i
        @result.send("#{stat}_damage=".to_sym, @result.send("#{stat}_damage".to_sym) - value)
        @result.success = true
        send("odometer_#{stat}=".to_sym, send("odometer_#{stat}".to_sym) - value)
      else
        send("coz_ebishod_gmactr_item_effect_recover_#{stat}".to_sym, user, item, effect)      
      end
    }
  }

end

#==============================================================================
# ** Game_Enemy
#==============================================================================

class Game_Enemy

  def execute_damage(user)
    on_damage(@result.hp_damage) if @result.hp_damage > 0
    self.hp -= @result.hp_damage
    self.mp -= @result.mp_damage
    user.odometer_hp -= @result.hp_drain
    user.odometer_mp -= @result.mp_drain
  end

end

#==============================================================================
# ** Scene_Battle
#==============================================================================

class Scene_Battle

  alias coz_ebishod_scbtl_start start
  def start
    coz_ebishod_scbtl_start
    @timerod = 0
  end

  alias coz_ebishod_scbtl_update_basic update_basic
  def update_basic(*args)
    coz_ebishod_scbtl_update_basic(*args)
    update_odometer
  end

  def update_odometer
    $game_party.members.each { |actor|
      if actor.odometer_hp != 0 or actor.odometer_mp != 0
        if actor.odometer_hp != 0 and Graphics.frame_count % Earthboundish::Odometer_Roll_Speed == 0
          damage = actor.odometer_hp > 0 ? 1 : - 1
          actor.hp -= damage
          actor.odometer_hp -= damage
        end
        if actor.odometer_mp != 0 and Graphics.frame_count % Earthboundish::Odometer_Roll_Speed == 0
          damage = actor.odometer_mp > 0 ? 1 : - 1
          actor.mp -= damage
          actor.odometer_mp -= damage
        end
        if @timerod == Earthboundish::Odometer_Roll_Speed
          @status_window.refresh
          @timerod = 0
        else
          @timerod += 1
        end
      end
    }
  end

end
The script works fine, but what I want to add is an alternative message that says "%s took mortal damage" when the HP will go to 0 and the character still receives damage because the odometer hasn't been set to 0, I also want to add a sound effect when the character receives the mortal damage and a screen shaking effect.

Sorry if this is a bit demanding, I'm not that good at scripting x'D
Code above updated.

Did some testing and there is a processing flaw. after getting damaged and using a potion to recover the count still goes down.

Also doing the shake is not working for me. Maybe @Timtrack can help with that.

*update. Found a fix for the item recover. Hopefully that works for all circumstances
Thanks! I will test it later!
Did some testing, works great but is there any way to keep the odometer graphics and put the message on top of the screen? Thanks!
Did some testing, works great but is there any way to keep the odometer graphics and put the message on top of the screen? Thanks!
You never requested to use the odometer graphics.
Then just use the original script. I can make the small adjustment for the sound and message.
Not entirely sure about getting it at the top, will try. works.
Spoiler: Odometer roll v1.2 with message
Ruby:
#==============================================================================
# ** Earthbound-Ish Odometer Roll
#------------------------------------------------------------------------------
# Version: 1.2
# Author: cozziekuns 
# fix by roninator2
# Date: February 17, 2013
#==============================================================================
# Description:
#------------------------------------------------------------------------------
# This script attempts to emulate the battle system of the Earthbound/Mother 
# series; most notably Earthbound and Earthbound 2 (Mother 2 and 3). This 
# certain addon addresses the infamous HP/MP scrolling system that made battles
# that much more intense.
#==============================================================================
# Instructions:
#------------------------------------------------------------------------------
# Paste this script into its own slot in the Script Editor, above Main but 
# below Materials. Edit the modules to your liking.
#==============================================================================
# Graphics:
#------------------------------------------------------------------------------
# You must have two Odometer pictures in your Graphics/System folder. One of 
# them must be named "Odometer_HP", and the other one must be named 
# "Odometer_MP". Obviously, they represent the odometer for HP and MP values,
# respectively
#==============================================================================

#==============================================================================
# ** Cozziekuns
#==============================================================================

module Cozziekuns
  
  module Earthboundish
    
    Odometer_Roll_Speed = 4 # Smaller speeds are faster than larger speeds.
    Four_Digits = false
    # data for when actor is fataly damaged
    Mortal_Damage_Msg = "%s took mortal damage and will die"
    Position = 0 # 0 = top, 1 = middle, 2 = default (bottom)
    Sound = RPG::ME.new("Item", 100, 100)
    # Power, Speed, Duration in frames
    Shake = [4, 4, 200] # shake the screen when fataly damaged
  end
  
end

include Cozziekuns

#==============================================================================
# ** Game_Actor
#==============================================================================

class Game_Actor
  
  attr_accessor :odometer_hp
  attr_accessor :odometer_mp
  attr_accessor :odometer_tp
  attr_accessor :shake
  
  alias coz_ebisohd_gmactr_setup setup
  def setup(actor_id, *args)
    coz_ebisohd_gmactr_setup(actor_id, *args)
    @odometer_hp = 0
    @odometer_mp = 0
    @odometer_tp = 0
    @shake = false
  end
  
  alias coz_ebishod_gmactr_execute_damage execute_damage
  def execute_damage(user, *args)
    if $game_party.in_battle
      on_damage(@result.hp_damage) if @result.hp_damage > 0
      if @odometer_hp < 0
        if (self.mhp - self.hp - @odometer_hp) > self.mhp
          @odometer_hp = (self.mhp - self.hp) * -1
        elsif (self.mhp - self.hp) < (@odometer_hp * -1)
          @odometer_hp = (self.mhp - self.hp) * -1
        end
      end
      @odometer_hp += @result.hp_damage
      @odometer_mp += @result.mp_damage
      user.hp += @result.hp_drain
      user.mp += @result.mp_drain
      if @odometer_hp >= self.hp && @shake == false
        me = Earthboundish::Sound
        me.play
        $game_message.position = Earthboundish::Position
        $game_message.add(sprintf(Earthboundish::Mortal_Damage_Msg, self.name))
      end
    else
      coz_ebishod_gmactr_execute_damage(user, *args)
    end
  end
  
  [:hp, :mp].each { |stat|
    alias_method("coz_ebishod_gmactr_item_effect_recover_#{stat}".to_sym, "item_effect_recover_#{stat}".to_sym)
    define_method("item_effect_recover_#{stat}".to_sym) { |user, item, effect|
      if $game_party.in_battle
        value = (send("m#{stat}".to_sym) * effect.value1 + effect.value2) * rec
        value *= user.pha if item.is_a?(RPG::Item)
        value = value.to_i
        @result.send("#{stat}_damage=".to_sym, @result.send("#{stat}_damage".to_sym) - value)
        @result.success = true
        send("odometer_#{stat}=".to_sym, send("odometer_#{stat}".to_sym) - value)
      else
        send("coz_ebishod_gmactr_item_effect_recover_#{stat}".to_sym, user, item, effect)        
      end
    }
  }

end

#==============================================================================
# ** Game_Enemy
#==============================================================================

class Game_Enemy
  
  def execute_damage(user)
    on_damage(@result.hp_damage) if @result.hp_damage > 0
    self.hp -= @result.hp_damage
    self.mp -= @result.mp_damage
    user.odometer_hp -= @result.hp_drain
    user.odometer_mp -= @result.mp_drain
  end
  
end

#==============================================================================
# ** Window_BattleStatus
#==============================================================================

class Window_BattleStatus
  
  def refresh_hpmp(actor, index)
    rect = item_rect(index)
    if gauge_area_rect(index) == item_rect(index) 
      rect.y += line_height * 2
      rect.height -= line_height * 2
      contents.clear_rect(rect)
    else
      contents.clear_rect(gauge_area_rect(index))
    end
    draw_gauge_area(gauge_area_rect(index), actor)
  end
  
  [:hp, :mp, :tp].each { |stat|
    define_method("draw_actor_#{stat}".to_sym) { |actor, x, y, width|
      change_color(system_color)
      draw_text(x, y, 30, line_height, Vocab.send("#{stat}_a"))
      od_x = x + contents.text_size(Vocab.send("#{stat}_a")).width + 4
      actor_hp = actor.send("#{stat}".to_sym).to_i
      actor_od_hp = actor.send("odometer_#{stat}".to_sym)
      draw_odometer(od_x, y, stat, actor_hp, actor_od_hp)
    }
  }
  
  if Cozziekuns::Earthboundish::Four_Digits
  def draw_odometer(x, y, type, value, od_value)
    bitmap = Cache.system("Odometer_#{type.upcase}")
    places = [1000, 100, 10, 1]
    od_ary = value.to_s.split("").collect { |str| str.to_i }
    (4 - od_ary.size).times { od_ary.unshift(0) }
    od_ary.each_index { |i|
      src_y = (9 - od_ary[i]) * 20
      if (od_ary.join.to_i) % places[i] == 0 and od_value != 0
        src_y += 20 / Earthboundish::Odometer_Roll_Speed * (Graphics.frame_count % Earthboundish::Odometer_Roll_Speed)
      end
      contents.blt(x + i * 24, y + 2, bitmap, Rect.new(0, src_y, 24, 20))
    }
  end
  else
  def draw_odometer(x, y, type, value, od_value)
    bitmap = Cache.system("Odometer_#{type.upcase}")
    places = [100, 10, 1]
    od_ary = value.to_s.split("").collect { |str| str.to_i }
    (3 - od_ary.size).times { od_ary.unshift(0) }
    od_ary.each_index { |i|
      src_y = (9 - od_ary[i]) * 20
      if (od_ary.join.to_i) % places[i] == 0 and od_value != 0
        src_y += 20 / Earthboundish::Odometer_Roll_Speed * (Graphics.frame_count % Earthboundish::Odometer_Roll_Speed)
      end
      contents.blt(x + i * 24, y + 2, bitmap, Rect.new(0, src_y, 24, 20))
    }
  end
  end
  
end

#==============================================================================
# ** Scene_Battle
#==============================================================================

class Scene_Battle
  
  alias coz_ebishod_scbtl_update_basic update_basic
  def update_basic(*args)
    coz_ebishod_scbtl_update_basic(*args)
    update_odometer
  end
  
  def shake_odometer
    pow = Earthboundish::Shake[0]
    spd = Earthboundish::Shake[1]
    dur = Earthboundish::Shake[2]
    $game_troop.screen.start_shake(pow, spd, dur)
  end

  def update_odometer
    $game_party.members.each { |actor|
      if actor.odometer_hp != 0 or actor.odometer_mp != 0
        if actor.odometer_hp != 0 and Graphics.frame_count % Earthboundish::Odometer_Roll_Speed == 0
          damage = actor.odometer_hp > 0 ? 1 : - 1
          actor.hp -= damage
          actor.odometer_hp -= damage
        end
        if actor.odometer_mp != 0 and Graphics.frame_count % Earthboundish::Odometer_Roll_Speed == 0
          damage = actor.odometer_mp > 0 ? 1 : - 1
          actor.mp -= damage
          actor.odometer_mp -= damage
        end
        @status_window.refresh_hpmp(actor, actor.index)
        if actor.hp == 0 or (actor.hp == actor.mhp) and damage != nil
          damage = 0
          actor.odometer_hp = 0
        end
        if actor.mp == 0 or (actor.mp == actor.mmp) and damage != nil
          damage = 0
          actor.odometer_mp = 0
        end
        @status_window.refresh_hpmp(actor, actor.index)
      end
      if (actor.hp < actor.odometer_hp) && actor.shake == false
        actor.shake = true
        shake_odometer
      elsif (actor.hp > actor.odometer_hp) && actor.shake == true
        actor.shake = false
      end
    }
  end
  
end

Here is a thread where I fixed some other issues with the scripts. https://forums.rpgmakerweb.com/inde...lp-with-cozziekuns-earthbound-scripts.138226/
But it still has one issue. If you heal and the numbers have not returned to the full heal amount then they will not go down again. So you can be damaged and do a full heal, until the health number reach maximum, you will not start taking any damage. I'm looking into it.
My bad! And thank you!
Script above updated. Should work.
Now if I can figure out the shake. Done

Test it
Did some testing and works perfect! Thanks!

Original thread: https://forums.rpgmakerweb.com/threads/cozziekunss-earthbound-system-mortal-damage.181962/