RCXDan

Champion of Brightmoon Tor
Veteran
Joined
Jan 4, 2019
Messages
342
Reaction score
767
First Language
English
Primarily Uses
RMVXA
So a disclaimer: I'm not looking for something that changes the formula for escaping from combat like making it based on agility or something. I've already modified my escape to be always guaranteed.

Instead I'm looking for a script that makes it so you can't escape immediately until a turn count passes or a enemy HP threshold is reached.

This is not something for every fight in the game. It is important because I want to have encounters where you are forced to survive against unbeatable enemies that track you down, and weakening them or outlasting them frees up the Escape command.
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
6,625
Reaction score
8,605
First Language
Indonesian
Primarily Uses
RMVXA
I made a similar system in my game, so here is the quick snatch (and modified version) of it.
The quickest implementation would be like this
Ruby:
class << BattleManager
  def can_escape?
    @can_escape && escape_eval
  end
 
  def escape_eval
    return true if $game_system.escape_eval.nil?
    return eval($game_system.escape_eval)
  end
end

class Game_System
  attr_accessor :escape_eval
end

class Scene_Battle
 
  alias turn_end_aed_escape turn_end
  def turn_end
    turn_end_aed_escape
    unless $game_system.escape_eval.nil?
      @party_command_window.clear_command_list
      @party_command_window.make_command_list
      @party_command_window.refresh  
    end
  end
 
end
This works for turn-based battle. Because the ability to escape is refreshed per turn. For other turn systems, such as ATB, I'm not sure how it behaves.

How to use:
Use script call before the battle started.

Turn-based escape condition
Ruby:
$game_system.escape_eval = "$game_troop.turn_count >= 10"

HP-based condition (replace the enemy index)
Ruby:
$game_system.escape_eval = "$game_troop.members[enemy_index].hp_rate <= 0.5"

If you want to disable the escape condition, make sure to revert back to nil
Ruby:
$game_system.escape_eval = nil

Of course, I haven't tested this yet. So, please do me a favor.

On an unrelated note, this could be good for another of my random MZ plugins, now that I think about it.
 

RCXDan

Champion of Brightmoon Tor
Veteran
Joined
Jan 4, 2019
Messages
342
Reaction score
767
First Language
English
Primarily Uses
RMVXA
@TheoAllen So it works! But testing revealed some things:

#1: Once a condition is set, it is like that for every fight in the game. Like Fight A will set the condition with the script, and once escaped and you leave to initiate Fight B, the same condition will apply even when I haven't applied the script there.

#2: The HP threshold version works with Yanfly Instant Cast moves, as using a move that does enough damage to a tagged enemy without taking up a turn allows you to escape by un-graying the escape function.

Something interesting would be adding a visible turn count near Escape like "Escape [x]T" with x representing the amount of turns needed.

Does this also allow And operands to be used? Like "enemy A && enemy B hp threshold >= 0.9" - that kind of thing.
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
6,625
Reaction score
8,605
First Language
Indonesian
Primarily Uses
RMVXA
#1: Once a condition is set, it is like that for every fight in the game. Like Fight A will set the condition with the script, and once escaped and you leave to initiate Fight B, the same condition will apply even when I haven't applied the script there.
This is why I said, you have to disable it manually by using script call
Ruby:
$game_system.escape_eval = nil
Or else, it would affect all other battles.

Something interesting would be adding a visible turn count near Escape like "Escape [x]T" with x representing the amount of turns needed.
Since I wrote this for various cases as possible (not just specific for turn condition), this is what I came up with
Ruby:
class << BattleManager
  def can_escape?
    @can_escape && escape_eval
  end
 
  def escape_eval
    return true if $game_system.escape_eval.nil?
    return eval($game_system.escape_eval)
  end
end

class << Vocab
  alias escape_origin escape
  def escape
    return $game_system.get_escape_text
  end
end

class Game_System
  attr_accessor :escape_eval
  attr_accessor :escape_text
 
  def get_escape_text
    return Vocab::escape_origin unless escape_text
    return escape_text.gsub(/\{(.+)\}/i) { eval($1.to_s) }
  end
 
end

class Scene_Battle
 
  alias turn_end_aed_escape turn_end
  def turn_end
    turn_end_aed_escape
    unless $game_system.escape_eval.nil?
      @party_command_window.clear_command_list
      @party_command_window.make_command_list
      @party_command_window.refresh 
    end
  end
 
