[Solved] Need help making a Transmute/Morph skill that turns enemies into Gold when killed with it.

I'm trying to make a Skill that deals little damage, but if that Skill kills the enemy, it instantly gives you a random amount of Gold between 100-200. The logic being that you're alchemically transforming the enemy into gold coins.

When the skill successfully hits, I'd like a message box or window to appear to show how much Gold the Player received.

Can this be done solely with events? Or should I look for a script?
theoretically it could be done by a combination of damage formula coding and events.
however that would have several problems due to the timing and coordination between all parts.
for a fluent sequence of what you want you'll likely have to use scripts.
theoretically it could be done by a combination of damage formula coding and events.
however that would have several problems due to the timing and coordination between all parts.
for a fluent sequence of what you want you'll likely have to use scripts.
After some searching I think I could use Yanfly's Death Common Event script, and have a common event trigger on every enemy.

The event would have to check the Element of the last source of damage dealt to that enemy somehow, and if that Element was a special "transmute" element, it would give them the gold and show the message.

Is it possible to check the Element of an attack that already happened?
After some searching I think I could use Yanfly's Death Common Event script, and have a common event trigger on every enemy.

The event would have to check the Element of the last source of damage dealt to that enemy somehow, and if that Element was a special "transmute" element, it would give them the gold and show the message.

Is it possible to check the Element of an attack that already happened?
I know that there's a method to check the last Skill type, but I don't remember (but I think it should) one to check the skill ID.
Later when I'm home I'm gonna check what can be do.


EDIT: Oh, I just think on a more easier method.
Use the common event you want. Make a Switch called "enemy to gold" or however you want to call it. Make that the skill turn the switch on. Then in the commont event make a conditional branch that when the switch is on, you gain the gold. Then after the condition that turn the switch to off regarding of the condition was fulfilled or not. This will make it to only generate gold when you use that skill.
I know that there's a method to check the last Skill type, but I don't remember (but I think it should) one to check the skill ID.
Later when I'm home I'm gonna check what can be do.


EDIT: Oh, I just think on a more easier method.
Use the common event you want. Make a Switch called "enemy to gold" or however you want to call it. Make that the skill turn the switch on. Then in the commont event make a conditional branch that when the switch is on, you gain the gold. Then after the condition that turn the switch to off regarding of the condition was fulfilled or not. This will make it to only generate gold when you use that skill.
Sorry for responding so late.
Unless I'm misunderstanding your method, I see a problem. The intended way I am aiming for is that the transmute spell has to deal the killing blow. As is, your method wouldn't account for this. It would turn on the switch and leave it there until it dies. Therefore any lethal attack would trigger the gold-drop effect.
Sorry for responding so late.
Unless I'm misunderstanding your method, I see a problem. The intended way I am aiming for is that the transmute spell has to deal the killing blow. As is, your method wouldn't account for this. It would turn on the switch and leave it there until it dies. Therefore any lethal attack would trigger the gold-drop effect.
My method should would perfectly unless I'm missing something:

1) You have the skill that when you kill an enemy it turn it into gold, right?
2) Make a switch and call it something like "Turn into gold" that by default is gonna be off.
3) In the traits of the skill that turn into gold, make that it turn on that switch.
4) In the death common event make a conditional branch that when the switch is ON, you will gain the amount of gold desired. THEN make it that the switch is turned off, so the next time that common event is called, it won't give you gold unless you used that skill again.
a script?
Ruby:
# ╔═════════════════════════════════════╦════════════════════╗
# ║ Title: Transmute enemy into Gold    ║  Version: 1.01     ║
# ║ Author: Roninator2                  ║                    ║
# ╠═════════════════════════════════════╬════════════════════╣
# ║ Function:                           ║   Date Created     ║
# ║     Transmute enemy into gold       ╠════════════════════╣
# ║     for specific skill on death     ║    05 Sep 2022     ║
# ╚═════════════════════════════════════╩════════════════════╝
# ╔══════════════════════════════════════════════════════════╗
# ║ Instructions:                                            ║
# ║                                                          ║
# ║   Specify which method to use for gaining gold           ║
# ║   0 = enemy maximum hp                                   ║
# ║   1 = random number from amount specified                ║
# ║   2 = exact amount specified                             ║
# ║                                                          ║
# ║   Specify the skill id that will be the transmute skill  ║
# ║                                                          ║
# ║   Specify the variable to use (required)                 ║
# ║                                                          ║
# ║   Specify the message to display                         ║
# ║    "Turned Slime A into 100 Gold"                        ║
# ║                                                          ║
# ║   This script will cuyrrently only work for one skill    ║
# ╚══════════════════════════════════════════════════════════╝
# ╔══════════════════════════════════════════════════════════╗
# ║ Updates:                                                 ║
# ║   2022-Sep-05 - Initial publish                          ║
# ║   2022-Sep-06 - Added support for Yanfly Battle Engine   ║
# ╚══════════════════════════════════════════════════════════╝
# ╔══════════════════════════════════════════════════════════╗
# ║ Terms of use:                                            ║
# ║ Free for all uses in RPG Maker VX Ace - except nudity    ║
# ╚══════════════════════════════════════════════════════════╝

module R2_Gain_Gold_Enemy_Bonus
  Method = 0 # 0 = enemy.hp, 1 = random amount, 2 = specific amount
  Amount = 1000 # for 1 & 2. 1 = random 1000, 2 = exactly 1000
  Skill = 128 # transmute skill
  Variable = 9
  Message = "Turned %s into " # %s = enemy name
end

# ╔══════════════════════════════════════════════════════════╗
# ║      End Of Editable Region                              ║
# ╚══════════════════════════════════════════════════════════╝

