Script call for "enemy transform" and "change enemy state" within battle?

Hi!

I'm trying to create a system within my game that requires some uses of "enemy transform" and "change enemy state". It would save me so much time if a could do this with a script call and substitute the enemy number with the value of a variable ($game_variables[n]), so i don't have to repeat the same code for all individual 8 enemies...

If anyone knows a script call for this it is much appreciated! I checked the master script call list for VX Ace but couldn't find any for these specific actions...
There should be a pinned topic in the forum for VXAce that contains the script equivalent of every event command.

Have you not checked as you didn't know that, or is that old link gone?
I'm not at the editor right now so I might be remembering incorrectly but you should be able to use:

$game_troop.alive_members.each { |member| member.add_state(n) }

Where "n" replace that with your State ID (from the database) or a variable containing the State ID.

That code should iterate through each currently active enemy and add the specified state to them (if able).

You'd replace "add_state" with "remove_state" to remove states instead.
There should be a pinned topic in the forum for VXAce that contains the script equivalent of every event command.

Have you not checked as you didn't know that, or is that old link gone?
Yeah i looked at that, but it unfortunately leaves out a lot of battle commands… so I couldn’t find specific script calls for change enemy state or transform enemy
🙁
I'm not at the editor right now so I might be remembering incorrectly but you should be able to use:

$game_troop.alive_members.each { |member| member.add_state(n) }

Where "n" replace that with your State ID (from the database) or a variable containing the State ID.

That code should iterate through each currently active enemy and add the specified state to them (if able).

You'd replace "add_state" with "remove_state" to remove states instead.
Thanks I’m gonna try this! You don’t know any script call for “enemy transform” by chance?
Thanks I’m gonna try this! You don’t know any script call for “enemy transform” by chance?
Not a problem!

Sorry, I don't know the transform thing off the top of my head unfortunately. I've been stupid busy with real life stuff this week so I don't have time to look into it right now.

You can try searching for the function yourself in the default VXAce scripts in the editor.

Use ctrl+f and search for "def transform", "def enemy_transform", or "def transform_enemy".

It should be "Game_Enemy" but might be in "Game_Battler", or "Game_BattlerBase" instead. There's a possibility of it being a "troop" function and found in "Game_Troop" instead.

If you find it, you should be able to figure out how it works and call to it in a script call.


If I get some free time to sit at the editor at some point I'll be sure to drop the solution here. If you haven't solved it yourself by then.
It would be better to tell us WHEN stuff like enemy's transformation should be triggered in your game to make it easy for you to use the commands at the right time.
$game_troop.alive_members.each { |member| member.transform(n) }

Where "n" put the corresponding database ID of the enemy you want to transform them into.

This will transform all currently active enemies to the enemy ID you provide.

And yes, as @kyonides said, some context as to when you want transformations, etc. to trigger would be helpful next time. Especially if you're looking for more elegant control over it. I'm just providing a "fast and dirty" solution for it here. It'll work just fine but it will affect every enemy in the current battle.

Hope that helps, good luck with your game!
$game_troop.alive_members.each { |member| member.transform(n) }

Where "n" put the corresponding database ID of the enemy you want to transform them into.

This will transform all currently active enemies to the enemy ID you provide.

And yes, as @kyonides said, some context as to when you want transformations, etc. to trigger would be helpful next time. Especially if you're looking for more elegant control over it. I'm just providing a "fast and dirty" solution for it here. It'll work just fine but it will affect every enemy in the current battle.

