Win Battle if All Enemies Have State?

I say it everytime "Hopefully this will be simple enough" and it never is, lol. Let's see if today's any different!

My game has a character with the ability to calm and tame animals and what I want is a way for the player to win a battle if the animal tamer calms the enemies down rather than killing them. They do this by afflicting them with a 'Soothed' status, which makes the enemy unable to act for a while (but is removed by damage, so you have to commit to the non-violent approach). Some enemies naturally will be easier to calm than others.

In-game design terms: I want the game to treat Soothed in a similar manner to how Final Fantasy treats Petrify, in that it counts as death if the entire troop is affected.

I thought all I would have to do is edit this in BattleManager:
Code:
  #--------------------------------------------------------------------------
  # * Determine Win/Loss Results
  #--------------------------------------------------------------------------
  def self.judge_win_loss
    if @phase
      return process_abort   if $game_party.members.empty?
      return process_defeat  if $game_party.all_dead?
      return process_victory if $game_troop.all_dead?
      return process_abort   if aborting?
    end
    return false
  end

And change it to this:
Code:
  #--------------------------------------------------------------------------
  # * Determine Win/Loss Results
  #--------------------------------------------------------------------------
  def self.judge_win_loss
    if @phase
      return process_abort   if $game_party.members.empty?
      return process_defeat  if $game_party.all_dead?
      return process_victory if $game_troop.all_dead?
      return process_victory if $game_troop.all_stateaffected(42)?
      return process_abort   if aborting?
    end
    return false
  end
However this resulted in an error stating that the 'aborting' line was missing a colon, which makes no sense because it's not like there was one there already :S I tried moving my new line BELOW aborting but that resutled in a 'expected 'end'' error. Am I simply placing this in the wrong order? Did I write the line wrong (should I remove the word 'all_' or something)?

I would really rather not make this a battle event that I have to copy to every troop, plus there would be no way to earn gold and experience if I did it that way.

Hopefully this is simple T_T I'm so exhausted from trying to fix stuff that should take 5 minutes but takes a whole day instead.
Code:
return process_victory if $game_troop.all_stateaffected(42)?
You put the question mark after ()
Assume you really have that method in Game_Troop
Oh I assumed the ? had to be the last thing in the line. So it's "stateaffected?(42)" at the end instead?

And I need to edit something in Game_Troop too? I'm completely alien to script editing so I've no idea where to look or what I need to change, and what to change it to.
You can't just assume a method exists and write it right away. Like, why do you assume the method all_stateaffected() exist?
Code:
  #--------------------------------------------------------------------------
  # * Determine Win/Loss Results
  #--------------------------------------------------------------------------
  def self.judge_win_loss
   if @phase
     return process_abort   if $game_party.members.empty?
     return process_defeat  if $game_party.all_dead?
     return process_victory if $game_troop.all_dead?
     return process_victory if $game_troop.members.all? (|m| m.state?(42))
     return process_abort   if aborting?
   end
   return false
  end
Try this instead.
I haven't heard the term method before and I thought maybe RPG Maker had in-built recognition for certain kinds of statements and I thought I'd seen terminology like 'if stateaffected' before within parts of the default scripts and my faulty logic assumed I could just write the same line elsewhere and it'd work :blush: This is why I don't play with scripts normally and prefer to use ones that others have already written. I originally wanted to use Hime's Alternate Death Conditions script which lets you tag states as death-like but sadly it's for MV only 🙁

I pasted your code in and received this upon trying to open the game:
"Script 'BattleManager line 195: SyntaxError occurred.
unexpected '|'
... if $game_troop.members.all? (|m| m.state?(42))"

Was I supposed to replace any of that with something else?
Ah, it's supposed to be {}
Code:
... if $game_troop.members.all? {|m| m.state?(42)}
This is why u shouldn't code after u wake up.
Haha I'm just glad it wasn't me dude. I was like "Ok, all I did was copy and paste... HOW did I even mess THAT up?" 🤣 Knowing me it wouldn't have surprised me if I had.

I just tested it out in battle and it worked flawlessly! 🙂 Thank you so much! And I'm sorry I'm such a dunce. I hate wasting people's time because I'm too stupid to 'get it'.

A thought occured to me that if the player wasn't keeping track of their state-afflictions, they might not realize WHY they won the battle. How difficult would it be for a message to pop on screen before the victory screen rolls, saying something like "the enemy troop was subdued" or something? If it'd be too complicated then I wouldn't bother with it and just let the player work it out, lol. I tend to overthink things like this and worry "oh what if they're mad at me for not making it clearer" lol
..... Er, I think you better consider mix and match. Your code assumes two things:
1) It runs Victory if 'ALL the enemies are dead' or
2) It runs Victory if 'ALL the enemies are under state 42'

You're not considering that some are dead and some are under state 42.

Oh, hey Theo! Long time no text. ☺️
@DerVVulfman lol you're right. And hello there!

@Psykai maybe you better to consider those point above.
Oh, err, I didn't think about that. Sounds ..................... tricky. How would I make that work? Without tearing even more of my hair out, I mean ... 🤣
Er...

Code:
  #--------------------------------------------------------------------------
  # * Determine Win/Loss Results
  #--------------------------------------------------------------------------
  def self.judge_win_loss
   if @phase
    heroes_won = true
    for member in  $game_troop.members
      heroes_won = false unless member.dead? or member.state?(42)
    end
    return process_abort   if $game_party.members.empty?
    return process_defeat  if $game_party.all_dead?
    return process_victory if heroes_won
    return process_abort   if aborting?
   end
   return false
  end

Mebby this?
Code:
  #--------------------------------------------------------------------------
  # * Determine Win/Loss Results
  #--------------------------------------------------------------------------
  def self.judge_win_loss
   if @phase
    return process_abort   if $game_party.members.empty?
    return process_defeat  if $game_party.all_dead?
    return process_victory if $game_troop.members.all? (|m| m.dead? || m.state?(42))
    return process_abort   if aborting?
   end
   return false
  end
Thanks guys 🙂

Copied Theo's script in and after changing the () to {} again it worked 🙂 Did a test battle, killed two of the enemies, soothed the last one and the battle ended fine 🙂

Original thread: https://forums.rpgmakerweb.com/threads/win-battle-if-all-enemies-have-state.102726/