RCXDan

Champion of Brightmoon Tor
Veteran
Joined
Jan 4, 2019
Messages
234
Reaction score
489
First Language
English
Primarily Uses
RMVXA
So a feature I quite enjoy in some games is when the enemies visibly react to getting hit by the element they're weak to.

I'm looking for a simple script that has it so an enemy shakes and flashes red if hit by an element weakness (or blue if hit by something they resist).

I don't know how feasible it is, but I'd also like it so I can play an animation on hit.
 

RCXDan

Champion of Brightmoon Tor
Veteran
Joined
Jan 4, 2019
Messages
234
Reaction score
489
First Language
English
Primarily Uses
RMVXA
(Singular bump just to revive the thread because I'm still interested in the function.)
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
3,707
Reaction score
2,808
First Language
English
Primarily Uses
RMMZ
Ruby:
class Game_ActionResult
  attr_accessor :weakness_hit
  attr_accessor :resist_hit
 
  alias tlb_gar_clear_hit_flags clear_hit_flags
  def clear_hit_flags
    tlb_gar_clear_hit_flags
    @weakness_hit = false
    @resist_hit = false
  end
end

class Game_Battler < Game_BattlerBase
  def item_apply(user, item)
    @result.clear
    @result.used = item_test(user, item)
    @result.missed = (@result.used && rand >= item_hit(user, item))
    @result.evaded = (!@result.missed && rand < item_eva(user, item))
    if @result.hit?
      unless item.damage.none?
        @result.critical = (rand < item_cri(user, item))
        @result.weakness_hit = item_element_rate(user, item) > 1
        @result.resist_hit = item_element_rate(user, item) < 1
        make_damage_value(user, item)
        execute_damage(user)
      end
      item.effects.each {|effect| item_effect_apply(user, item, effect) }
      item_user_effect(user, item)
    end
  end
end

class Game_Enemy < Game_Battler
  def perform_weakness_effect
    @sprite_effect_type = :weak
    Sound.play_enemy_damage
  end
 
  def perform_resistance_effect
    @sprite_effect_type = :resist
    Sound.play_enemy_damage
  end
end

class Game_Actor < Game_Battler
  def perform_weakness_effect
  end
 
  def perform_resistance_effect
  end
end

class Sprite_Battler < Sprite_Base
  def start_effect(effect_type)
    @effect_type = effect_type
    case @effect_type
    when :appear
      @effect_duration = 16
      @battler_visible = true
    when :disappear
      @effect_duration = 32
      @battler_visible = false
    when :whiten
      @effect_duration = 16
      @battler_visible = true
    when :blink
      @effect_duration = 20
      @battler_visible = true
    when :weak
      @effect_duration = 40
      @battler_visible = true
    when :resist
      @effect_duration = 40
      @battler_visible = true
    when :collapse
      @effect_duration = 48
      @battler_visible = false
    when :boss_collapse
      @effect_duration = bitmap.height
      @battler_visible = false
    when :instant_collapse
      @effect_duration = 16
      @battler_visible = false
    end
    revert_to_normal
  end
 
  def update_effect
    if @effect_duration > 0
      @effect_duration -= 1
      case @effect_type
      when :whiten
        update_whiten
      when :blink
        update_blink
      when :weak
        update_weak
      when :resist
        update_resist
      when :appear
        update_appear
      when :disappear
        update_disappear
      when :collapse
        update_collapse
      when :boss_collapse
        update_boss_collapse
      when :instant_collapse
        update_instant_collapse
      end
      @effect_type = nil if @effect_duration == 0
    end
  end
 
  def update_weak
    self.color.set(255, 0, 0, 0)
    self.color.alpha = 128 - (16 - @effect_duration) * 10
    self.ox = bitmap.width / 2 + @effect_duration % 2 * 6 - 2
  end
 
  def update_resist
    self.color.set(0, 0, 255, 0)
    self.color.alpha = 128 - (16 - @effect_duration) * 10
    self.ox = bitmap.width / 2 + @effect_duration % 2 * 4 - 2
  end
end

class Window_BattleLog < Window_Selectable
  def display_hp_damage(target, item)
    return if target.result.hp_damage == 0 && item && !item.damage.to_hp?
    if target.result.weakness_hit
      target.perform_weakness_effect
    elsif target.result.resist_hit
      target.perform_resistance_effect
    elsif target.result.hp_damage > 0 && target.result.hp_drain == 0
      target.perform_damage_effect
    end
    Sound.play_recovery if target.result.hp_damage < 0
    add_text(target.result.hp_damage_text)
    wait
  end
end
 

RCXDan

Champion of Brightmoon Tor
Veteran
Joined
Jan 4, 2019
Messages
234
Reaction score
489
First Language
English
Primarily Uses
RMVXA
Thanks so much for responding, @Trihan! Unfortunately I caught a quite... embarassing bug:

f3BPzWo.png


It seems like the script doesn't play nice with Ace Battle Engine's core script, since the numbers and pop-ups refused to go away when the turn ended. Aside from that, the script you made is perfectly usable. :LZSexcite:
 

RCXDan

Champion of Brightmoon Tor
Veteran
Joined
Jan 4, 2019
Messages
234
Reaction score
489
First Language
English
Primarily Uses
RMVXA
The script by Trihan needs to be above ace battle engine.
I did that, but unfortunately the script itself seems to not work when it's above Ace Battle Engine. :(

Oh well, it was worth a shot. :)
 