Hope that helps, good luck with your game!
Thanks! Yeah maybe i wasn’t to clear on what I meant, but thanks for helping me out. Although unfortunately I do need a script call that can reference a specific enemy number within the troop. I would like to do this in order to not have to repeat the same code for every single troop member in my common event for enemy transformations. I’m thinking that if i had a script call in which i can insert the value of a variable in place of the enemy (in the troop) who I want to transform I could make this part of my game a lot less messy (and of course not have to repeat the same code for all troop members).
Thanks! Yeah maybe i wasn’t to clear on what I meant, but thanks for helping me out. Although unfortunately I do need a script call that can reference a specific enemy number within the troop. I would like to do this in order to not have to repeat the same code for every single troop member in my common event for enemy transformations. I’m thinking that if i had a script call in which i can insert the value of a variable in place of the enemy (in the troop) who I want to transform I could make this part of my game a lot less messy (and of course not have to repeat the same code for all troop members).
Once again, forget about what variable you wanna use for a moment and focus on the WHAT serves as the trigger & WHEN the transformation should be triggered. I think it might be one of the reasons you're facing some issues now.
I concur. I'm not quite understanding what exactly it is you are trying to do.
Alright, so I have a troop event that runs when an enemy inflicted with a "Necro-Curse" state reaches 0 % health. This troop event runs a common event in which the enemy that has reached 0 % health is transformed into a zombie. This works great and I have no issues with it. Although... My game uses different monster types. There are animal-types, ice-types, human-types etc etc. And all the different types have different zombie transformations. The types are determined by different passive states applied to each respective enemy.

Here's a snippet of the code for the transformations:

common event.png


As you can see there are a lot to just make enemy 1# of the troop into a zombie (this is just a small part of all possible transformations). This will then have to be repeated 7 more times to cover all possible enemies within a troop. If I had a script call I don't have to do this, and I would be able to change the code and make revisions to it without having to make 7 copies every time I want to tweak something.

So the script call I would want is one that doesn't require me to copy and paste every transformation over and over again. If a script call could make the troop ID of the enemy based upon the value of a variable it would help a lot and make the work much less tediuous.
What would additionally be great is a script call within the conditinal branch that could check if a state is applied to a troop number based upon the value of a variable.

If i had these tools it would tighten up this common event and make it 10 times shorter...
I hope I made sense this time, and I really appreciate you for trying to help me out, even if it's a problem that is very hard to explain...
I think I have come up with a prototype of the script you'd need to make the transform happen as smoothly as possible. Remember it's just a PROTOTYPE!

Ruby:
# * KAfterDefeat ACE - Prototype!
#   Scripter : Kyonides Arkanthes
#   2023-04-28

# How to Use:

# Just leave a note in your favorite enemy's notebox:

# Example: _die & become 1_

# ...and then it will become... a slime!

module KAfterDefeat
  REGEX = /_die & become (\d+)_/i
  extend self
  attr_accessor :enemy_needs_refresh
end

class Game_Battler
  alias :kyon_after_def_gm_btlr_exe_dmg :execute_damage
  def execute_damage(user)
    kyon_after_def_gm_btlr_exe_dmg(user)
    process_deadly_transformation
  end

  def process_deadly_transformation
    return if @actor_id or @hp > 0
    enemy.note[KAfterDefeat::REGEX]
    enemy_id = $1.to_i
    return if enemy_id == 0
    recover_all
    transform(enemy_id)
    $game_troop.make_unique_names
    KAfterDefeat.enemy_needs_refresh = true
  end
end

class Spriteset_Battle
  alias :kyon_after_def_spriteset_btl_up_enemies :update_enemies
  def update_enemies
    refresh_enemies
    kyon_after_def_spriteset_btl_up_enemies
  end

  def refresh_enemies
    return unless KAfterDefeat.enemy_needs_refresh
    KAfterDefeat.enemy_needs_refresh = nil
    mobsters = $game_troop.members.reverse
    @enemy_sprites.size.times{|n| @enemy_sprites[n].battler = mobsters[n] }
  end
end
Thanks @kyonides, I haven't had any time to work on this at all. And you went a step further than me and implemented the whole notetags thing, brilliant. I've never been able to figure out how you all do that.

Can I ask a technical question?: How the heck did you get the enemy id from "$1.to_i"? It looks like on the previous line you treat the enemy's note variable like an array with the "REGEX" part but I don't quite understand what's happening there.