class Game_Battler < Game_BattlerBase
  attr_accessor :gold_skill
  alias r2_enemy_gold_transmute die
  def die
    r2_enemy_gold_transmute
    return if @actions.empty?
    if self.is_a?(Game_Enemy)
      if $game_variables[R2_Gain_Gold_Enemy_Bonus::Variable] == R2_Gain_Gold_Enemy_Bonus::Skill
        add_gold
      end
    end
    $game_variables[R2_Gain_Gold_Enemy_Bonus::Variable] = 0
  end
  def current_action
    act = @actions[0]
    return if act.nil?
    return if $imported["YEA-BattleEngine"] == true && act.item.nil?
    $game_variables[R2_Gain_Gold_Enemy_Bonus::Variable] = act.item.id if self.is_a?(Game_Actor) && @actions.any?
    return act
  end
  def add_gold
    gold = 0
    case R2_Gain_Gold_Enemy_Bonus::Method
    when 0
      gold = self.mhp
    when 1
      gold = rand(R2_Gain_Gold_Enemy_Bonus::Amount + 1)
    when 2
      gold = R2_Gain_Gold_Enemy_Bonus::Amount
    end
    $game_party.gain_gold(gold)
    text = sprintf(R2_Gain_Gold_Enemy_Bonus::Message,self.name) + gold.to_s + " \\G!"
    $game_message.add(text)
  end
end
My method should would perfectly unless I'm missing something:

1) You have the skill that when you kill an enemy it turn it into gold, right?
2) Make a switch and call it something like "Turn into gold" that by default is gonna be off.
3) In the traits of the skill that turn into gold, make that it turn on that switch.
4) In the death common event make a conditional branch that when the switch is ON, you will gain the amount of gold desired. THEN make it that the switch is turned off, so the next time that common event is called, it won't give you gold unless you used that skill again.
Oh. For some reason I forgot about using the Death Common Event script. Okay, that makes a lot more sense.
Edit: Sorry, I only now just realized the source of confusion. The idea is that the spell itself has to kill the enemy for it to work. It's not intended to "mark" the enemy to drop more gold. Like, it shouldn't work if the enemy is killed by something like a basic attack following the spell.

Ruby:
# ╔═════════════════════════════════════╦════════════════════╗
# ║ Title: Transmute enemy into Gold    ║  Version: 1.00     ║
# ║ Author: Roninator2                  ║                    ║
# ╠═════════════════════════════════════╬════════════════════╣
# ║ Function:                           ║   Date Created     ║
# ║     Transmute enemy into gold       ╠════════════════════╣
# ║     for specific skill on death     ║    05 Sep 2022     ║
# ╚═════════════════════════════════════╩════════════════════╝
# ╔══════════════════════════════════════════════════════════╗
# ║ Instructions:                                            ║
# ║                                                          ║
# ║   Specify which method to use for gaining gold           ║
# ║   0 = enemy maximum hp                                   ║
# ║   1 = random number from amount specified                ║
# ║   2 = exact amount specified                             ║
# ║                                                          ║
# ║   Specify the skill id that will be the transmute skill  ║
# ║                                                          ║
# ║   Specify the variable to use (required)                 ║
# ║                                                          ║
# ║   Specify the message to display                         ║
# ║    "Turned Slime A into 100 Gold"                        ║
# ║                                                          ║
# ║   This script will cuyrrently only work for one skill    ║
# ╚══════════════════════════════════════════════════════════╝
# ╔══════════════════════════════════════════════════════════╗
# ║ Updates:                                                 ║
# ║   2022-Sep-05 - Initial publish                          ║
# ║                                                          ║
# ╚══════════════════════════════════════════════════════════╝
# ╔══════════════════════════════════════════════════════════╗
# ║ Terms of use:                                            ║
# ║ Free for all uses in RPG Maker VX Ace - except nudity    ║
# ╚══════════════════════════════════════════════════════════╝

module R2_Gain_Gold_Enemy_Bonus
  Method = 0 # 0 = enemy.hp, 1 = random amount, 2 = specific amount
  Amount = 1000 # for 1 & 2. 1 = random 1000, 2 = exactly 1000
  Skill = 128 # transmute skill
  Variable = 9
  Message = "Turned %s into " # %s = enemy name
end

# ╔══════════════════════════════════════════════════════════╗
# ║      End Of Editable Region                              ║
# ╚══════════════════════════════════════════════════════════╝

class Game_Battler < Game_BattlerBase
  attr_accessor :gold_skill
  alias r2_enemy_gold_transmute die
  def die
    r2_enemy_gold_transmute
    return if @actions.empty?
    if self.is_a?(Game_Enemy)
      if $game_variables[R2_Gain_Gold_Enemy_Bonus::Variable] == R2_Gain_Gold_Enemy_Bonus::Skill
        add_gold
      end
    end
    $game_variables[R2_Gain_Gold_Enemy_Bonus::Variable] = 0
  end
  def current_action
    act = @actions[0]
    return if act.nil?
    $game_variables[R2_Gain_Gold_Enemy_Bonus::Variable] = @actions[0].item.id if self.is_a?(Game_Actor) && [email protected]?
    return act
  end
  def add_gold
    gold = 0
    case R2_Gain_Gold_Enemy_Bonus::Method
    when 0
      gold = self.mhp
    when 1
      gold = rand(R2_Gain_Gold_Enemy_Bonus::Amount)
    when 2
      gold = R2_Gain_Gold_Enemy_Bonus::Amount
    end
    $game_party.gain_gold(gold)
    text = sprintf(R2_Gain_Gold_Enemy_Bonus::Message,self.name) + gold.to_s + " \\G!"
    $game_message.add(text)
  end
end
Wow, thank you so much. I tried it out, but I'm sorry to say, I ran into an issue:
tm.png