Last edited:

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
3,707
Reaction score
2,808
First Language
English
Primarily Uses
RMMZ
I can probably work out a compatibility fix, but frankly it's gonna be low on my list of priorities for today because boy howdy do I have a lot of items on my docket. XD
 

Roninator2

Gamer
Veteran
Joined
May 22, 2016
Messages
3,192
Reaction score
722
First Language
English
Primarily Uses
RMVXA
@RCXDan @Trihan
How about just aliasing the update effect method. Seems to work in my tests.
Ruby:
class Game_ActionResult
  attr_accessor :weakness_hit
  attr_accessor :resist_hit
 
  alias tlb_gar_clear_hit_flags clear_hit_flags
  def clear_hit_flags
    tlb_gar_clear_hit_flags
    @weakness_hit = false
    @resist_hit = false
  end
end

class Game_Battler < Game_BattlerBase
  def item_apply(user, item)
    @result.clear
    @result.used = item_test(user, item)
    @result.missed = (@result.used && rand >= item_hit(user, item))
    @result.evaded = (!@result.missed && rand < item_eva(user, item))
    if @result.hit?
      unless item.damage.none?
        @result.critical = (rand < item_cri(user, item))
        @result.weakness_hit = item_element_rate(user, item) > 1
        @result.resist_hit = item_element_rate(user, item) < 1
        make_damage_value(user, item)
        execute_damage(user)
      end
      item.effects.each {|effect| item_effect_apply(user, item, effect) }
      item_user_effect(user, item)
    end
  end
end

class Game_Enemy < Game_Battler
  def perform_weakness_effect
    @sprite_effect_type = :weak
    Sound.play_enemy_damage
  end
 
  def perform_resistance_effect
    @sprite_effect_type = :resist
    Sound.play_enemy_damage
  end
end

class Game_Actor < Game_Battler
  def perform_weakness_effect
  end
 
  def perform_resistance_effect
  end
end

