Hey there, I was curious if there was a way to get the number of battlers active built in to the engine, or if a work around would be needed?
I.E., you're fighting a troop of Wolf, Wolf, Slime. The Slime is dead, so the # of active battlers is 2. Wolf, Wolf, Slime, but Slime isn't dead would be 3.
Control Variables > Script: $game_troop.alive_members
will tell you how many of the enemy troop are still alive
Control Variables > Script: $game_party.alive_members
will tell you how many of your party's battlers (first 4) are alive if you run the command while in battle, or how many of your total party members are alive if you run the command outside of battle.
The above will put the number into the variable you choose. If you just want to use it in a conditional branch and not store it, just put $game_troop.alive_members >= whatever_number_you_want into the Script box of a Conditional Branch instead of using Control Variables.
Is $game_troop an array that can be accessed? The end goal is a "plague" state that "spreads" from enemy to enemy. Right now, I've created a loop that checks if an enemy has appeared, doesn't have the death state, and doesn't have the "plague" state.
So right now, it checks if Battler 1 has Plague state. Then, random # 1-8, checks a loop to see if the corresponding enemy has appeared, doesn't have death state, and doesn't have the Plague. If all that comes back true, it applies the Plague state to that enemy, and breaks loop. But, this has to currently be run for every single battler 1-8, and that's a TON of logic to run.
I'm wondering if I'm over-complicating this, or if I might be worrying too much about the stress of that logic on the average computer. I don't know how much more efficient scripting is vs. eventing for this kind of thing. Sorry for the lack of detail in the first post, at the time I was thinking along the lines of "get the number of active battlers, and then parse through them." But, with an array I could skip getting the number of active battlers.
I think so, anyway. I'm pretty dumb at this stuff.
Thank you, Shaz. You're, as always, a life saver. Or a plague-spreader, in this particular instance.
That'd have to be the most disturbing compliment I've ever received 😀
Did you try it? Did it work?
Yup! Just implemented it with great success. I'll probably use SceneManager.log_window.add_text to add some flavorful spin on it, like "Such and such's disease is spreading!", but that's for the future. Booting up a troop and watching this state just spread is.. it's just beautiful.
And you gave that to me! And to them! 🙂
Works beautifully. The final call ended up looking like this:
m = $game_troop.alive_members.select{|m| !m.state?(135)}.sample
if m
m.add_state(18)
SceneManager.scene.log_window.add_text(m.name + "'s Plague is spreading!")
SceneManager.scene.log_window.wait_and_clear
end
It plays wonderfully, works great, and is super flexible. At this point, the only thing I'm even curious about is how to change the text color. Normally, the \c[##] marker would do it, but this is scripting, so.. not sure. But anywho! That's off topic. Thank you again, Shaz 🙂
I don't know if you CAN change the log window text colour.
Also, you're looking for one state but adding a different one - I think there's another 18 that needs to be changed to 135 there (m.add_state).
And the other issue is that the message will show the enemy's name who is GETTING the state, not the one it's coming from. So if you had a rat and a slime, and the rat had the plague, on that turn the slime would get the plague, but the message would say Slime's Plague is spreading, rather than Rat's Plague is spreading. To fix that, you'd have to have a second variable that you put that member into (when you're looking to see if anyone has the state on the first line) and use that in the message, instead of the enemy you're adding the state to.