• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

[Scripting Question] Help with Emergency Exit?

6
Posts
7
Years
  • Age 35
  • Seen Dec 1, 2016
I'm not sure how to code "when hp drops from above 50% to below 50%". It activates whenever they take damage below 50% which isn't how it works,

I currently have:
Code:
      if target.hasWorkingAbility(:EMERGENCYEXIT) && target.hp<=(target.totalhp/2).floor && !target.damagestate.substitute
        if !target.isFainted? && @battle.pbCanChooseNonActive?(target.index) &&
         [email protected]?(@battle.pbParty(target.index))
          @battle.pbDisplay(_INTL("Golisopod's Emergency Exit activates!"))    
          @battle.pbDisplay(_INTL("Golisopod went back to {2}!",target.pbThis,@battle.pbGetOwner(target.index).name))
          @battle.pbClearChoices(target.index)
          newpoke=0
          [email protected](target.index,true,false)
          @battle.pbMessagesOnReplace(target.index,newpoke)
          @battle.pbRecallAndReplace(target.index,newpoke,true)
          target.pbResetForm
          @battle.pbOnActiveOne(target)
          target.pbAbilitiesOnSwitchIn(true)
        end
      end
 
Last edited by a moderator:

Adrenst

Adrenst
3
Posts
6
Years
  • Age 30
  • Seen Feb 8, 2018
So I'm pretty new to this, but this was the only thing that comes up when I google searching for this so I figured I'd toss my two cents in for anyone else who stumbles into it.

Also, before I go - I'm on v17.2 I'm working on getting gen 6&7 in my project now so not sure if this will work with v16 or what have you

After doing some testing I got this working, but I'm not sure if the PBEffects::Uturn is in previous versions, if not use something like he did above?

Where to put this: Script: PokeBattle_Move in def pbOnDamageLost (edited to handle wild battles too)
Code:
#berries -- moved here by Adrenst
    for j in 0...4
      @battle.battlers[j].pbBerryCureCheck(true)
    end
     # Emergency Exit -- Adrenst
    if opponent.hasWorkingAbility(:EMERGENCYEXIT) && opponent.hp<=(opponent.totalhp/2).floor && (opponent.hp+damage)>(opponent.totalhp/2) && !opponent.damagestate.substitute
      if !opponent.isFainted? && @battle.pbCanChooseNonActive?(opponent.index) &&
      [email protected]?(@battle.pbParty(opponent.index))
        if @battle.opponent
           @battle.pbDisplay(_INTL("{1}'s Emergency Exit activates!", opponent.pbThis)) 
          opponent.effects[PBEffects::Uturn]=true
        else
          @battle.pbRun(opponent.index);
        end
      end
    end

In pbRun in PokeBattle_Battle add this below the run away clause:
Code:
if thispkmn.hasWorkingAbility(:EMERGENCYEXIT) && thispkmn.hp<=(thispkmn.totalhp/2).floor && (thispkmn.hp+thispkmn.lastHPLost)>(thispkmn.totalhp/2) && !thispkmn.damagestate.substitute
      pbSEPlay("Battle flee")
      if duringBattle
        pbDisplayPaused(_INTL("{1}'s Emergency Exit triggered!",thispkmn.pbThis))
        pbDisplayPaused(_INTL("Got away safely!"))
      else
        pbDisplayPaused(_INTL("{1} escaped with Emergency Exit!",thispkmn.pbThis))
      end
      @decision=3
      return 1
    end

It's important to note I added in eating healing berries after taking damage. I'm not sure why that wasn't there to begin with but it needs to happen before the emergency exit code runs.
The three cases I tested were: falling below half health, falling below half health then eating berry and falling down again after, and under half hp and taking some damage.
 
Last edited:
Back
Top