class Sprite_Battler < Sprite_Base
  def start_effect(effect_type)
    @effect_type = effect_type
    case @effect_type
    when :appear
      @effect_duration = 16
      @battler_visible = true
    when :disappear
      @effect_duration = 32
      @battler_visible = false
    when :whiten
      @effect_duration = 16
      @battler_visible = true
    when :blink
      @effect_duration = 20
      @battler_visible = true
    when :weak
      @effect_duration = 40
      @battler_visible = true
    when :resist
      @effect_duration = 40
      @battler_visible = true
    when :collapse
      @effect_duration = 48
      @battler_visible = false
    when :boss_collapse
      @effect_duration = bitmap.height
      @battler_visible = false
    when :instant_collapse
      @effect_duration = 16
      @battler_visible = false
    end
    revert_to_normal
  end
 
  alias sprite_battler_update_effect_trihan update_effect
  def update_effect
    sprite_battler_update_effect_trihan
    case @effect_type
    when :weak
      update_weak
    when :resist
      update_resist
    end
  end
 
  def update_weak
    self.color.set(255, 0, 0, 0)
    self.color.alpha = 128 - (16 - @effect_duration) * 10
    self.ox = bitmap.width / 2 + @effect_duration % 2 * 6 - 2
  end
 
  def update_resist
    self.color.set(0, 0, 255, 0)
    self.color.alpha = 128 - (16 - @effect_duration) * 10
    self.ox = bitmap.width / 2 + @effect_duration % 2 * 4 - 2
  end
end

class Window_BattleLog < Window_Selectable
  def display_hp_damage(target, item)
    return if target.result.hp_damage == 0 && item && !item.damage.to_hp?
    if target.result.weakness_hit
      target.perform_weakness_effect
    elsif target.result.resist_hit
      target.perform_resistance_effect
    elsif target.result.hp_damage > 0 && target.result.hp_drain == 0
      target.perform_damage_effect
    end
    Sound.play_recovery if target.result.hp_damage < 0
    add_text(target.result.hp_damage_text)
    wait
  end
end
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
3,707
Reaction score
2,808
First Language
English
Primarily Uses
RMMZ
Yeah, that works. I didn't bother with aliases originally since it was a quick snippet.
 

RCXDan

Champion of Brightmoon Tor
Veteran
Joined
Jan 4, 2019
Messages
234
Reaction score
489
First Language
English
Primarily Uses
RMVXA
@Trihan @Roninator2
Both of you, thank you so much! It works now! :kaojoy:

Edit: Uh-oh. It doesn't seem to play sound effects when you yourself get hit with a weakness or resisted attack... or show the text that an attack missed.
 
Last edited:

Roninator2

Gamer
Veteran
Joined
May 22, 2016
Messages
3,192
Reaction score
722
First Language
English
Primarily Uses
RMVXA
show the text that an attack missed.
It showed the miss for me in my test.
I added the sound play for the effects. and added a return value for a bug if the actor sprite is not a bitmap.
Ruby:
class Game_ActionResult
  attr_accessor :weakness_hit
  attr_accessor :resist_hit
 
  alias tlb_gar_clear_hit_flags clear_hit_flags
  def clear_hit_flags
    tlb_gar_clear_hit_flags
    @weakness_hit = false
    @resist_hit = false
  end
end

class Game_Battler < Game_BattlerBase
  def item_apply(user, item)
    @result.clear
    @result.used = item_test(user, item)
    @result.missed = (@result.used && rand >= item_hit(user, item))
    @result.evaded = (!@result.missed && rand < item_eva(user, item))
    if @result.hit?
      unless item.damage.none?
        @result.critical = (rand < item_cri(user, item))
        @result.weakness_hit = item_element_rate(user, item) > 1
        @result.resist_hit = item_element_rate(user, item) < 1
        make_damage_value(user, item)
        execute_damage(user)
      end
      item.effects.each {|effect| item_effect_apply(user, item, effect) }
      item_user_effect(user, item)
    end
  end
end

class Game_Enemy < Game_Battler
  def perform_weakness_effect
    @sprite_effect_type = :weak
    Sound.play_enemy_damage
  end
 
  def perform_resistance_effect
    @sprite_effect_type = :resist
    Sound.play_enemy_damage
  end
end