Edit2: It seems to have a problem with 'item.id'. I'm not experienced enough in Ruby to tell for certain, but after testing the script out in a new project, I believe it is conflicting with Yanfly's Ace Battle Engine. After a ctrl+f search through my scripts for 'item.id', I found it within the battle engine script. I added the same script to the new project, and it recreated the error. Not entirely sure what to do to fix it, though.
The idea is that the spell itself has to kill the enemy for it to work. It's not intended to "mark" the enemy to drop more gold. Like, it shouldn't work if the enemy is killed by something like a basic attack following the spell.

I think that maybe you still gotten my point of the way to achiev it. I made it in a blank project and it works just fine:

1662461067134.png

You must create the skill you want, and in the damage formula give it the property to turn the switch corresponding to the convertion to gold to on.

1662461112455.png

And then you create the corresponding common event for each enemy with the conditional branch of the switch that turn into gold.

1662461405295.png


I even added a text box to be sure that I'm gaining that amount of gold. You can kill any enemy and you won't gain gold unless you use that skill.

But the annoying part is that you must create a common event for every different enemy. So if Roni script work better I recommend you to use it. Just wanted to point out that my method would be valid too.
a problem with 'item.id'.
Code above updated
I think that maybe you still gotten my point of the way to achiev it. I made it in a blank project and it works just fine:

View attachment 239819
You must create the skill you want, and in the damage formula give it the property to turn the switch corresponding to the convertion to gold to on.

View attachment 239820
And then you create the corresponding common event for each enemy with the conditional branch of the switch that turn into gold.

View attachment 239821

I even added a text box to be sure that I'm gaining that amount of gold. You can kill any enemy and you won't gain gold unless you use that skill.

But the annoying part is that you must create a common event for every different enemy. So if Roni script work better I recommend you to use it. Just wanted to point out that my method would be valid too.
Yeah, but in that case what happens when you use the transmute spell, and it doesn't kill the enemy? The Switch is only turned off when the common event triggers.
Every other skill would also have to have to handle the Switch and toggle it off so that it doesn't trigger the transmute event as well.
Yeah, but in that case what happens when you use the transmute spell, and it doesn't kill the enemy? The Switch is only turned off when the common event triggers.
Every other skill would also have to have to handle the Switch and toggle it off so that it doesn't trigger the transmute event as well.
Oh, I see your point. My bad, in that case, you should do a common event that turn off that switch. Cool thing is that you only need 1 common event for that. In the traits of that skill add that it call for a common event, and in that common event all you have to put is the switch to be turned off. But in that case I'm not sure if it will nullified the other common event. I'm not home to try it. Anyway, if roni already fixed it script, this is pointless I guess.
Code above updated
So, I have run into a new issue that doesn't produce an error. In battle, you can't seem to use any action at all. I'm certain it's a conflict with an edited version of Fomar0153's ATB script. Here's the script, but I'm at a bit of a loss.

Sorry to keep adding on stuff lol. If this is too much right now, that's totally understandable.

Ruby:
=begin
YanFly Compatible Customisable ATB/Stamina Based Battle System Script
by Fomar0153
Edited by Deathsia
Further Edits by AnarchCassius
Version 1.5
----------------------
Notes
----------------------
Requires Yanfly Engine Ace - Ace Battle Engine
Customises the battle system to be similar to
ATB or Stamina based battle systems.
----------------------
Instructions
----------------------
Edit variables in CBS to suit your needs.
The guard status should be set to 2~2 turns.
----------------------
Change Log
----------------------
1.0 -> 1.1 Added CTB related options
           Added the ability to pass a turn
           Added options for turn functionality to be based on time
           or number of actions
           Added the ability to change the bar colours based on states
1.1 -> 1.2 Fixed a bug when escaping using CTB mode
1.2 -> 1.4 Players should no longer have any trouble escaping, even with one character dead in battle while using ATB mode
           Yanfly's skill restriction script should work properly now when used with this script
           Various other bug fixes

If any further incompatibilities are found, please report them to Fomar0153, I(Deathsia) simply pointed out bugs he fixed and with my limited scripting knowledge provided a bug fix to allow compatibility with Yanfly's skill restriction script
----------------------
Known bugs
----------------------
None
=end

$imported = {} if $imported.nil?
$imported["Fomar0153-CBS"] = true