If you don't mind my asking.
I think I have come up with a prototype of the script you'd need to make the transform happen as smoothly as possible. Remember it's just a PROTOTYPE!

Ruby:
# * KAfterDefeat ACE - Prototype!
#   Scripter : Kyonides Arkanthes
#   2023-04-28

# How to Use:

# Just leave a note in your favorite enemy's notebox:

# Example: _die & become 1_

# ...and then it will become... a slime!

module KAfterDefeat
  REGEX = /_die & become (\d+)_/i
  extend self
  attr_accessor :enemy_needs_refresh
end

class Game_Battler
  alias :kyon_after_def_gm_btlr_exe_dmg :execute_damage
  def execute_damage(user)
    kyon_after_def_gm_btlr_exe_dmg(user)
    process_deadly_transformation
  end

  def process_deadly_transformation
    return if @actor_id or @hp > 0
    enemy.note[KAfterDefeat::REGEX]
    enemy_id = $1.to_i
    return if enemy_id == 0
    recover_all
    transform(enemy_id)
    $game_troop.make_unique_names
    KAfterDefeat.enemy_needs_refresh = true
  end
end

class Spriteset_Battle
  alias :kyon_after_def_spriteset_btl_up_enemies :update_enemies
  def update_enemies
    refresh_enemies
    kyon_after_def_spriteset_btl_up_enemies
  end

  def refresh_enemies
    return unless KAfterDefeat.enemy_needs_refresh
    KAfterDefeat.enemy_needs_refresh = nil
    mobsters = $game_troop.members.reverse
    @enemy_sprites.size.times{|n| @enemy_sprites[n].battler = mobsters[n] }
  end
end
This script is pretty cool, but unfortunatley it's not gonna work in my case. I guess im just poor at explaining what I need. You see, I'm not looking for a script, rather a script call. But i guess there are no script calls for transform enemy that take into account troop numbers? (werid) The script you provided doesn't take into account that the enemy needs to have the Necro-Curse state applied in order for the transformation to take place. Also it doesn't take into account that for each enemy type there are three possible transformations determined by RNG (see common event screenshot in previous reply). But don't do any adjustments to the script since i don't think i need a script. But thanks for taking your time with my request, I really appreciate you taking time out of your day to try and help me out 🙂
I'm not looking for a script, rather a script call
and were basically saying it won't work for a script call.
The process is too complicated for a one line script call.

I tested in a new project.
I used a skill to inflict a state and then killed the slime and he transformed
You will have to edit the script to add or remove some state checks.
I'm not sure how to streamline it so that editing of the script is not required.
Version two is more stream lined. Just set the states and transform enemy id's and it will go through them all and if the state is applied it will do the transform.
Spoiler: first version
Ruby:
module R2_Multi_Transform
  # { state id => [ enemy id 1, enemy id 2, enemy id 3, ... ] }
  State1 = { 10 => [ 15,16,17 ] }
  State2 = { 11 => [ 18,19,20 ] }
  State3 = { 28 => [ 3,4,5 ] }
end

class Game_Battler
  alias r2_check_state_transform_death execute_damage
  def execute_damage(user)
    @infected_states = self.states
    r2_check_state_transform_death(user)
    check_enemy_transform
    @infected_states = nil
  end
  def check_enemy_transform
    return if self.is_a?(Game_Actor) || self.hp > 0
    infected = []
    @infected_states.each do |state_i|
      infected << state_i.id
    end
    state_check = R2_Multi_Transform::State1.keys[0]
    transform1 = R2_Multi_Transform::State1.values[0] if infected.include?(state_check)
    state_check = R2_Multi_Transform::State2.keys[0]
    transform2 = R2_Multi_Transform::State2.values[0] if infected.include?(state_check)
    state_check = R2_Multi_Transform::State3.keys[0]
    transform3 = R2_Multi_Transform::State3.values[0] if infected.include?(state_check)
    if !transform1.nil?
      tren = transform1.sample
    end
    if !transform2.nil?
      tren = transform2.sample
    end
    if !transform3.nil?
      tren = transform3.sample
    end
    remove_state(death_state_id) if tren != nil
    transform(tren) if tren != nil
    recover_all if tren != nil
  end
