How do I make a variable based on how many specific enemies are in battle? For example, if there are 2 Slimes on the battlefield, the variable would be 2. If there are none, then it would be 0.
Variable based on number of enemies in battle?
RPG Maker VXAce SupportControl Variables: Script
$game_troop.members.select{|mbr| mbr.id == enemy.id}.size
where enemy.id is the id of the enemy you're interested in, so 1 for slimes.
If you are after how many of that kind of enemy remain (if some have been killed), use alive_members instead of members.
$game_troop.members.select{|mbr| mbr.id == enemy.id}.size
where enemy.id is the id of the enemy you're interested in, so 1 for slimes.
If you are after how many of that kind of enemy remain (if some have been killed), use alive_members instead of members.
The code doesn't fit inside the Script tab...Shaz said:
What do you mean by it doesn't fit?
well, enemy.id would be replaced by a one- or two-digit number. Instead of mbr you could just put m - those two things reduce the length by 10 characters.
If that still isn't enough, use a Script command instead of a Control Variables command:
If that still isn't enough, use a Script command instead of a Control Variables command:
Code:
$game_variables[#] = $game_troop.members.select{|mbr| mbr.id == #}.size
It worked perfectly, thanks! I just had to replace id with enemy_id.Shaz said:
i have a similar question
variable based on how many enemies still alive in battle?
idk if this works:
$game_variables[#] = $game_troop.membersthanks
variable based on how many enemies still alive in battle?
idk if this works:
$game_variables[#] = $game_troop.membersthanks
Please do not hijack other people's topics. If you have a question, make your own topic - we want one topic per question for searchability.
As the original question appears to be solved, closing
Original thread: https://forums.rpgmakerweb.com/threads/variable-based-on-number-of-enemies-in-battle.45402/