module CBS

  MAX_STAMINA = 1000
  RESET_STAMINA = true
 
  # If ATB is set to false then the bars won't appear and
  # the pauses where the bars would be filling up are removed
  # effectively turning this into a CTB system
  ATB = false
  SAMINA_GAUGE_NAME = ""
  ENABLE_PASSING = true
  PASSING_COST = 1000

  # If TURN_LENGTH is set to 0 then a turn length will be
  # decided on number of actions
  # TURN_LENGTH is number of seconds per turn
  TURN_LENGTH = 0
 
  ESCAPE_COST = 1000
  # If reset stamina is set to true then all characters
  # will start with a random amount of stamina capped at
  # the percentage you set.
  # If reset stamina is set to false then this just
  # affects enemies.
  STAMINA_START_PERCENT = 10

  # Default skill cost
  # If you want to customise skill costs do it like this
  # SKILL_COST[skill_id] = cost
  SKILL_COST = []
  SKILL_COST[0] = 1000
  # Attack
  SKILL_COST[1] = 1000
  # Guard
  SKILL_COST[2] = 1000
 
 
  SKILL_COST[34] = 1000
 
  ITEM_COST = 1000

  # If you prefer to have states handle agility buffs then set STATES_HANDLE_AGI to true
  STATES_HANDLE_AGI = false
  # In the following section mult means the amount you multiply stamina gains by
  # if STATES_HANDLE_AGI is set to true then it is only used to determine bar color
  # with debuffs taking precedence over buffs
  STAMINA_STATES = []
  # Default colour
  STAMINA_STATES[0] = [1,14,32]
  # in the form
  # STAMINA_STATES[STATE_ID] = [MULT,FILL_COLOUR,EMPTY_COLOR]
  # e.g. Haste
  STAMINA_STATES[28] = [2,4,32]
  # e.g. Slow 
  STAMINA_STATES[29] = [0.5,8,32]

  #--------------------------------------------------------------------------
  # ● New Method stamina_gain
  #--------------------------------------------------------------------------
  def self.stamina_gain(battler)
    return ((20) * self.stamina_mult(battler)).to_i
    #return ((2 + [0, battler.agi / 10].max) * self.stamina_mult(battler)).to_i
  end
  #--------------------------------------------------------------------------
  # ● New Method stamina_gain
  #--------------------------------------------------------------------------
  def self.stamina_mult(battler)
    return 1 if STATES_HANDLE_AGI
    mult = STAMINA_STATES[0][0]
    for state in battler.states
      unless STAMINA_STATES[state.id].nil?
        mult *= STAMINA_STATES[state.id][0]
      end
    end
    return mult
  end
  #--------------------------------------------------------------------------
  # ● New Method stamina_gain
  #--------------------------------------------------------------------------
  def self.stamina_colors(battler)
    colors = STAMINA_STATES[0]
    for state in battler.states
      unless STAMINA_STATES[state.id].nil?
        if STAMINA_STATES[state.id][0] < colors[0] or colors[0] == 1
          colors = STAMINA_STATES[state.id]
        end
      end
    end
    return colors
  end
  #--------------------------------------------------------------------------
  # ● New Method stamina_start
  #--------------------------------------------------------------------------
  def self.stamina_start(battler)
    battler.stamina = rand(MAX_STAMINA * STAMINA_START_PERCENT / 100)
  end
end

class Game_BattlerBase
  #--------------------------------------------------------------------------
  # ● New attr_accessor
  #--------------------------------------------------------------------------
  attr_accessor :stamina
 
  #--------------------------------------------------------------------------
  # ● Aliases initialize
  #--------------------------------------------------------------------------
  alias yf_fomar_cbs_initialize initialize
  def initialize
    yf_fomar_cbs_initialize
    @stamina = 0
  end
  #--------------------------------------------------------------------------
  # ● New Method stamina_rate
  #--------------------------------------------------------------------------
  def stamina_rate
    @stamina.to_f / CBS::MAX_STAMINA
  end
  #--------------------------------------------------------------------------
  # ● New Method stamina_rate
  #--------------------------------------------------------------------------
  def stamina_gain
    #Removed the bit about imovable actors not incrementing stamina
    #it was causing a major Paralysis bug (it never went away)
    @stamina = [CBS::MAX_STAMINA, @stamina + CBS.stamina_gain(self)].min
  end
  #--------------------------------------------------------------------------
  # ● New Method stamina_color
  #--------------------------------------------------------------------------
  def stamina_color
    for state in @states
      unless CBS::STAMINA_STATES[state].nil?
        return STAMINA_STATES[state]
      end
    end
    return STAMINA_STATES[0]
  end
end