end
Spoiler: second version
Ruby:
# ╔═════════════════════════════════════╦════════════════════╗
# ║ Title: Multi Enemy Transform        ║  Version: 1.00     ║
# ║ Author: Roninator2                  ║                    ║
# ╠═════════════════════════════════════╬════════════════════╣
# ║ Function:                           ║   Date Created     ║
# ║                                     ╠════════════════════╣
# ║ Transform Enemy when dead with state║    30 Apr 2023     ║
# ╚═════════════════════════════════════╩════════════════════╝
# ╔══════════════════════════════════════════════════════════╗
# ║ Instructions:                                            ║
# ║   Configure Hash below to you preference                 ║
# ║   When the state is applied to the enemy,                ║
# ║   the enemy will transform into a random enemy specified ║
# ╚══════════════════════════════════════════════════════════╝
# ╔═════════════════════════════════════╗
# ║ Terms of use:                       ║
# ║ Free for all uses in RPG Maker      ║
# ╚═════════════════════════════════════╝

module R2_Multi_Transform
  # { state id => [ enemy id 1, enemy id 2, enemy id 3, ... ] }
  State1 = { 10 => [ 15,16,17 ] }
  State2 = { 11 => [ 18,19,20 ] }
  State3 = { 28 => [ 3,4,5 ] }
end

class Game_Battler
  alias r2_check_state_transform_death execute_damage
  def execute_damage(user)
    @infected_states = self.states
    r2_check_state_transform_death(user)
    check_enemy_transform
    @infected_states = nil
  end
  def check_enemy_transform
    return if self.is_a?(Game_Actor) || self.hp > 0
    infected = []
    @infected_states.each do |state|
      infected << state.id
    end
    @tren = nil
    R2_Multi_Transform.constants.each do |i|
      hash_check = R2_Multi_Transform.const_get(i).to_hash
      state_check = hash_check.keys[0]
      @tren = hash_check.values[0] if infected.include?(state_check)
    end
    if [email protected]?
      tren = @tren.sample
    end
    remove_state(death_state_id) if @tren != nil
    transform(tren) if @tren != nil
    recover_all if @tren != nil
    @tren = nil
  end
end
and were basically saying it won't work for a script call.
The process is too complicated for a one line script call.

I tested in a new project.
I used a skill to inflict a state and then killed the slime and he transformed
You will have to edit the script to add or remove some state checks.
I'm not sure how to streamline it so that editing of the script is not required.
Version two is more stream lined. Just set the states and transform enemy id's and it will go through them all and if the state is applied it will do the transform.
Spoiler: first version
Ruby:
module R2_Multi_Transform
  # { state id => [ enemy id 1, enemy id 2, enemy id 3, ... ] }
  State1 = { 10 => [ 15,16,17 ] }
  State2 = { 11 => [ 18,19,20 ] }
  State3 = { 28 => [ 3,4,5 ] }
end

class Game_Battler
  alias r2_check_state_transform_death execute_damage
  def execute_damage(user)
    @infected_states = self.states
    r2_check_state_transform_death(user)
    check_enemy_transform
    @infected_states = nil
  end
  def check_enemy_transform
    return if self.is_a?(Game_Actor) || self.hp > 0
    infected = []
    @infected_states.each do |state_i|
      infected << state_i.id
    end
    state_check = R2_Multi_Transform::State1.keys[0]
    transform1 = R2_Multi_Transform::State1.values[0] if infected.include?(state_check)
    state_check = R2_Multi_Transform::State2.keys[0]
    transform2 = R2_Multi_Transform::State2.values[0] if infected.include?(state_check)
    state_check = R2_Multi_Transform::State3.keys[0]
    transform3 = R2_Multi_Transform::State3.values[0] if infected.include?(state_check)
    if !transform1.nil?
      tren = transform1.sample
    end
    if !transform2.nil?
      tren = transform2.sample
    end
    if !transform3.nil?
      tren = transform3.sample
    end
    remove_state(death_state_id) if tren != nil
    transform(tren) if tren != nil
    recover_all if tren != nil
  end