end

How to use:
To print whatever escape text you want, use script call
Ruby:
$game_system.escape_text = "Escape {ruby code here}"

In your case, specifically, it should look like
Ruby:
$game_system.escape_text = "Escape [{10 - $game_troop.turn_count}]T"

Although, if the turn count is over 10, it would draw a negative value, thus this would be better.
Ruby:
$game_system.escape_text = "Escape {t = 10 - $game_troop.turn_count; t > 0 ? \"[\" + t.to_s + \"]T\" : \"\"} }"

Yes, unfortunately, you have to have ruby coding knowledge to use.

Similar to the escape condition, you have to set it to nil to disable it.
Ruby:
$game_system.escape_text = nil

Does this also allow And operands to be used? Like "enemy A && enemy B hp threshold >= 0.9" - that kind of thing.
Yes, you can. The condition would be a bit longer like.
Ruby:
$game_system.escape_eval = "$game_troop.members[index_1].hp_rate >= 0.9 && $game_troop.members[index_2].hp_rate >= 9"
 
Last edited:

RCXDan

Champion of Brightmoon Tor
Veteran
Joined
Jan 4, 2019
Messages
342
Reaction score
767
First Language
English
Primarily Uses
RMVXA
This is why I said, you have to disable it manually by using script call
Ruby:
$game_system.escape_eval = nil
Or else, it would affect all other battles.


Since I wrote this for various cases as possible (not just specific for turn condition), this is what I came up with
Ruby:
class << BattleManager
  def can_escape?
    @can_escape && escape_eval
  end
 
  def escape_eval
    return true if $game_system.escape_eval.nil?
    return eval($game_system.escape_eval)
  end
end

class << Vocab
  alias escape_origin escape
  def escape
    return $game_system.get_escape_text
  end
end

class Game_System
  attr_accessor :escape_eval
  attr_accessor :escape_text
 
  def get_escape_text
    return Vocab::escape_origin unless escape_text
    return escape_text.gsub(/\{(.+)\}/i) { eval($1.to_s) }
  end
 
end

class Scene_Battle
 
  alias turn_end_aed_escape turn_end
  def turn_end
    turn_end_aed_escape
    unless $game_system.escape_eval.nil?
      @party_command_window.clear_command_list
      @party_command_window.make_command_list
      @party_command_window.refresh
    end
  end
 
end

How to use:
To print whatever escape text you want, use script call
Ruby:
$game_system.escape_text = "Escape {ruby code here}"

In your case, specifically, it should look like
Ruby:
$game_system.escape_text = "Escape [{10 - $game_troop.turn_count}]T"

Although, if the turn count is over 10, it would draw a negative value, thus this would be better.
Ruby:
$game_system.escape_text = "Escape {t = 10 - $game_troop.turn_count; t > 0 ? \"[\" + t.to_s + \"]T\" : \"\"} }"

Yes, unfortunately, you have to have ruby coding knowledge to use.

Similar to the escape condition, you have to set it to nil to disable it.
Ruby:
$game_system.escape_text = nil


Yes, you can. The condition would be a bit longer like.
Ruby:
$game_system.escape_eval = "$game_troop.members[index_1].hp_rate >= 0.9 && $game_troop.members[index_2].hp_rate >= 9"

Oh wow. Thanks @TheoAllen , I can see many uses for this.

I've tested it in different scenarios enough to justify saying that it does pretty much what I want. :LZScheeze:
 
Last edited:

Latest Threads

Latest Posts

Latest Profile Posts

Awright ya marshmallows! :kaopride: Here's a peek of what Alice's 8-bit Gothic gonna be like! EXPECT IT! (...in 2025?) :kaoswt:

alice_gothictiles.png
SF_People3_4 added!
index.php

Finds notes for an old side project... Oh, that's right, the two tracks that sounded really cool and gave inspiration for the big bad in that game... Spends day working on cutscene from old notes, looks okay, now lets slot in the first track... um... I did have those tracks??? It was a year or so ago but I did buy them didn't I?
CA9mtHJ.gif

Everything is really confusing for me

Forum statistics

Threads
118,590
Messages
1,117,156
Members
155,658
Latest member
CarloFourQuattro
Top