class Scene_Battle < Scene_Base
 
  attr_accessor :last_battler
  #--------------------------------------------------------------------------
  # ● Rewrote update
  #--------------------------------------------------------------------------
  def update
    super
    if (CBS::ENABLE_PASSING and @actor_command_window.active) and Input.press?(:A)
      command_pass
    end
    if BattleManager.in_turn? and !inputting?
      while @subject.nil? and !CBS::ATB
        process_stamina
      end
      if CBS::ATB
        process_stamina
      end
      process_event
      process_action
    end
    BattleManager.judge_win_loss
  end
  #--------------------------------------------------------------------------
  # ● Rewrote Method update_info_viewport
  #--------------------------------------------------------------------------
  def update_info_viewport
    move_info_viewport(0)   if @party_command_window.active
    move_info_viewport(128) if @actor_command_window.active
    move_info_viewport(128)  if BattleManager.in_turn? and !inputting?
  end
  #--------------------------------------------------------------------------
  # ● New Method inputting?
  #--------------------------------------------------------------------------
  def inputting?
    return @actor_command_window.active || @skill_window.active ||
      @item_window.active || @actor_window.active || @enemy_window.active
  end
  #--------------------------------------------------------------------------
  # ● New Method process_stamina
  #--------------------------------------------------------------------------
  def process_stamina
    @actor_command_window.close
    return if @subject
    BattleManager.advance_turn
    all_battle_members.each do |battler|
      battler.stamina_gain
    end
    @status_window.refresh_stamina
    if @status_window.close?
      @status_window.open
     end
    if BattleManager.escaping?
      $game_party.alive_members.each do |battler|
        if battler.stamina < CBS::MAX_STAMINA
          $game_troop.members.each do |enemy|
            if enemy.stamina == CBS::MAX_STAMINA
              #Casey: update time during Flee
              #enemy.run_lunatic_states(:begin)
              #enemy.update_cooldowns #added a line here
              enemy.on_turn_end
              BattleManager.add_action
              enemy.make_actions
              @subject = enemy
            end
          end
          return
        end
      end
      unless BattleManager.process_escape
        $game_party.alive_members.each do |actor|
          actor.stamina -= CBS::ESCAPE_COST
          #Casey: update time during Flee
          #actor.run_lunatic_states(:begin)
          #actor.update_cooldowns #added a line here
          actor.on_turn_end
          BattleManager.add_action
        end
        BattleManager.set_escaping(false)
      end
    end
    all_battle_members.each do |battler|
      if battler.stamina == CBS::MAX_STAMINA
        ### Casey: Lunatic states and paralysis fix
        @subject = battler
        if @last_battler.nil?
          @last_battler = 0
        end
        ### Casey: Moved paralysis handling to here from Stamina gain
        if not battler.movable? #and not battler.hidden?
          battler.stamina = 0
          #battler.run_lunatic_states(:begin)
          #@subject.update_cooldowns #added a line here
          ### Casey: And more lines
          battler.on_turn_end
          BattleManager.add_action
          return
        end
        if not @last_battler == battler
          #battler.run_lunatic_states(:begin)
          @last_battler = battler
          #@subject.update_cooldowns #added a line here
          ### Casey: And more lines
          battler.on_turn_end
          BattleManager.add_action
        end
        battler.make_actions
        if @subject.inputable? and battler.is_a?(Game_Actor) and not battler.hidden?
          @actor_command_window.setup(@subject)
          @status_window.index = @subject.index
          BattleManager.set_actor(battler)
        end
        return
      end
    end
  end
  #--------------------------------------------------------------------------
  # ● Rewrote start_party_command_selection Yanfly version
  #--------------------------------------------------------------------------
  def start_party_command_selection
    unless scene_changing?
      refresh_status
      @status_window.unselect
      @status_window.open
      if BattleManager.input_start
        @actor_command_window.close
        @party_command_window.setup
      else
        @party_command_window.deactivate
        turn_start
      end
    end
  end
  #--------------------------------------------------------------------------
  # ● Rewrote start_actor_command_selection
  #--------------------------------------------------------------------------
  def start_actor_command_selection
    @party_command_window.close
    BattleManager.set_escaping(false)
    turn_start
  end
  #--------------------------------------------------------------------------
  # ● Rewrote prior_command Yanfly version
  #--------------------------------------------------------------------------
  def prior_command
    redraw_current_status
    start_party_command_selection
  end
  #--------------------------------------------------------------------------
  # ● Rewrote process_action
  #--------------------------------------------------------------------------
  def process_action
    return if scene_changing?
    if !@subject || [email protected]_action
      @subject = BattleManager.next_subject
    end
    if Input.trigger?(:B) and (@subject == nil)
      start_party_command_selection
    end
    return unless @subject
    if @subject.current_action
      @subject.current_action.prepare
      if @subject.current_action.valid?
        @status_window.open
        execute_action
      end
      @subject.remove_current_action
      refresh_status
      @log_window.display_auto_affected_status(@subject)
      @log_window.wait_and_clear
    end
    process_action_end unless @subject.current_action
  end
  #--------------------------------------------------------------------------
  # ● Aliases use_item
  #--------------------------------------------------------------------------
  alias cbs_use_item use_item
  def use_item
    cbs_use_item
    @subject.stamina_loss
  end
  #--------------------------------------------------------------------------
  # ● Rewrote turn_end
  #--------------------------------------------------------------------------
  def turn_end
    all_battle_members.each do |battler|
      #battler.on_turn_end
      refresh_status
      @log_window.display_auto_affected_status(battler)
      @log_window.wait_and_clear
    end
    #BattleManager.turn_end
    #process_event
    #start_party_command_selection
  end
  #--------------------------------------------------------------------------
  # ● Rewrote command_fight
  #--------------------------------------------------------------------------
  def command_fight
    BattleManager.next_command
    start_actor_command_selection
  end
  #--------------------------------------------------------------------------
  # ● Rewrote command_escape
  #--------------------------------------------------------------------------
  def command_escape
    @party_command_window.close
    BattleManager.set_escaping(true)
    turn_start
  end
  #--------------------------------------------------------------------------
  # ● New method command_pass
  #--------------------------------------------------------------------------
  def command_pass
    BattleManager.actor.stamina -= CBS::PASSING_COST
    BattleManager.clear_actor
    @subject = nil
    turn_start
    @actor_command_window.active = false
    @actor_command_window.close
  end
  #--------------------------------------------------------------------------
  # ● Destroyed next_command
  #--------------------------------------------------------------------------
  def next_command
    @status_window.show
    @actor_command_window.show
    @status_aid_window.hide
  end
end




module BattleManager
  #--------------------------------------------------------------------------
  # ● New attr_accessor
  #--------------------------------------------------------------------------
  attr_accessor :premptive
  attr_accessor :surprise
 
  #--------------------------------------------------------------------------
  # ● Rewrote setup
  #--------------------------------------------------------------------------
  def self.setup(troop_id, can_escape = true, can_lose = false)
    init_members
    $game_troop.setup(troop_id)
    @can_escape = can_escape
    @can_lose = can_lose
     make_escape_ratio
    @escaping = false
    @turn_counter = 0
    @actions_per_turn = $game_party.members.size + $game_troop.members.size
    ($game_party.members + $game_troop.members).each do |battler|
      if battler.is_a?(Game_Enemy) or CBS::RESET_STAMINA
        CBS.stamina_start(battler)
      end
      if !battler.is_a?(Game_Enemy) and @surprise
        battler.stamina += 1000
      end
      if battler.is_a?(Game_Enemy) and @premptive
        battler.stamina += 1000
      end
    end
  end
  #--------------------------------------------------------------------------
  # ● New Method set_escaping
  #--------------------------------------------------------------------------
  def self.set_escaping(escaping)
    @escaping = escaping
  end
  #--------------------------------------------------------------------------
  # ● New Method escaping?
  #--------------------------------------------------------------------------
  def self.escaping?
    return @escaping
  end
  #--------------------------------------------------------------------------
  # ● Rewrote turn_start Yanfly version
  #--------------------------------------------------------------------------
  def self.turn_start
    @phase = :turn
    clear_actor
    $game_troop.increase_turn if $game_troop.turn_count == 0
    @performed_battlers = []
  end
  #--------------------------------------------------------------------------
  # ● New Method set_actor
  #--------------------------------------------------------------------------
  def self.set_actor(actor)
    @actor_index = actor.index
  end
  #--------------------------------------------------------------------------
  # ● New Increase action counter
  #--------------------------------------------------------------------------
  def self.add_action
    return if @actions_per_turn.nil?
    @turn_counter += 1
    if @turn_counter == @actions_per_turn and CBS::TURN_LENGTH == 0
      $game_troop.increase_turn
      SceneManager.scene.turn_end
      @turn_counter = 0
    end
  end
  #--------------------------------------------------------------------------
  # ● New Method advance_turn
  #--------------------------------------------------------------------------
  def self.advance_turn
    return if CBS::TURN_LENGTH == 0
    @turn_counter += 1
    if @turn_counter == 60 * CBS::TURN_LENGTH
      $game_troop.increase_turn
      SceneManager.scene.turn_end
      @turn_counter = 0
    end
  end