end
Spoiler: second version
Ruby:
# ╔═════════════════════════════════════╦════════════════════╗
# ║ Title: Multi Enemy Transform        ║  Version: 1.00     ║
# ║ Author: Roninator2                  ║                    ║
# ╠═════════════════════════════════════╬════════════════════╣
# ║ Function:                           ║   Date Created     ║
# ║                                     ╠════════════════════╣
# ║ Transform Enemy when dead with state║    30 Apr 2023     ║
# ╚═════════════════════════════════════╩════════════════════╝
# ╔══════════════════════════════════════════════════════════╗
# ║ Instructions:                                            ║
# ║   Configure Hash below to you preference                 ║
# ║   When the state is applied to the enemy,                ║
# ║   the enemy will transform into a random enemy specified ║
# ╚══════════════════════════════════════════════════════════╝
# ╔═════════════════════════════════════╗
# ║ Terms of use:                       ║
# ║ Free for all uses in RPG Maker      ║
# ╚═════════════════════════════════════╝

module R2_Multi_Transform
  # { state id => [ enemy id 1, enemy id 2, enemy id 3, ... ] }
  State1 = { 10 => [ 15,16,17 ] }
  State2 = { 11 => [ 18,19,20 ] }
  State3 = { 28 => [ 3,4,5 ] }
end

class Game_Battler
  alias r2_check_state_transform_death execute_damage
  def execute_damage(user)
    @infected_states = self.states
    r2_check_state_transform_death(user)
    check_enemy_transform
    @infected_states = nil
  end
  def check_enemy_transform
    return if self.is_a?(Game_Actor) || self.hp > 0
    infected = []
    @infected_states.each do |state|
      infected << state.id
    end
    R2_Multi_Transform.constants.each do |i|
      hash_check = R2_Multi_Transform.const_get(i).to_hash
      state_check = hash_check.keys[0]
      @tren = hash_check.values[0] if infected.include?(state_check)
    end
    if [email protected]?
      tren = @tren.sample
    end
    remove_state(death_state_id) if tren != nil
    transform(tren) if @tren != nil
    @tren = nil
    recover_all if tren != nil
  end
end
This is really cool! I thought there were script calls for every event command, but i guess not... That goes to show you how much I know about this stuff ^^'
for every event command
Generally, yes, but your request needs to get the battler id and specify the transform for it.
In the common event you have no idea what the battler id or troop number is without doing some more work. which is why a single script call will not work.
It's really easier to use a script when doing such complicated things.

When using common events and you know the battler id or position in the troop, then you can get the id and vice versa, then you can use a script command.
Something like $game_troop.members[1].transform(3)
* sorry typo
Generally, yes, but your request needs to get the battler id and specify the transform for it.
In the common event you have no idea what the battler id or troop number is without doing some more work. which is why a single script call will not work.
It's really easier to use a script when doing such complicated things.

When using common events and you know the battler id or position in the troop, then you can get the id and vice versa, then you can use a script command.
Something like $game_troop.members[1].transform[3]
Yeah! Something closer to "$game_troop.members[1].transform[3]". I already have a way of the game "knowing" which troop number to use. Unfortunatly this specific one you provided doesn't work, and gives me an error. But this is the kind of simple thing that I need, it doesn't need to be a whole system, I already have a functioning system.

In short, all i need is a script call like "$game_troop.members[1].transform[3]"... But this specific one doesn't work for some reason... But if it did, it would've been perfect - just what I needed ^^
Then you need to show more about your system you have as if I use that line in a troop page it works fine.

Original thread: https://forums.rpgmakerweb.com/threads/script-call-for-enemy-transform-and-change-enemy-state-within-battle.157006/