Randomized critical messages, help needed

Hello, I'm editing Yanfly Engine Ace - Ace Battle Engine v1.22 script, I want it to be able to display a variety of "CRITICAL" messages, which would be picked at random, instead of having just one.
I've tried many things to get it to work.
Such as overriding the original output for :critical (it didn't work).
Spoiler: failed scripting 1
#am meddling MIGRATING ONTO A SEPARATE SCRIPT IT DIDNT WORK ABORT #class Game_Battler # # def criticalmessagerandomizer # randomcritmsg = [1, 2, 3].sample # if randomcritmsg = 1 # {:critical => "crit msg 1",} # elsif randomcritmsg = 2 # {:critical => "crit msg 2",} # else randomcritmsg = 3 # {:critical => "crit msg 3",} # end # end # #end #done meddling


Then I tried to make the :critical method pick a random position from an array. However, it plainly ignores .sample and .shuffle commands, instead only picking a single position in the array. I've been all evening at it, and it's driving me insane. Help?

Spoiler: failed scripting 2
POPUP_SETTINGS ={ :offset => -24, # Height offset of a popup. :fade => 12, # Fade rate for each popup. :full => 90, # Frames before a popup fades. :hp_dmg => "-%s ", # SprintF for HP damage. :hp_heal => "+%s ", # SprintF for HP healing. :mp_dmg => "-%s SP", # SprintF for MP damage. :mp_heal => "+%s SP", # SprintF for MP healing. :tp_dmg => "-%s TP", # SprintF for MP damage. :tp_heal => "+%s TP", # SprintF for MP healing. :drained => "PARASITIC", # Text display for draining HP/MP. :critical => ["crit msg 1", "crit msg 2", "crit msg 3"].to_a.sample, #.to_a.shuffle.sample, #.shuffle.first, #.sample :missed => "TRY AGAIN...", # Text display for missed attack. :evaded => "HIT DENIED", # Text display for evaded attack. :nulled => "POOR EFFORT", # Text display for nulled attack. :failed => "EFFORTS IN VAIN", # Text display for a failed attack. :add_state => "+%s", # SprintF for added states. :rem_state => "-%s", # SprintF for removed states. :dur_state => "%s", # SprintF for during states. :ele_rates => true, # This will display elemental affinities. :ele_wait => 20, # This is how many frames will wait. :weakpoint => "SUFFERING INFLICTED", # Appears if foe is weak to element. :resistant => "FALLING FLAT", # Appears if foe is resistant to element. :immune => "EFFORT NULLED", # Appears if foe is immune to element. :absorbed => "SPONGED IN", # Appears if foe can absorb the element. :add_buff => "+%s", # Appears when a positive buff is applied. :add_debuff => "-%s", # Appears when a negative buff is applied. } # Do not remove this.

Thanks very much in advance. Here's the full script from yanfly (unmodified). https://github.com/Archeia/YEARepo/blob/master/Ace_Battle_Engine.rb
I'm also using an addon called "Fix Critical", to well, make the message actually display.
This is the addon.


Spoiler: fix critical addon
class Game_Battler def make_damage_value(user, item) game_battler_make_damage_value_abe(user, item) rate = item_element_rate(user, item) make_rate_popup(rate) unless $game_temp.evaluating if @result.critical text = YEA::BATTLE::POPUP_SETTINGS[:critical] rules = "CRITICAL" create_popup(text,rules) end end end
two things.
1. you did an assignment operation not a comparison operation
if randomcritmsg = 1
that should be
if randomcritmsg == 1

2. you don't need to convert an array into an array. just use the .sample
should work.

I'll do some testing if I get a chance shortly unless someone else is able to offer their input.
Oh, I tend to confuse comparisons and assignments hahaha, my bad... I edited it just now and it still wasn't overwriting stuff, unfortunately, I was convinced to ditch overwriting stuff early this evening, but it seems that may be necessary? I'm not even sure if the array stuff would be picked once per game or once per turn (I need crit messages to be randomized each turn). Regardless, here's the expanded bit back when I was trying to overwrite stuff.
Spoiler: attempts to overwrite :critical
POPUP_SETTINGS ={ :offset => -24, # Height offset of a popup. :fade => 12, # Fade rate for each popup. :full => 90, # Frames before a popup fades. :hp_dmg => "-%s ", # SprintF for HP damage. :hp_heal => "+%s ", # SprintF for HP healing. :mp_dmg => "-%s SP", # SprintF for MP damage. :mp_heal => "+%s SP", # SprintF for MP healing. :tp_dmg => "-%s TP", # SprintF for MP damage. :tp_heal => "+%s TP", # SprintF for MP healing. :drained => "PARASITIC", # Text display for draining HP/MP. :critical => "error", #.to_a.shuffle.sample, #.shuffle.first, #.sample :missed => "TRY AGAIN...", # Text display for missed attack. :evaded => "HIT DENIED", # Text display for evaded attack. :nulled => "POOR EFFORT", # Text display for nulled attack. :failed => "EFFORTS IN VAIN", # Text display for a failed attack. :add_state => "+%s", # SprintF for added states. :rem_state => "-%s", # SprintF for removed states. :dur_state => "%s", # SprintF for during states. :ele_rates => true, # This will display elemental affinities. :ele_wait => 20, # This is how many frames will wait. :weakpoint => "SUFFERING INFLICTED", # Appears if foe is weak to element. :resistant => "FALLING FLAT", # Appears if foe is resistant to element. :immune => "EFFORT NULLED", # Appears if foe is immune to element. :absorbed => "SPONGED IN", # Appears if foe can absorb the element. :add_buff => "+%s", # Appears when a positive buff is applied. :add_debuff => "-%s", # Appears when a negative buff is applied. } # Do not remove this. #am meddling MIGRATING ONTO A SEPARATE SCRIPT IT DIDNT WORK ABORT class Game_Battler def criticalmessagerandomizer randomcritmsg = [1, 2, 3].sample if randomcritmsg == 1 {:critical => "crit msg 1",} elsif randomcritmsg == 2 {:critical => "crit msg 2",} else randomcritmsg == 3 {:critical => "crit msg 3",} end end end #done meddling

Yeah, I know .to_a stuff is extra, I guess I'm just trying everything at this point, you can see I've left some other methods w/o .to_a as comments and they did not work either.
Thanks for such a fast reply by the way!!!

Mild update, as I predicted, the .sample on an array works, but only upon initial game launch. I need it to work every turn. How can I refresh it???

Ok so uh, more developments I suppose, I need to update the .sample method which is inside a hash, I've rummaged the web and tried every method on how to do it and it didn't work. My idea is to update the hash each turn or each instance of a critical hit to refresh the .sample method.
I feel like I should make a separate thread at this point, but that seems like bad tone, so, for now, I'll just keep updating this one.

Spoiler: how do i update a hash every turn
#HOW DO I UPDATE THIS EVERY TURN THIS WHOLE EVENING line 1261????? #POPUP_SETTINGS.update(POPUP_SETTINGS) #POPUP_SETTINGS.update({|:critical, ["crit msg 1", "crit msg 2", "crit msg 3"].sample| :critical, ["crit msg 1", "crit msg 2", "crit msg 3"].sample}) #POPUP_SETTINGS.update(POPUP_SETTINGS) { |:critical, ["crit msg 1", "crit msg 2", "crit msg 3"].sample| ["crit msg 1", "crit msg 2", "crit msg 3"].sample } #POPUP_SETTINGS[:critical] = ["crit msg 1", "crit msg 2", "crit msg 3"].sample #POPUP_SETTINGS[:critical] = ["crit msg 1", "crit msg 2", "crit msg 3"].sample

A lot of those attempts to update the POPUP_SETTINGS hash results in the error called "uninitialized constant" even though the line a couple above line 1261 references? What is going on? I've ran into a brickwall.
Careful you've done several posts in a row.
You should read the forum rules.

It appears you've been looking in the wrong place.

I gather the goal is to have the text in the battle log change to random text?

The section you've been working with is simply a flag that tells the script to display the text in the battle log. Nothing should be changed there.

Instead you need to apply a few changes to the battelog.

Ruby:
class Window_BattleLog < Window_Selectable
  #--------------------------------------------------------------------------
  # * Display Critical Hit
  #--------------------------------------------------------------------------
  def display_critical(target, item)
    if target.result.critical
      text = target.actor? ? Vocab::CriticalToActor : enemy_critical_text
      add_text(text)
      wait
    end
  end
  def enemy_critical_text
    pick = rand(3)
    case pick
    when 0
      return "Critical!"
    when 1
      return "Masterful!"
    when 2
      return "Excellent!"
    else
      return "WOW!"
    end
  end
end
Apologies for the numerous posts, it won't happen again. I've reset the script, removing all the stuff that I wrote, then ported the code you posted to both ace engine and, when it didn't work, to kernel RPG maker battle log code, unfortunately the feature didn't work, it just returned the original message which I've stated in the POPUP_SETTINGS customizable part.
Did I do something wrong? I've pasted the code below those. One of the end operators was extra (?) , since it had crashed my game, giving me an error which said that end operator was unexpected. Does "critical fix" I mention in the header post interfere somehow perhaps???
I've also pasted the script to be an independent one below ace battle engine and critical fix, and the result was sadly the same.
1708807825308.png
1708808043720.png
1708808095157.png

Also, if possible, I need it to go both ways, both from actor to the enemy and from the enemy to the actor.
Apologies for the numerous posts, it won't happen again. I've reset the script, removing all the stuff that I wrote, then ported the code you posted to both ace engine and, when it didn't work, to kernel RPG maker battle log code, unfortunately the feature didn't work, it just returned the original message which I've stated in the POPUP_SETTINGS customizable part.
Did I do something wrong? I've pasted the code below those. One of the end operators was extra (?) , since it had crashed my game, giving me an error which said that end operator was unexpected. Does "critical fix" I mention in the header post interfere somehow perhaps???
I've also pasted the script to be an independent one below ace battle engine and critical fix, and the result was sadly the same.
View attachment 296363View attachment 296365View attachment 296366
Also, if possible, I need it to go both ways, both from actor to the enemy and from the enemy to the actor.
You need to tell us what other scripts you have?
The yanfly battle engine script does not create popup for the text.

If you need it for the enemy as well then just add another method and call that method in the text portion
Ruby:
class Window_BattleLog < Window_Selectable
  #--------------------------------------------------------------------------
  # * Display Critical Hit
  #--------------------------------------------------------------------------
  def display_critical(target, item)
    if target.result.critical
      text = target.actor? ? actor_critical_text : enemy_critical_text
      add_text(text)
      wait
    end
  end
  def enemy_critical_text
    # message if an actor gets a critical hit
    pick = rand(3)
    case pick
    when 0
      return "Critical!"
    when 1
      return "Masterful!"
    when 2
      return "Excellent!"
    else
      return "WOW!"
    end
  end
  def actor_critical_text
    # message if an enemy gets a critical hit
    pick = rand(3)
    case pick
    when 0
      return "Critical!"
    when 1
      return "Masterful!"
    when 2
      return "Excellent!"
    else
      return "WOW!"
    end
  end
end

No there was not an extra end.

I have no idea what you have done to have 'error' show up as a popup.

This snippet I put below materials and above yanfly battle engine.
Those are the only scripts in my test project.
I have a script for displaying the critical text in-battle, it was included within the first post, but here it is, I have it directly below the ace engine.
Spoiler: fix critical script
class Game_Battler def make_damage_value(user, item) game_battler_make_damage_value_abe(user, item) rate = item_element_rate(user, item) make_rate_popup(rate) unless $game_temp.evaluating if @result.critical text = YEA::BATTLE::POPUP_SETTINGS[:critical] rules = "CRITICAL" create_popup(text,rules) end end end
I have "error" set as the option for the displayed critical message, for testing.
Spoiler: POPUP_SETTINGS
# This hash adjusts the popup settings that will govern how popups appear. # Adjust them accordingly. POPUP_SETTINGS ={ :offset => -24, # Height offset of a popup. :fade => 12, # Fade rate for each popup. :full => 90, # Frames before a popup fades. :hp_dmg => "-%s ", # SprintF for HP damage. :hp_heal => "+%s ", # SprintF for HP healing. :mp_dmg => "-%s SP", # SprintF for MP damage. :mp_heal => "+%s SP", # SprintF for MP healing. :tp_dmg => "-%s TP", # SprintF for MP damage. :tp_heal => "+%s TP", # SprintF for MP healing. :drained => "PARASITIC", # Text display for draining HP/MP. :critical => "error", # Text display for critical hit. :missed => "TRY AGAIN...", # Text display for missed attack. :evaded => "EFFORT DENIED", # Text display for evaded attack. :nulled => "POOR EFFORT", # Text display for nulled attack. :failed => "EFFORTS IN VAIN", # Text display for a failed attack. :add_state => "+%s", # SprintF for added states. :rem_state => "-%s", # SprintF for removed states. :dur_state => "%s", # SprintF for during states. :ele_rates => true, # This will display elemental affinities. :ele_wait => 20, # This is how many frames will wait. :weakpoint => "SUFFERING INFLICTED", # Appears if foe is weak to element. :resistant => "FALLING FLAT", # Appears if foe is resistant to element. :immune => "EFFORT NULLED", # Appears if foe is immune to element. :absorbed => "SPONGED IN", # Appears if foe can absorb the element. :add_buff => "+%s", # Appears when a positive buff is applied. :add_debuff => "-%s", # Appears when a negative buff is applied. } # Do not remove this.
I have "error" set as the option for the displayed critical message, for testing.
Again that's just a flag condition.

So I think all you needed to do was adjust your popup script you did
Ruby:
class Game_Battler
 
  def make_damage_value(user, item)
    game_battler_make_damage_value_abe(user, item)
    rate = item_element_rate(user, item)
    make_rate_popup(rate) unless $game_temp.evaluating
    if @result.critical
      text = enemy_critical_text #YEA::BATTLE::POPUP_SETTINGS[:critical]
      rules = "CRITICAL"
      create_popup(text,rules)
    end
  end
  def enemy_critical_text
    # message if an actor gets a critical hit
    pick = rand(3)
    case pick
    when 0
      return "Critical!"
    when 1
      return "Masterful!"
    when 2
      return "Excellent!"
    else
      return "WOW!"
    end
  end

end
Wohooo! It worksss! The code looks much more simple and smooth than the insane junk I was making, I've only began to tackle rubyscript all on my own few months ago, and this is perhaps one of the more ambitious things I was trying, so, I guess I need to curb my ambitions a little, a thousand thank yous to you, this is gonna rock...

Original thread: https://forums.rpgmakerweb.com/threads/randomized-critical-messages-help-needed.166126/