end

class Game_Battler < Game_BattlerBase
  #--------------------------------------------------------------------------
  # ● Rewrote on_turn_end
  #--------------------------------------------------------------------------
  def on_turn_end
    @result.clear
    regenerate_all
    update_state_turns
    update_buff_turns
    remove_states_auto(2)
  end
  #--------------------------------------------------------------------------
  # ● New Method on_turn_end
  #--------------------------------------------------------------------------
  def stamina_loss
    return if dead?
    return if hidden?
    if self.actor?
      @stamina -= input.stamina_cost
    else
      @stamina -= @actions[0].stamina_cost
    end
    #BattleManager.add_action
  end
end

class Game_Actor < Game_Battler
  #--------------------------------------------------------------------------
  # ● Rewrote input
  #--------------------------------------------------------------------------
  def input
    if @actions[@action_input_index] == nil
      @actions[@action_input_index] = Game_Action.new(self)
    end
    return @actions[@action_input_index]
  end
end

class Game_Action
  #--------------------------------------------------------------------------
  # ● New Method stamina_cost
  #--------------------------------------------------------------------------
  def stamina_cost
    if @item.is_skill?
      return CBS::SKILL_COST[item.id] if CBS::SKILL_COST[item.id]
      return CBS::SKILL_COST[0]
    end
    return CBS::ITEM_COST if @item.is_item?
    return CBS::MAX_STAMINA
  end
end

class Window_BattleStatus < Window_Selectable
  #--------------------------------------------------------------------------
  # Aliases method: draw_item yanfly version
  #--------------------------------------------------------------------------
  alias prefomar_draw_item draw_item
  def draw_item(index)
    unless CBS::ATB
      prefomar_draw_item(index)
      return
    end
    return if index.nil?
    clear_item(index)
    actor = battle_members[index]
    rect = item_rect(index)
    return if actor.nil?
    draw_actor_face(actor, rect.x+2, rect.y+2, actor.alive?)
    draw_actor_name(actor, rect.x, rect.y, rect.width-8)
    draw_actor_action(actor, rect.x, rect.y)
    draw_actor_icons(actor, rect.x, line_height*1, rect.width)
    gx = YEA::BATTLE::BATTLESTATUS_HPGAUGE_Y_PLUS
    contents.font.size = YEA::BATTLE::BATTLESTATUS_TEXT_FONT_SIZE
    draw_actor_hp(actor, rect.x+2, line_height*2, rect.width-4)
    if draw_tp?(actor) && draw_mp?(actor)
      dw = rect.width/2-2
      dw += 1 if $imported["YEA-CoreEngine"] && YEA::CORE::GAUGE_OUTLINE
      draw_actor_tp(actor, rect.x+2, line_height*2+gx, dw)
      dw = rect.width - rect.width/2 - 2
      draw_actor_mp(actor, rect.x+rect.width/2, line_height*2+gx, dw)
    elsif draw_tp?(actor) && !draw_mp?(actor)
      draw_actor_tp(actor, rect.x+2, line_height*2+gx, rect.width-4)
    else
      draw_actor_mp(actor, rect.x+2, line_height*2+gx, rect.width-4)
    end
    draw_actor_stamina(actor, rect.x+2, line_height*3, rect.width-4)
  end
  #--------------------------------------------------------------------------
  # overwrite method: draw_item yanfly version
  #--------------------------------------------------------------------------
  def draw_item_stamina(index)
    return if index.nil?
    actor = battle_members[index]
    rect = item_rect(index)
    return if actor.nil?
    gx = YEA::BATTLE::BATTLESTATUS_HPGAUGE_Y_PLUS
    contents.font.size = YEA::BATTLE::BATTLESTATUS_TEXT_FONT_SIZE
    draw_actor_stamina(actor, rect.x+2, line_height*3, rect.width-4)
  end
  #--------------------------------------------------------------------------
  # new method: refresh_stamina
  #--------------------------------------------------------------------------
  def refresh_stamina
    return unless CBS::ATB
    item_max.times {|i| draw_item_stamina(i) }
  end
  #--------------------------------------------------------------------------
  # new method: draw_actor_stamina
  #--------------------------------------------------------------------------
  def draw_actor_stamina(actor, dx, dy, width = 124)
    draw_gauge(dx, dy, width, actor.stamina_rate, text_color(CBS.stamina_colors(actor)[2]),text_color(CBS.stamina_colors(actor)[1]))
    change_color(system_color)
    cy = (Font.default_size - contents.font.size) / 2 + 1
    draw_text(dx+2, dy+cy, 30, line_height, CBS::SAMINA_GAUGE_NAME)
  end
