• Just a reminder that providing specifics on, sharing links to, or naming websites where ROMs can be accessed is against the rules. If your post has any of this information it will be removed.
  • Our friends from the Johto Times are hosting a favorite Pokémon poll - and we'd love for you to participate! Click here for information on how to vote for your favorites!
  • Cyndy, May, Hero (Conquest), or Wes - which Pokémon protagonist is your favorite? Let us know by voting in our poll!
  • 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] Surrender Script [help/question]

  • 32
    Posts
    7
    Years
    • Seen Sep 9, 2019
    after playing around with pokemon essentials for a week I've decided to register here, after seeing how collaborative and helpful this community is
    .. okay so straight to the point;

    as i've said i'm new, so i have no experience with PkmnE 's code language.
    ive been handling pretty okay/good, with trial/error and tinkering.
    though right now im having trouble with the following, the option to surrender a trainer battle (almost necessary for this game)

    my idea was trying to locate the script that the debug mode uses for it and work with that, but i havnt been able to locate it.

    i know i should ve gone pretty simple and generic for my first pkmn fangame, but again ive been able to work my way arround a lot of the issues i thought were gonna be a problem.

    so, anyone knows where i can find said debug code inside PE?
    .. or anyone knows another way i can aproach this?
     
    Firstly, Pokemon Essentials uses the scripting language Ruby, (because that's what RMXP uses).
    And the Debug code you are looking for is in def pbRun in Script Section PokeBattle_Battle on line 1567 on a clean version of v17.2, the latest one.
    The stuff for a trainer battle is in lines 1576 to 1594.
    Code:
        if @opponent
          if $DEBUG && Input.press?(Input::CTRL)
            if pbDisplayConfirm(_INTL("Treat this battle as a win?"))
              @decision=1
              return 1
            elsif pbDisplayConfirm(_INTL("Treat this battle as a loss?"))
              @decision=2
              return 1
            end
          elsif @internalbattle
            pbDisplayPaused(_INTL("No! There's no running from a Trainer battle!"))
          elsif pbDisplayConfirm(_INTL("Would you like to forfeit the match and quit now?"))
            pbSEPlay("Battle flee")
            pbDisplay(_INTL("{1} forfeited the match!",self.pbPlayer.name))
            @decision=3
            return 1
          end
          return 0
        end
    I'm going to leave this with you. Try to make an attempt at what you think would work, and if it just doesn't pan out, feel free to reply to ask for help.
    Have fun!
    Quote to get your attention, because I got quoted by you (Asking for help I think, but I only saw a bit) but the forum swallowed the post wholesale
    I just changed the above code I posted to this.
    Code:
        if @opponent
          if pbDisplayConfirm(_INTL("Would you like to forfeit the match and quit now?"))
            pbSEPlay("Battle flee")
            pbDisplay(_INTL("{1} forfeited the match!",self.pbPlayer.name))
            @decision=2
            return 1
          end
          return 0
        end
    This makes the player forfeit, but also triggers the loss money payment/pokecenter cutscene (Because using the regular forfeit battle ending got me in an infinite loop of battle with regular trainers.)
    If this isn't close enough, I can try to look deeper and get closer to what you wanted.
     
    Last edited:
    Firstly, Pokemon Essentials uses the scripting language Ruby, (because that's what RMXP uses).
    And the Debug code you are looking for is in def pbRun in Script Section PokeBattle_Battle on line 1567 on a clean version of v17.2, the latest one.
    The stuff for a trainer battle is in lines 1576 to 1594.
    Code:
        if @opponent
          if $DEBUG && Input.press?(Input::CTRL)
            if pbDisplayConfirm(_INTL("Treat this battle as a win?"))
              @decision=1
              return 1
            elsif pbDisplayConfirm(_INTL("Treat this battle as a loss?"))
              @decision=2
              return 1
            end
          elsif @internalbattle
            pbDisplayPaused(_INTL("No! There's no running from a Trainer battle!"))
          elsif pbDisplayConfirm(_INTL("Would you like to forfeit the match and quit now?"))
            pbSEPlay("Battle flee")
            pbDisplay(_INTL("{1} forfeited the match!",self.pbPlayer.name))
            @decision=3
            return 1
          end
          return 0
        end
    I'm going to leave this with you. Try to make an attempt at what you think would work, and if it just doesn't pan out, feel free to reply to ask for help.
    Have fun!

    thank you very much!
    although i still need to tinker with it to make it fit my purposes, i was able to inject it and make it run, so that's a good start .. hopefully i can get it to work.

    again, thank : )
     
    why thank you, how nice of you!
    (the quote was mainly thanking you tho)

    .. I was gonna try to figure it out myself, but i guess since you ask i can at least let you know exactly what im going for;

    since i'm gonna be implementing pokemon death (ive already looked into it), the logic behind the surrender option is so that you can save some of your pokemon if the battle is going to hell.
    the idea then would be upon surrendering, you loose money and the battle ends with the player on the same area (no pokecenter) and leaving pkmn with the damage they sustained (just like wild battles).

    ..somethign along those lines.
     
    I just changed the above code I posted to this.
    Code:
        if @opponent
          if pbDisplayConfirm(_INTL("Would you like to forfeit the match and quit now?"))
            pbSEPlay("Battle flee")
            pbDisplay(_INTL("{1} forfeited the match!",self.pbPlayer.name))
            @decision=2
            return 1
          end
          return 0
        end
    This makes the player forfeit, but also triggers the loss money payment/pokecenter cutscene (Because using the regular forfeit battle ending got me in an infinite loop of battle with regular trainers.)
    If this isn't close enough, I can try to look deeper and get closer to what you wanted.

    btw i actually didnt run to this problem .. i used what you first gave me and surrendering trigger'd
    money payment/pokecenter :V
     
    Okay, watch carefully because there are quite a few changes in a number of sections! BTW this does the forfeit gives money, makes opponent say win ending speech, leave the player on the field, but you can't rebattle them.

    Okay, in PokeBattle_Battle, in def pbRun replace this
    Code:
        if @opponent
          if $DEBUG && Input.press?(Input::CTRL)
            if pbDisplayConfirm(_INTL("Treat this battle as a win?"))
              @decision=1
              return 1
            elsif pbDisplayConfirm(_INTL("Treat this battle as a loss?"))
              @decision=2
              return 1
            end
          elsif @internalbattle
            pbDisplayPaused(_INTL("No! There's no running from a Trainer battle!"))
          elsif pbDisplayConfirm(_INTL("Would you like to forfeit the match and quit now?"))
            pbSEPlay("Battle flee")
            pbDisplay(_INTL("{1} forfeited the match!",self.pbPlayer.name))
            @decision=3
            return 1
          end
          return 0
        end
    with this
    Code:
        if @opponent
          if pbDisplayConfirm(_INTL("Would you like to forfeit the match and quit now?"))
            pbSEPlay("Battle flee")
            pbDisplay(_INTL("{1} forfeited the match!",self.pbPlayer.name))
            @decision=3
            return 1
          end
          return 0
        end

    also, in def pbEndOfBattle, above the end above this comment: # Pass on Pokérus within the party, add
    Code:
        ##### FORFEIT (Lose money, battle ends, don't move on map) #####
        when 3
          PBDebug.log("")
          PBDebug.log("***Player forfeit***")
          if @internalbattle
            moneylost=pbMaxLevelFromIndex(0)   # Player's Pokémon only, not partner's
            multiplier=[8,16,24,36,48,64,80,100,120]
            moneylost*=multiplier[[multiplier.length-1,self.pbPlayer.numbadges].min]
            moneylost=self.pbPlayer.money if moneylost>self.pbPlayer.money
            moneylost=0 if $game_switches[NO_MONEY_LOSS]
            oldmoney=self.pbPlayer.money
            self.pbPlayer.money-=moneylost
            lostmoney=oldmoney-self.pbPlayer.money
            if @opponent
              if @opponent.is_a?(Array)
                pbDisplayPaused(_INTL("You forfeited to {1} and {2}!",@opponent[0].fullname,@opponent[1].fullname))
              else
                pbDisplayPaused(_INTL("You forfeited to\r\n{1}!",@opponent.fullname))
              end
              if moneylost>0
                pbDisplayPaused(_INTL("You gave ${1} to the winner...",pbCommaNumber(lostmoney)))  
              end
              if @endspeechwin
                @scene.pbShowOpponent(0)
                pbDisplayPaused(@endspeechwin.gsub(/\\[Pp][Nn]/,self.pbPlayer.name))
                if @opponent.is_a?(Array)
                  @scene.pbHideOpponent
                  @scene.pbShowOpponent(1)
                  pbDisplayPaused(@endspeechwin2.gsub(/\\[Pp][Nn]/,self.pbPlayer.name))
                end
              end
            end
          end
    Finally, in PField_Battles, in both def pbTrainerBattle and def pbDoubleTrainerBattle, replace
    Code:
    return (decision==1)
    with
    Code:
    return (decision==1 || decision==3)

    It works for me, I can't rebattle them though, but no infinite loops and no healing!
     
    wow, you really went above and beyond.
    srsly, i feel like your initial reply would've been enough.
    can't thank you enough (other than crediting you of course)

    it works btw.
    only problem is that surrendering to gym leader and gym trainers (also poke league) treats it like a win
    ... but this is good enought, im sure i can eventually tinker it into working

    again, thanks!
     
    Last edited:
    Store the outcome of the battle in a variable and check if it's a win (variable==1) or forfeit (variable==3)

    okay tho one more thing, im just looking for a hint.
    youve helped so much already, i'd feel kinda bad if you did it for me;

    this can totally be a noob mistake but , is this doable via event?
    .. since global variable 42 is the outcome one i can do a conditional thingy, right?

    .. or this is a scrip only thing?

    i ask cuz ive been trying to mess with the trainer events but with no results
    ..again, could be a noob mistake on my part.
     
    okay tho one more thing, im just looking for a hint.
    youve helped so much already, i'd feel kinda bad if you did it for me;

    this can totally be a noob mistake but , is this doable via event?
    .. since global variable 42 is the outcome one i can do a conditional thingy, right?

    .. or this is a scrip only thing?

    i ask cuz ive been trying to mess with the trainer events but with no results
    ..again, could be a noob mistake on my part.

    This is one hundred percent a conditional event thing.
    something like this would work:
    [PokeCommunity.com] Surrender Script [help/question]

    You only get the badge if you won.
     
    This is one hundred percent a conditional event thing.
    something like this would work:
    [PokeCommunity.com] Surrender Script [help/question]

    You only get the badge if you won.

    okay i suck .. now im just testing your patience (I tried doing both of the things listed below btw )

    ---------------------------
    Pokemon Essentials
    ---------------------------
    [Pokémon Essentials version 17.2]

    Exception: RuntimeError

    Message: Script error within event 3 (coords 6,5), map 10 (Cedolan Gym):

    Exception: SyntaxError

    Message: (eval):3:in `pbExecuteScript'compile error
    (eval):3: syntax error
    ("Very good."),false 0,false,42)
    ^
    (eval):3: syntax error
    ("Very good."),false 0,false,42)
    ^

    ***Line '("Very good."),false 0,false,42)' shouldn't begin with '('. Try

    putting the '(' at the end of the previous line instead,

    or using 'extendtext.exe'.

    ***Full script:

    pbTrainerBattle(
    PBTrainers::LEADER_Brock,"Brock",_I
    ("Very good."),false 0,false,42)




    Interpreter:276:in `pbExecuteScript'

    Interpreter:1606:in `command_355'

    Interpreter:494:in `execute_command'

    Interpreter:193:in `update'

    Interpreter:106:in `loop'

    Interpreter:198:in `update'

    Scene_Map:163:in `update'

    Scene_Map:161:in `loop'

    Scene_Map:170:in `update'

    Scene_Map:234:in `main'



    :V
     
    ..at least i know it can be done with events
    i just gotta make it work then
     
    So just checking, you did do this with extendtext.exe, yeah
    [PokeCommunity.com] Surrender Script [help/question]

    Otherwise, you've got to do it like this (but please try doing it with extendtext, this is annoying)
    [PokeCommunity.com] Surrender Script [help/question]

    yes i did. ALSO it worked now
    there was a typo on the first img you gave me (that's on me for not knowing my stuff tho)

    yeah, we were missing a "," before false,0

    dude you've been so helpfull! like we say over here; i should build you a monument xD
     
    Okay, watch carefully because there are quite a few changes in a number of sections! BTW this does the forfeit gives money, makes opponent say win ending speech, leave the player on the field, but you can't rebattle them.

    anyway i just wanted to let you know that i think ive made it work (unless im missing something)
    for auto battles im just using regular battles and letting an 1 time stepable event handle it.
    thanks again, i think this might be it!
     
    anyway i just wanted to let you know that i think ive made it work (unless im missing something)
    for auto battles im just using regular battles and letting an 1 time stepable event handle it.
    thanks again, i think this might be it!

    i guess the only thing im still curious about, is if this part of the code
    "pbDisplayPaused(_INTL("No! There's no running from a Trainer battle!"))"
    can still be put back in but have it come up if the npc is a particular type, team rocket for example
    .. it kinda sounds logical, but what the heck do i know

    as contingency im probably gonna have it where fleeing from team rocket battles makes it so that they take one of your pokemon or something, an easy event
     
    i guess the only thing im still curious about, is if this part of the code
    "pbDisplayPaused(_INTL("No! There's no running from a Trainer battle!"))"
    can still be put back in but have it come up if the npc is a particular type, team rocket for example
    .. it kinda sounds logical, but what the heck do i know

    as contingency im probably gonna have it where fleeing from team rocket battles makes it so that they take one of your pokemon or something, an easy event

    hey sorry for the wait, I don't always have access to RMXP.
    change this
    Code:
        if @opponent
          if pbDisplayConfirm(_INTL("Would you like to forfeit the match and quit now?"))
            pbSEPlay("Battle flee")
            pbDisplay(_INTL("{1} forfeited the match!",self.pbPlayer.name))
            @decision=3
            return 1
          end
          return 0
        end
    to
    Code:
        if @opponent
          banrun=[getID(PBTrainers,:TEAMROCKET_M),
                  getID(PBTrainers,:TEAMROCKET_F),
                  getID(PBTrainers,:ROCKETBOSS)]
          if $DEBUG && Input.press?(Input::CTRL)
            if pbDisplayConfirm(_INTL("Treat this battle as a win?"))
              @decision=1
              return 1
            elsif pbDisplayConfirm(_INTL("Treat this battle as a loss?"))
              @decision=2
              return 1
            end
          elsif !banrun.include(pbGetOwner(1).trainertype) && 
              pbDisplayConfirm(_INTL("Would you like to forfeit the match and quit now?"))
            pbSEPlay("Battle flee")
            pbDisplay(_INTL("{1} forfeited the match!",self.pbPlayer.name))
            @decision=3
            return 1
          else
            pbDisplayPaused(_INTL("No! You can't forfeit to these guys!"))
          end
          return 0
        end
    So, if the owner of the first pokemon on the opposing side is a Team Rocket member (or Boss), you can't forfeit.
    This did require adding back in the ability to debug exit a battle.
    To add more, you can just add more trainertypes to the array banrun. Just do the same thing I did.
    And yes, it works, I tested it.
     
    hey sorry for the wait, I don't always have access to RMXP.
    change this
    Code:
        if @opponent
          if pbDisplayConfirm(_INTL("Would you like to forfeit the match and quit now?"))
            pbSEPlay("Battle flee")
            pbDisplay(_INTL("{1} forfeited the match!",self.pbPlayer.name))
            @decision=3
            return 1
          end
          return 0
        end
    to
    Code:
        if @opponent
          banrun=[getID(PBTrainers,:TEAMROCKET_M),
                  getID(PBTrainers,:TEAMROCKET_F),
                  getID(PBTrainers,:ROCKETBOSS)]
          if $DEBUG && Input.press?(Input::CTRL)
            if pbDisplayConfirm(_INTL("Treat this battle as a win?"))
              @decision=1
              return 1
            elsif pbDisplayConfirm(_INTL("Treat this battle as a loss?"))
              @decision=2
              return 1
            end
          elsif !banrun.include(pbGetOwner(1).trainertype) && 
              pbDisplayConfirm(_INTL("Would you like to forfeit the match and quit now?"))
            pbSEPlay("Battle flee")
            pbDisplay(_INTL("{1} forfeited the match!",self.pbPlayer.name))
            @decision=3
            return 1
          else
            pbDisplayPaused(_INTL("No! You can't forfeit to these guys!"))
          end
          return 0
        end
    So, if the owner of the first pokemon on the opposing side is a Team Rocket member (or Boss), you can't forfeit.
    This did require adding back in the ability to debug exit a battle.
    To add more, you can just add more trainertypes to the array banrun. Just do the same thing I did.
    And yes, it works, I tested it.

    yo, don't even apologize. you are being way to helpfull and going above and beyond
    srsly thank you, i'll try it as soon as i get a chance.
     
    hey sorry for the wait, I don't always have access to RMXP.
    change this
    Code:
        if @opponent
          if pbDisplayConfirm(_INTL("Would you like to forfeit the match and quit now?"))
            pbSEPlay("Battle flee")
            pbDisplay(_INTL("{1} forfeited the match!",self.pbPlayer.name))
            @decision=3
            return 1
          end
          return 0
        end
    to
    Code:
        if @opponent
          banrun=[getID(PBTrainers,:TEAMROCKET_M),
                  getID(PBTrainers,:TEAMROCKET_F),
                  getID(PBTrainers,:ROCKETBOSS)]
          if $DEBUG && Input.press?(Input::CTRL)
            if pbDisplayConfirm(_INTL("Treat this battle as a win?"))
              @decision=1
              return 1
            elsif pbDisplayConfirm(_INTL("Treat this battle as a loss?"))
              @decision=2
              return 1
            end
          elsif !banrun.include(pbGetOwner(1).trainertype) && 
              pbDisplayConfirm(_INTL("Would you like to forfeit the match and quit now?"))
            pbSEPlay("Battle flee")
            pbDisplay(_INTL("{1} forfeited the match!",self.pbPlayer.name))
            @decision=3
            return 1
          else
            pbDisplayPaused(_INTL("No! You can't forfeit to these guys!"))
          end
          return 0
        end
    So, if the owner of the first pokemon on the opposing side is a Team Rocket member (or Boss), you can't forfeit.
    This did require adding back in the ability to debug exit a battle.
    To add more, you can just add more trainertypes to the array banrun. Just do the same thing I did.
    And yes, it works, I tested it.

    ---------------------------
    Pokemon Essentials
    ---------------------------
    [Pokémon Essentials version 17.2]

    Exception: NoMethodError

    Message: undefined method `include' for [56, 57, 58]:Array

    PokeBattle_Battle:1606:in `pbRun_ebs'

    EliteBattle_0:287:in `pbRun'

    PokeBattle_Battle:2696:in `pbCommandPhase_ebs'

    PokeBattle_Battle:2640:in `loop'

    PokeBattle_Battle:2730:in `pbCommandPhase_ebs'

    PokeBattle_Battle:2629:in `each'

    PokeBattle_Battle:2629:in `pbCommandPhase_ebs'

    EliteBattle_0:294:in `pbCommandPhase'

    EliteBattle_0:224:in `pbStartBattleCore'

    EliteBattle_0:223:in `logonerr'



    .. I should really try to get a grasp on Ruby, so I can even understand what's going on when this kinda things happen :v
     
    Back
    Top