Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Always Escape

Hey there, all...

I'm trying to set up a script or do an edit which enables the party to always escape from battle, 100% chance irregardless of AGI, unless the "Escape Allowed" option is set to off, of course.

Had no luck so far... anybody can help out?

Alternatively, a script that sets a hard % chance to Escape would also do.

Thanks,
 
M'kay, I have a pretty good understand of how this works. The escape possibility is Scene_Battle 2 and goes from line 84 to line 129. Since you posted this in Script Support, I'm going to explain to you how it works. Here's the section, singled out:
Code:
#==============================================================================

# ** Scene_Battle (part 2)

#------------------------------------------------------------------------------

#  This class performs battle screen processing.

#==============================================================================

 

class Scene_Battle

  def update_phase2_escape

    # Calculate enemy agility average

    enemies_agi = 0

    enemies_number = 0

    for enemy in $game_troop.enemies

      if enemy.exist?

        enemies_agi += enemy.agi

        enemies_number += 1

      end

    end

    if enemies_number > 0

      enemies_agi /= enemies_number

    end

    # Calculate actor agility average

    actors_agi = 0

    actors_number = 0

    for actor in $game_party.actors

      if actor.exist?

        actors_agi += actor.agi

        actors_number += 1

      end

    end

    if actors_number > 0

      actors_agi /= actors_number

    end

    # Determine if escape is successful

    success = rand(100) < 50 * actors_agi / enemies_agi

    # If escape is successful

    if success

      # Play escape SE

      $game_system.se_play($data_system.escape_se)

      # Return to BGM before battle started

      $game_system.bgm_play($game_temp.map_bgm)

      # Battle ends

      battle_end(1)

    # If escape is failure

    else

      # Clear all party member actions

      $game_party.clear_actions

      # Start main phase

      start_phase4

    end

  end

end

It's a little confusing to look at when you first see it, so I'll break it down into pieces.

Code:
    # Calculate enemy agility average

    enemies_agi = 0

    enemies_number = 0

    for enemy in $game_troop.enemies

      if enemy.exist?

        enemies_agi += enemy.agi

        enemies_number += 1

      end

    end

    if enemies_number > 0

      enemies_agi /= enemies_number

    end

 
First, it sets the values for enemies_agi and enemies_number to 0 (basically resetting it). Then it finds all of the enemies and adds their agility to the enemies_agi value and then adds 1 to the enemies_number value. Then if there are more than one enemy, it divides enemies_agi by that number. Basically, it's finding the average. It does the same for actors in the next section.

This is the part we should really focus on:
Code:
    # Determine if escape is successful

    success = rand(100) < 50 * actors_agi / enemies_agi

    # If escape is successful

    if success

      # Play escape SE

      $game_system.se_play($data_system.escape_se)

      # Return to BGM before battle started

      $game_system.bgm_play($game_temp.map_bgm)

      # Battle ends

      battle_end(1)

    # If escape is failure

    else

      # Clear all party member actions

      $game_party.clear_actions

      # Start main phase

      start_phase4

    end

 

success = rand(100) < 50 * actors_agi / enemies_agi

^ That line decides the success of an escape. It takes a random number between 1 and 100, then checks if it's less than 50 multiplied by the actors_agi divide by enemies_agi. Let's give values to these to make it easier.

actors_agi = 10
enemies_agi = 20

So that would be 50 * 10/20 -> 50 * .5 -> 25

Therefore, the random value has to be less than 25 to make the escape successful. Let's switch that around.

actors_agi = 20
enemies_agi = 10

50 * 20/10 -> 50 * 2 -> 100

So now it would have to be less than 100 for it to succeed. That's to help you see how this whole operation works.



First of all, with something like this, I suggest re-defining stuff as a new script instead of editing the defaults. It gives you more freedom and you can more easily play around with values and such. Something like what I singled out at the top is what you could paste above "Main" to work with it.

Here's a few things you can do:

1. If you want escape to always happen, take out all of the calculations and make it so only the success results is in that definition. EX:
Code:
#==============================================================================

# ** Scene_Battle (part 2)

#------------------------------------------------------------------------------

#  This class performs battle screen processing.

#==============================================================================

 

class Scene_Battle

  def update_phase2_escape

      # Play escape SE

      $game_system.se_play($data_system.escape_se)

      # Return to BGM before battle started

      $game_system.bgm_play($game_temp.map_bgm)

      # Battle ends

      battle_end(1)

   end

end
This guarantees you'll be able to escape no matter what because it isn't making any of the calculations.

2. Edit the values of the operation. For example, you could decrease the chance of success by making rand(100) into rand(125), which would give you 25 more possibilities of it being too high to succeed.

3. Both of these will edit the rate throughout your game. If you want to have it happen only at certain times or if you want to be able to change it on-the-go, you should make a post in Script Requests (and you could probably link back to this for reference). Making a script like this is beyond my abilities, unfortunately.


I hope I was helpful. Let me know if I need to make something more clear. :thumb:
 
Wow, Guardian... you just blew my mind, man. That's exactly what I needed. Solution 1 and 2 are both good options, but in case this turns out to unbalance the game too much in beta testing, I will be sure to find somebody to help code a flexible script.

Thank you! :)
 

Zeriab

Sponsor

Here's a quick hack which should allowed you to turn always escape on by turning Switch 42 ON.
You can the 42 in $game_switches[42] to any number you like. For example $game_switches[103]. (No leading zeros, i.e. 5 good 0005 bad)

[rgss]#==============================================================================
# ** Scene_Battle (part 2)
#------------------------------------------------------------------------------
#  This class performs battle screen processing.
#==============================================================================
 
class Scene_Battle
  unless method_defined?("always_escape_update_phase2_escape")
    alias_method :always_escape_update_phase2_escape, :update_phase2_escape
  end
  def update_phase2_escape
      return always_escape_update_phase2_escape unless $game_switches[42]
      # Play escape SE
      $game_system.se_play($data_system.escape_se)
      # Return to BGM before battle started
      $game_system.bgm_play($game_temp.map_bgm)
      # Battle ends
      battle_end(1)
   end
end
[/rgss]

I haven't tested it, but I hope it'll work

*hugs*
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top