end
edited version of Fomar0153's ATB script
It processes the death differently.
Ruby:
# ╔═════════════════════════════════════╦════════════════════╗
# ║ Title: Transmute enemy into Gold    ║  Version: 1.02     ║
# ║ Author: Roninator2                  ║                    ║
# ╠═════════════════════════════════════╬════════════════════╣
# ║ Function:                           ║   Date Created     ║
# ║     Transmute enemy into gold       ╠════════════════════╣
# ║     for specific skill on death     ║    05 Sep 2022     ║
# ╚═════════════════════════════════════╩════════════════════╝
# ╔══════════════════════════════════════════════════════════╗
# ║ Instructions:                                            ║
# ║                                                          ║
# ║   Specify which method to use for gaining gold           ║
# ║   0 = enemy maximum hp                                   ║
# ║   1 = random number from amount specified                ║
# ║   2 = exact amount specified                             ║
# ║                                                          ║
# ║   Specify the skill id that will be the transmute skill  ║
# ║                                                          ║
# ║   Specify the variable to use (required)                 ║
# ║                                                          ║
# ║   Specify the message to display                         ║
# ║    "Turned Slime A into 100 Gold"                        ║
# ║                                                          ║
# ║   This script will cuyrrently only work for one skill    ║
# ╚══════════════════════════════════════════════════════════╝
# ╔══════════════════════════════════════════════════════════╗
# ║ Updates:                                                 ║
# ║   2022-Sep-05 - Initial publish                          ║
# ║   2022-Sep-06 - Added support for Yanfly Battle Engine   ║
# ║   2022-Sep-06 - Added support for Fomar ATB 1.5 edit     ║
# ║                 Use 1.01 is you do not have Fomar ATB    ║
# ╚══════════════════════════════════════════════════════════╝
# ╔══════════════════════════════════════════════════════════╗
# ║ Terms of use:                                            ║
# ║ Free for all uses in RPG Maker VX Ace - except nudity    ║
# ╚══════════════════════════════════════════════════════════╝

module R2_Gain_Gold_Enemy_Bonus
  Method = 0 # 0 = enemy.hp, 1 = random amount, 2 = specific amount
  Amount = 1000 # for 1 & 2. 1 = random 1000, 2 = exactly 1000
  Skill = 128 # transmute skill
  Variable = 9
  Message = "Turned %s into " # %s = enemy name
end

# ╔══════════════════════════════════════════════════════════╗
# ║      End Of Editable Region                              ║
# ╚══════════════════════════════════════════════════════════╝

class Game_Battler
  attr_accessor :gold_skill
  alias r2_enemy_gold_transmute die
  def die
    r2_enemy_gold_transmute
    return if @actions.empty?
    if self.is_a?(Game_Enemy)
      if $game_variables[R2_Gain_Gold_Enemy_Bonus::Variable] == R2_Gain_Gold_Enemy_Bonus::Skill
        add_gold
      end
    end
    $game_variables[R2_Gain_Gold_Enemy_Bonus::Variable] = 0
  end
  def transmute
    if self.is_a?(Game_Enemy)
      if $game_variables[R2_Gain_Gold_Enemy_Bonus::Variable] == R2_Gain_Gold_Enemy_Bonus::Skill
        add_gold
      end
    end
    $game_variables[R2_Gain_Gold_Enemy_Bonus::Variable] = 0
  end
  def check_action
    act = @actions[0]
    return if act.nil?
    return if $imported["YEA-BattleEngine"] == true && act.item.nil?
    $game_variables[R2_Gain_Gold_Enemy_Bonus::Variable] = act.item.id if self.is_a?(Game_Actor) && @actions.any?
  end
  def current_action
    check_action
    @actions[0]
  end
  def add_gold
    gold = 0
    case R2_Gain_Gold_Enemy_Bonus::Method
    when 0
      gold = self.mhp
    when 1
      gold = rand(R2_Gain_Gold_Enemy_Bonus::Amount + 1)
    when 2
      gold = R2_Gain_Gold_Enemy_Bonus::Amount
    end
    $game_party.gain_gold(gold)
    text = sprintf(R2_Gain_Gold_Enemy_Bonus::Message,self.name) + gold.to_s + " \\G!"
    $game_message.add(text)
  end
end
class Scene_Battle < Scene_Base
  def apply_item_effects(target, item)
    if $imported["YEA-LunaticObjects"]
      lunatic_object_effect(:prepare, item, @subject, target)
    end
    target.item_apply(@subject, item)
    target.transmute if target.dead?
    status_redraw_target(@subject)
    status_redraw_target(target) unless target == @subject
    @log_window.display_action_results(target, item)
    if $imported["YEA-LunaticObjects"]
      lunatic_object_effect(:during, item, @subject, target)
    end
    perform_collapse_check(target)
  end