class Game_Actor < Game_Battler
  def perform_weakness_effect
    @sprite_effect_type = :weak
    Sound.play_actor_damage
  end
 
  def perform_resistance_effect
    @sprite_effect_type = :resist
    Sound.play_actor_damage
  end
end

class Sprite_Battler < Sprite_Base
  def start_effect(effect_type)
    @effect_type = effect_type
    case @effect_type
    when :appear
      @effect_duration = 16
      @battler_visible = true
    when :disappear
      @effect_duration = 32
      @battler_visible = false
    when :whiten
      @effect_duration = 16
      @battler_visible = true
    when :blink
      @effect_duration = 20
      @battler_visible = true
    when :weak
      @effect_duration = 40
      @battler_visible = true
    when :resist
      @effect_duration = 40
      @battler_visible = true
    when :collapse
      @effect_duration = 48
      @battler_visible = false
    when :boss_collapse
      @effect_duration = bitmap.height
      @battler_visible = false
    when :instant_collapse
      @effect_duration = 16
      @battler_visible = false
    end
    revert_to_normal
  end
 
  alias sprite_battler_update_effect_trihan update_effect
  def update_effect
    sprite_battler_update_effect_trihan
    case @effect_type
    when :weak
      update_weak
    when :resist
      update_resist
    end
  end
 
  def update_weak
    return if bitmap.nil?
    self.color.set(255, 0, 0, 0)
    self.color.alpha = 128 - (16 - @effect_duration) * 10
    self.ox = bitmap.width / 2 + @effect_duration % 2 * 6 - 2
  end
 
  def update_resist
    return if bitmap.nil?
    self.color.set(0, 0, 255, 0)
    self.color.alpha = 128 - (16 - @effect_duration) * 10
    self.ox = bitmap.width / 2 + @effect_duration % 2 * 4 - 2
  end
end

class Window_BattleLog < Window_Selectable
  def display_hp_damage(target, item)
    return if target.result.hp_damage == 0 && item && !item.damage.to_hp?
    if target.result.weakness_hit
      target.perform_weakness_effect
    elsif target.result.resist_hit
      target.perform_resistance_effect
    elsif target.result.hp_damage > 0 && target.result.hp_drain == 0
      target.perform_damage_effect
    end
    Sound.play_recovery if target.result.hp_damage < 0
    add_text(target.result.hp_damage_text)
    wait
  end
end
 

RCXDan

Champion of Brightmoon Tor
Veteran
Joined
Jan 4, 2019
Messages
234
Reaction score
489
First Language
English
Primarily Uses
RMVXA
It showed the miss for me in my test.
I added the sound play for the effects. and added a return value for a bug if the actor sprite is not a bitmap.
Ruby:
class Game_ActionResult
  attr_accessor :weakness_hit
  attr_accessor :resist_hit
 
  alias tlb_gar_clear_hit_flags clear_hit_flags
  def clear_hit_flags
    tlb_gar_clear_hit_flags
    @weakness_hit = false
    @resist_hit = false
  end
end

class Game_Battler < Game_BattlerBase
  def item_apply(user, item)
    @result.clear
    @result.used = item_test(user, item)
    @result.missed = (@result.used && rand >= item_hit(user, item))
    @result.evaded = (!@result.missed && rand < item_eva(user, item))
    if @result.hit?
      unless item.damage.none?
        @result.critical = (rand < item_cri(user, item))
        @result.weakness_hit = item_element_rate(user, item) > 1
        @result.resist_hit = item_element_rate(user, item) < 1
        make_damage_value(user, item)
        execute_damage(user)
      end
      item.effects.each {|effect| item_effect_apply(user, item, effect) }
      item_user_effect(user, item)
    end
  end
end

class Game_Enemy < Game_Battler
  def perform_weakness_effect
    @sprite_effect_type = :weak
    Sound.play_enemy_damage
  end
 
  def perform_resistance_effect
    @sprite_effect_type = :resist
    Sound.play_enemy_damage
  end
end