end
It processes the death differently.
Ruby:
# ╔═════════════════════════════════════╦════════════════════╗
# ║ Title: Transmute enemy into Gold    ║  Version: 1.02     ║
# ║ Author: Roninator2                  ║                    ║
# ╠═════════════════════════════════════╬════════════════════╣
# ║ Function:                           ║   Date Created     ║
# ║     Transmute enemy into gold       ╠════════════════════╣
# ║     for specific skill on death     ║    05 Sep 2022     ║
# ╚═════════════════════════════════════╩════════════════════╝
# ╔══════════════════════════════════════════════════════════╗
# ║ Instructions:                                            ║
# ║                                                          ║
# ║   Specify which method to use for gaining gold           ║
# ║   0 = enemy maximum hp                                   ║
# ║   1 = random number from amount specified                ║
# ║   2 = exact amount specified                             ║
# ║                                                          ║
# ║   Specify the skill id that will be the transmute skill  ║
# ║                                                          ║
# ║   Specify the variable to use (required)                 ║
# ║                                                          ║
# ║   Specify the message to display                         ║
# ║    "Turned Slime A into 100 Gold"                        ║
# ║                                                          ║
# ║   This script will cuyrrently only work for one skill    ║
# ╚══════════════════════════════════════════════════════════╝
# ╔══════════════════════════════════════════════════════════╗
# ║ Updates:                                                 ║
# ║   2022-Sep-05 - Initial publish                          ║
# ║   2022-Sep-06 - Added support for Yanfly Battle Engine   ║
# ║   2022-Sep-06 - Added support for Fomar ATB 1.5 edit     ║
# ║                 Use 1.01 is you do not have Fomar ATB    ║
# ╚══════════════════════════════════════════════════════════╝
# ╔══════════════════════════════════════════════════════════╗
# ║ Terms of use:                                            ║
# ║ Free for all uses in RPG Maker VX Ace - except nudity    ║
# ╚══════════════════════════════════════════════════════════╝

module R2_Gain_Gold_Enemy_Bonus
  Method = 0 # 0 = enemy.hp, 1 = random amount, 2 = specific amount
  Amount = 1000 # for 1 & 2. 1 = random 1000, 2 = exactly 1000
  Skill = 128 # transmute skill
  Variable = 9
  Message = "Turned %s into " # %s = enemy name
end

# ╔══════════════════════════════════════════════════════════╗
# ║      End Of Editable Region                              ║
# ╚══════════════════════════════════════════════════════════╝

class Game_Battler
  attr_accessor :gold_skill
  alias r2_enemy_gold_transmute die
  def die
    r2_enemy_gold_transmute
    return if @actions.empty?
    p($game_variables[R2_Gain_Gold_Enemy_Bonus::Variable])
    if self.is_a?(Game_Enemy)
      if $game_variables[R2_Gain_Gold_Enemy_Bonus::Variable] == R2_Gain_Gold_Enemy_Bonus::Skill
        add_gold
      end
    end
    $game_variables[R2_Gain_Gold_Enemy_Bonus::Variable] = 0
  end
  def transmute
    p($game_variables[R2_Gain_Gold_Enemy_Bonus::Variable])
    if self.is_a?(Game_Enemy)
      if $game_variables[R2_Gain_Gold_Enemy_Bonus::Variable] == R2_Gain_Gold_Enemy_Bonus::Skill
        add_gold
      end
    end
    $game_variables[R2_Gain_Gold_Enemy_Bonus::Variable] = 0
  end
  def check_action
    act = @actions[0]
    return if act.nil?
    if $imported["YEA-BattleEngine"] == true
      return if act.item.nil?
    end
    $game_variables[R2_Gain_Gold_Enemy_Bonus::Variable] = act.item.id if self.is_a?(Game_Actor) && [email protected]?
  end
  def current_action
    check_action
    @actions[0]
  end
  def add_gold
    gold = 0
    case R2_Gain_Gold_Enemy_Bonus::Method
    when 0
      gold = self.mhp
    when 1
      gold = rand(R2_Gain_Gold_Enemy_Bonus::Amount)
    when 2
      gold = R2_Gain_Gold_Enemy_Bonus::Amount
    end
    $game_party.gain_gold(gold)
    text = sprintf(R2_Gain_Gold_Enemy_Bonus::Message,self.name) + gold.to_s + " \\G!"
    $game_message.add(text)
  end
end
class Scene_Battle < Scene_Base
  def apply_item_effects(target, item)
    if $imported["YEA-LunaticObjects"]
      lunatic_object_effect(:prepare, item, @subject, target)
    end
    target.item_apply(@subject, item)
    target.transmute if target.dead?
    status_redraw_target(@subject)
    status_redraw_target(target) unless target == @subject
    @log_window.display_action_results(target, item)
    if $imported["YEA-LunaticObjects"]
      lunatic_object_effect(:during, item, @subject, target)
    end
    perform_collapse_check(target)
  end
end
Works like a charm! Thank you again, so very very much.
Oh, I see your point. My bad, in that case, you should do a common event that turn off that switch. Cool thing is that you only need 1 common event for that. In the traits of that skill add that it call for a common event, and in that common event all you have to put is the switch to be turned off. But in that case I'm not sure if it will nullified the other common event. I'm not home to try it. Anyway, if roni already fixed it script, this is pointless I guess.
All good. Thanks for helping though, I appreciate it a lot.
Works like a charm!
Had a small mistake, I left two print statements in the code. I've updated the code above.
I know this is quite hypothetical but what happens when an enemy ally tries to revive his fellow mob and fails?

These pieces of code say:
Ruby:
    if $imported["YEA-BattleEngine"] == true
      return if act.item.nil?
    end
...
    $game_variables[R2_Gain_Gold_Enemy_Bonus::Variable] = act.item.id if self.is_a?(Game_Actor) && [email protected]?

They should read instead:
Ruby:
    return if $imported["YEA-BattleEngine"] and act.item.nil?
...
    $game_variables[R2_Gain_Gold_Enemy_Bonus::Variable] = act.item.id if self.is_a?(Game_Actor) && @actions.any?

And concerning randomly generated values:
Ruby:
    when 1
      gold = rand(R2_Gain_Gold_Enemy_Bonus::Amount)

Ruby:
    when 1
      gold = rand(R2_Gain_Gold_Enemy_Bonus::Amount + 1)

Otherwise the value will NEVER hit the maximum value you set there.

Original thread: https://forums.rpgmakerweb.com/threads/solved-need-help-making-a-transmute-morph-skill-that-turns-enemies-into-gold-when-killed-with-it.150766/