class Game_Actor < Game_Battler
  def perform_weakness_effect
    @sprite_effect_type = :weak
    Sound.play_actor_damage
  end
 
  def perform_resistance_effect
    @sprite_effect_type = :resist
    Sound.play_actor_damage
  end
end

class Sprite_Battler < Sprite_Base
  def start_effect(effect_type)
    @effect_type = effect_type
    case @effect_type
    when :appear
      @effect_duration = 16
      @battler_visible = true
    when :disappear
      @effect_duration = 32
      @battler_visible = false
    when :whiten
      @effect_duration = 16
      @battler_visible = true
    when :blink
      @effect_duration = 20
      @battler_visible = true
    when :weak
      @effect_duration = 40
      @battler_visible = true
    when :resist
      @effect_duration = 40
      @battler_visible = true
    when :collapse
      @effect_duration = 48
      @battler_visible = false
    when :boss_collapse
      @effect_duration = bitmap.height
      @battler_visible = false
    when :instant_collapse
      @effect_duration = 16
      @battler_visible = false
    end
    revert_to_normal
  end
 
  alias sprite_battler_update_effect_trihan update_effect
  def update_effect
    sprite_battler_update_effect_trihan
    case @effect_type
    when :weak
      update_weak
    when :resist
      update_resist
    end
  end
 
  def update_weak
    return if bitmap.nil?
    self.color.set(255, 0, 0, 0)
    self.color.alpha = 128 - (16 - @effect_duration) * 10
    self.ox = bitmap.width / 2 + @effect_duration % 2 * 6 - 2
  end
 
  def update_resist
    return if bitmap.nil?
    self.color.set(0, 0, 255, 0)
    self.color.alpha = 128 - (16 - @effect_duration) * 10
    self.ox = bitmap.width / 2 + @effect_duration % 2 * 4 - 2
  end
end

class Window_BattleLog < Window_Selectable
  def display_hp_damage(target, item)
    return if target.result.hp_damage == 0 && item && !item.damage.to_hp?
    if target.result.weakness_hit
      target.perform_weakness_effect
    elsif target.result.resist_hit
      target.perform_resistance_effect
    elsif target.result.hp_damage > 0 && target.result.hp_drain == 0
      target.perform_damage_effect
    end
    Sound.play_recovery if target.result.hp_damage < 0
    add_text(target.result.hp_damage_text)
    wait
  end
end
I actually still had the "miss" pop-up not showing up, and that was bothering me a lot.

So I instead chose to go crazy: I chopped up Yanfly Ace Engine and @Trihan's script into two halves each, placed them like this:

* Yanfly Ace Battle Engine (1/2)
* Trihan's Script (1/2)
* Yanfly Ace Battle Engine (2/2)
* Trihan's Script (2/2)

... A couple rounds of testing and a full replay of one of my games with it on later, now I can say it works for sure. Yeah, it's an extremely hacky workaround but now I have what I want. :)
 
Last edited:

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
3,707
Reaction score
2,808
First Language
English
Primarily Uses
RMMZ
Hey, it's not hacky if it does what you need it to. :p
 

Latest Threads

Latest Posts

Latest Profile Posts

Chili: Evolved to taste spicy so no animal would eat them.

Humans: "Jokes on you ..."
I guess it becomes purely academic in less than four days but before then can anyone explain to me why the %^&*( animations in the MZ database don't have a 'Hue' slider??
Who here knows of the hidden laws of this multiverse? Such as the law of attraction
Exploding Fruits and Rasaks Pixelfarm Assets | RPG Maker News #108

So ghosts can go through walls and stuff, and depending their type (according to fantasy media) they can or can't interact with objects to a certain degree...

So why they don't always fall through floors? Do they always float and sometimes simulate walking? If things go through them how can they hear/see? And why sometimes they have clothing? Do clothes die as well?

Forum statistics

Threads
113,704
Messages
1,076,796
Members
147,728
Latest member
Alteria
Top